Everybody,
I am a Python/C# guy and I am trying to learn C++.
In Python I used to do things like:
myRoutes = {0:[1,2,3], 1:[[1,2],[3,4]], 2:[[1,2,3],[[1,2,3],[1,2,3]],[4]]}
Basically when you have arrays of variable length and you don't want to wast a 2D matrix for them, nesting arrays into a dictionary to keep track of them is a good option.
In C++ I tried std::map<int, std:map<int, std:map<int, int> > > and it works but I feel there got to bo a better way to do this.
I prefer to stick to the standard libraries but popular libraries like boost are also acceptable for me.
I appreciate your help,
Ali
std::map<int, std::list<int>>or something similar with a fixed number of levels, not arbitrarily deep data structures, as in Python. That's not to say it can't be done, just that it's not trivial.std::map<int, std::list<int>>orstd::map<int, std::vector<int>>will do that job just fine. The problem is that your arrays can hold more arrays and so on ad infinitum. Boost::Any or Boost::Variant might meet your needs, as @Phooji says.