How to convert a sorted std::list of std::pair to a std::map

前端 未结 3 1207
南方客
南方客 2021-01-12 09:27

I have got a std::list< std::pair >, which I know is sorted according to the std::string element.

Since I

3条回答
  •  失恋的感觉
    2021-01-12 09:31

    You can use std::copy and std::inserter:

    std::copy(the_list.begin(),the_list.end(),std::inserter(the_map,the_map.begin()));  
    

    because the iterator for a list< pair > has a value type compatible to map< X,Y >'s iterators.

提交回复
热议问题