Renaming first and second of a map iterator

后端 未结 8 1733
北恋
北恋 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:00

    If you don't need the iterator (e.g., a range-based for loop suits your purpose), then as of c++17 you can use structured bindings:

    map adjacency_list;
    for( auto & [ vertex, edge ] : adjacency_list )
    {
        // do stuff with vertex
    }
    

提交回复
热议问题