C++ std::transform vector of pairs->first to new vector

前端 未结 6 2115
你的背包
你的背包 2020-12-31 00:51

Sorry for a little bit beginner question. There are vector and vector of pairs

typedef std::vector  TItems;
typedef std::vector < std::pair <         


        
6条回答
  •  臣服心动
    2020-12-31 01:57

    another possibility from C++11 would be std::mem_fn, which is similar to solution with std::bind:

    std::transform(pairs.begin(), 
                   pairs.end(), 
                   std::back_inserter(items), 
                   std::mem_fn(&std::pair::first)               
    );
    

提交回复
热议问题