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
#include
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
using namespace boost::lambda;
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::map countries_t;
countries_t countries;
countries[0] = 5;
countries[1] = 3;
countries[2] = 1;
typedef vector 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 ==========