How do I create an array on the heap and initialize it at construction time from another array?
template <typename T>
T* Copy(T* myOriginalArray, size_t myOriginalArraySize)
{
T* copy = new T[myOriginalArraySize]; // copy data from myOriginalArray here too
return copy;
}
I could create the array and then use std::copy, but this would require the array contents to have an empty constructor. You can assume the object has a copy and move constructor. I have access to C++17.
std::array. It has a proper copy constructor already.std::vectoralignofand some casting, but it would be hideously complicated to avoid undefined behavior.