I would like to construct a vector of vectors. This question has already been posted many time on SO but I did not find a satisfying answer. That because:
- each vector can have a different type
- I don't know the types at compilation time
- I don't know how many vectors it will contain
Basically I would like to be able to do something like that in pseudo code later
types = ["char", "int", "double", "int"]
container<vector> x
foreach (type in types)
{
if (type == "char")
x.push_back(vector<char>)
else if (type == "int")
x.push_back(vector<int>)
else
x.push_back(vector<double>)
}
and then I would like to be able to do for example
x[0].push_back("a")
x[1].push_back(1)
x[2].push_back(3.1416)
I think boost::any may help me but I'm not familiar with boost yet.
The point is, even if it sound weird, it is really what I want to do. I don't want a vector of structures, I really want a container (no matter which one) containing std::vector of different types. The reason is because I'm reading binary files. The header of the file states the number of data and their types but it can change from a file to another. Thus it cannot be known at compilation time.