Renaming first and second of a map iterator

后端 未结 8 1723
北恋
北恋 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 03:12

    You can't rename the members, but you can have some functions to help.

    inline Vertex& vertex(map::iterator& it) {return it->first;}
    inline Edge& edge(map::iterator& it) {return it->second;}
    

    Then, instead of it->vertex like you want, you can do vertex(it)

提交回复
热议问题