Wednesday, 28 August 2013

Construct std::set from array

Construct std::set from array

Why doesn't C++ provide us with a constructor which takes an array as an
argument? Alternatively, is there anything wrong with defining the
following function?
template <class T>
std::set<T> ArrayToSet(T array[]) {
return std::set<T>(array, array + sizeof(array) / sizeof(array[0]));
}
I think the answer might come down to ideas of dynamic memory allocation,
but I'd like to hear some feedback on this.

No comments:

Post a Comment