Can UnaryOperator be a member function when std::transform is called

后端 未结 3 1003
终归单人心
终归单人心 2021-01-22 21:07

Based on std::transform

template < class InputIterator, class OutputIterator, class UnaryOperator >
  OutputIterator transform ( InputIterator first1, Inpu         


        
3条回答
  •  囚心锁ツ
    2021-01-22 21:58

    No (well, not directly). You need to use an adaptor, either old std::mem_fun (together with bind1st, IIRC) or std::bind/boost::bind.

    std::transform(
        xs.begin(), xs.end(), ys.begin(),
        std::bind(&Class::member, &class_instance)
    );
    

提交回复
热议问题