STL map onto itself?

c++, containers, dictionary, stl

Solution

You could use forward declaration of a new type.

class MapItContainers;
typedef map<int, MapItContainers>::iterator MyMap_it;

class MapItContainers
{
public:
 vector<MyMap_it> vec;
};

With this indirection the compiler should let you get away with it. It is not so very pretty but honestly I don't think you can break the self referencing easily.

Problem

I'd like to create a `std::map` that contains a `std::vector` of iterators into itself, to implement a simple adjacency list-based graph structure. However, the type declaration has me stumped: it would seem you need the entire map type definition to get the iterator type of said map, like so: ``` map< int, Something >::iterator MyMap_it; // what should Something be? map< int, vector<MyMap_it> > MyMap_t; ``` Is there some sort of partial map iterator type I can get with just the key type, so I can declare the full map?

Original source