Background:
I'm trying to create a few of my own wrapper classes for the STL containers so I can separate implementation from my code base. I have already done alittle bit with my Vector class wrapper like so:
Vector.h
template<typename type>
class Vector
{
public:
Vector();
Vector(std::initializer_list<type> initializer);
Vector(int size, int defaultValue);
Vector(int size);
~Vector();
void PushBack(type itemToPushBack);
type AtPosition(int position);
private:
std::vector<type> m_collectionOfItems;
};
As you can see, I have constructors setup and I've used std::vector as a member so that I can just call std::vector functions within my own Vector classes.
Issue:
With std::array I have to specificy a size immediately when instantiating any object. So if I created a member variable like I did with my vector class, I would have to give that array object a size. I would rather the size be specified by the user using some similar constructor setup to Vector's (ex. MyArrayClass myArray(10) ). How might I try and implement this Array wrapper?
std::arraywraps a static array, so its size must be specified at compile-time. Astd::vectoris an array whose size is determined dynamically at run-time.std::array, its chief distinction fromstd::vector, is that its size is determined at compile time and thus it doesn't require a dynamic memory allocation. If you insist on wrappingstd::array, your wrapper should have the same property, otherwise it would largely defeat the point.allocaand it's variants are non standard and should be avoided if at all possible but one can wrap it similarly. It's available on most compilers but it is NOT standard C++.