currently I’m struggling with maps which should contain themselves. But I don’t know the depth of the nesting when compiling.
std::map<Key, std::map<Key, std::map<Key, std::map<Key, ...>>>>
Is there a way to achieve this goal without infinitely repeating myself?
The golden hammer for self-referential data structures is the use of pointers. In your particular, case, to implement a tree you can just do that:
Each node in the tree contains a value and a set of child
Nodes maintained though a map of shared pointers. Thestd::maprequires (according to the standard) the stored types to be complete, butshared_ptronly needs the type to be complete at the point of creation which allows this data structure. A plainNode*would also have worked, but then you would have to manage the memory manually.