Trying to use boost lambda, but my code won't compile

Posted by hamishmcn on Stack Overflow See other posts from Stack Overflow or by hamishmcn
Published on 2010-04-15T05:07:54Z Indexed on 2010/04/15 5:13 UTC
Read the original article Hit count: 398

Filed under:
|
|

Hi, I am trying to use boost lambda to avoid having to write trivial functors. For example, I want to use the lambda to access a member of a struct or call a method of a class, eg:

#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 );

When I try and compile this I get the following errors:

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>
        ]

Since vp contains pair<int,int> I thought that _1.first should work. What I am doing wrong?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost-lambda