自明なファンクターを作成する必要がないように、ブースト ラムダを使用しようとしています。たとえば、ラムダを使用して構造体のメンバーにアクセスしたり、クラスのメソッドを呼び出したりしたいとします。
#include <vector>
#include <utility>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost::lambda;
vector< pair<int,int> > vp;
vp.push_back( make_pair<int,int>(1,1) );
vp.push_back( make_pair<int,int>(3,2) );
vp.push_back( make_pair<int,int>(2,3) );
sort(vp.begin(), vp.end(), _1.first > _2.first );
これをコンパイルしようとすると、次のエラーが発生します。
error C2039: 'first' : is not a member of 'boost::lambda::lambda_functor<T>'
with
[
T=boost::lambda::placeholder<1>
]
error C2039: 'first' : is not a member of 'boost::lambda::lambda_functor<T>'
with
[
T=boost::lambda::placeholder<2>
]
vp には含まれているのでpair<int,int>
、_1.first が機能するはずだと思いました。私が間違っていることは何ですか?