Is there a way to declare a std::map
whose value type is an iterator to itself?
map::iterator> myMap;
Only through type erasure. For example, you could use std::any
std::map myMap;
auto inserted = myMap.emplace("foo", std::any());
// how it can be populated:
inserted.first->second = inserted.first;
using it_type = decltype(myMap.begin());
// how values can be extracted:
auto it = std::any_cast(myMap["foo"]);
EDIT: The following also seems to work (clang-7.0.0 and gcc-8.2), but it is illegal (basically std::map
does not specify that incomplete types are allowed):
struct Iter;
using Map = std::map;
struct Iter {
Map::iterator it;
};