How I can define a list of map::iterator and map of list::iterator

断了今生、忘了曾经 提交于 2019-12-05 16:02:05

Something like this should help you:

#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <string>

struct decl_t {
    typedef std::map<std::string, decl_t> map_t;
    typedef std::list<std::pair<int, typename map_t::iterator>> list_t;

    list_t::iterator it;
};

int main(int argc, const char* argv[])
{
    decl_t::map_t map;
    decl_t::list_t list;

    auto list_it = list.emplace(list.end(), 42, decl_t::map_t::iterator());
    const auto pair = std::make_pair(std::string("key"), decl_t{list_it});
    auto result = map.insert(pair);
    assert(result.second);
    auto map_it = result.first;
    list_it->second = map_it;

    std::cout << list_it->second->first << std::endl;
    std::cout << map_it->second.it->first << std::endl;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!