use bind.
try using bind.
namespace bll = boost::lambda;

std::sort(countries1.begin(), countries1.end(), bll::bind(&countries_t::second, _1) < bll::bind(&countries_t::second, _2));

On 8/8/07, Olaf van der Spek <olafvdspek@gmail.com> wrote:
Hi,

I'm trying to sort a map based on second, but I get all kinds of
compiler errors and I have no idea what's wrong. A simple _1 > _2
works fine, but that compares the maps themselves.

Also, is there a better way to write the copy from map to vector or to
sort the map in general?

Note that I'm using a map because I'm counting how often an integer or
string occurs.

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;
using namespace boost::lambda;

int _tmain(int argc, _TCHAR* argv[])
{
        typedef std::map<int, int> countries_t;
        countries_t countries;
        countries[0] = 5;
        countries[1] = 3;
        countries[2] = 1;
        typedef vector<countries_t::const_iterator> countries1_t;
        countries1_t countries1;
        for (countries_t::const_iterator i = countries.begin(); i !=
countries.end(); i++)
                countries1.push_back(i);
        sort(countries1.begin(), countries1.end(), _1->second > _2->second);
        return 0;
}

------ Build started: Project: Lambda Test, Configuration: Debug Win32 ------
Compiling...
Lambda Test.cpp
c:\vc\temp\lambda test\lambda test.cpp(23) : error C2819: type
'boost::lambda::lambda_functor<T>' does not have an overloaded member
'operator ->'
        with
        [
            T=boost::lambda::placeholder<1>
        ]
        did you intend to use '.' instead?
c:\vc\temp\lambda test\lambda test.cpp(23) : error C2039: 'second' :
is not a member of 'boost::lambda::lambda_functor<T>'
        with
        [
            T=boost::lambda::placeholder<1>
        ]
c:\vc\temp\lambda test\lambda test.cpp(23) : error C2819: type
'boost::lambda::lambda_functor<T>' does not have an overloaded member
'operator ->'
        with
        [
            T=boost::lambda::placeholder<2>
        ]
        did you intend to use '.' instead?
c:\vc\temp\lambda test\lambda test.cpp(23) : error C2039: 'second' :
is not a member of 'boost::lambda::lambda_functor<T>'
        with
        [
            T=boost::lambda::placeholder<2>
        ]
c:\vc\temp\lambda test\lambda test.cpp(23) : error C2780: 'void
std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided
        c:\program files\microsoft visual studio
8\vc\include\algorithm(3109) : see declaration of 'std::sort'
Lambda Test - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users