I am learning template programming. While doing so, I am trying to implement a template function to read n-dimensional vector.
My thought process is to recursively read through all dimensions and once I reach the innermost vector, start reading its elements. Below is the (incorrect)code that I have tried.
template<typename Container>
void read_vectors(Container c){
read_vectors<decltype(begin(c))>(begin(c));
}
template<>
void read_vectors(vector<int> container){
for(auto i:container)
cout<<i<<endl;
}
int main(){
vector<vector<vector<int>>> intvectors{{{1,2,3},{1,2,3}},{{1,2,3}, {1,2,3}}};
read_vectors(intvectors);
return 0;
}
Any pointers on how that can be achieved is helpful.