Renaming first and second of a map iterator

后端 未结 8 1724
北恋
北恋 2020-12-14 02:41

Is there any way to rename the first and second accessor functions of a map iterator. I understand they have these names because of the underlying pair which represents the

8条回答
  •  -上瘾入骨i
    2020-12-14 03:13

    If you're just concerned about readability you could do something like this:

    typedef map AdjacencyList;
    struct adjacency
    {
        adjacency(AdjacencyList::iterator& it) 
          : vertex(it->first), edge(it->second) {}
        Vertex& vertex;
        Edge& edge;
    };
    

    And then:

    Vertex v = adjacency(it).vertex;
    

提交回复
热议问题