I'd like to change the construction of std::array<unsigned int, size>
the following way:
myarray a {};
should construct[0,1,2,3,4...]
instead of[0,0,0,0,...]
myarray a {5,2};
should construct[5,2,2,3,4...]
instead of[5,2,0,0,0...]
One obvious solution is to have a class:
template <size_t size>
struct myarray {
std::array<int, size> ar;
myarray() { for (size_t i=0; i<size; i++) ar[i]=i; }
myarray(std::initializer_list<unsigned int> il) :ar(il) {
for (size_t i=il.size(); i<size; i++) ar[i]=i;
}
...
};
However it forces me to wrap every single member of ar
. As far as I understand, inheriting from std::array
is not a very good idea. Is there a third reasonable way ?