Say that I have 3 variables:
vector<int> vec(3);
int stat[3];
auto dyn = make_unique<int[]>(3);
I can initialize any of these if I know the size is 3:
for(auto i = 0; i < 3; ++i) X[3] = i;
Where X
is either, vec
, stat
, or dyn
. But I'd like to be able to do this in a template just by passing in X
again. What I'd need in order to do this is:
- The contained type
- The container size
Can I get that in a function like:
template <typename T>
void init(T& X);
Or am I unable to extract size information from the unique_ptr
? Or type in a universal fashion? (I've marked this question C++17 in the hopes that size
can be used.)