C++ function object to return `p->first` and `p->second`

后端 未结 3 1193
北恋
北恋 2021-01-17 19:02

Is there a builtin function object that returns p->first and p->second, so that I can happily write

transform(m.begin(),m.end         


        
3条回答
  •  礼貌的吻别
    2021-01-17 19:20

    If you can use C++0x you can either use real lambdas since G++ 4.5 or you can use the new tuple-library which is fully compatible with std::pairs. Then you could use std::get<0> for first and std::get<1> for second.

    If you are bound to C++98 you can use std::tr1::tuple instead of std::pair, as in TR1 get doesn't work with std::pair.

    Also you can use bind from TR1 (tr1/functional) like Elazar described it.

提交回复
热议问题