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 ==========
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?
maps are already sorted! see the third template argument. a simple vec.insert(vec.end(), map.begin(), map.end()) will copy it. did you need something else? -- Cory Nelson
maps are sorted base on key. I think his trying to sort the value. .. Alternative solution. /* ugly coding */ template <template <typename ELEM,typename = std::allocator<ELEM> > class CONT, class T, class U> inline CONT<U> getValues(const boost::unordered_map<T, U>& data) { CONT<U> retCont; typedef typename boost::unordered_map<T, U>::value_type value_type; BOOST_FOREACH(value_type val, data) { retCont.push_back(val.second); } return retCont; } std::vector<int> countriesValue = getValues<std::vector, int, int>(countries); std::sort(countriesValue.begin(), countriesValue.end()); On 8/8/07, Cory Nelson <phrosty@gmail.com> wrote:
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?
maps are already sorted! see the third template argument. a simple vec.insert(vec.end(), map.begin(), map.end()) will copy it. did you need something else?
-- Cory Nelson _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 8/8/07, Cory Nelson <phrosty@gmail.com> wrote:
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?
maps are already sorted! see the third template argument. a simple
Yes, on key, not on value.
vec.insert(vec.end(), map.begin(), map.end()) will copy it. did you need something else?
Yes, I use iterators (or pointers) in the vector to avoid an expensive copy in the case of strings.
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
On 8/8/07, chun ping wang <cablepuff@gmail.com> wrote:
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));
Does that compile for you? It doesn't for me. Note that second is not a function. ------ Build started: Project: Lambda Test, Configuration: Debug Win32 ------ Compiling... Lambda Test.cpp c:\vc\temp\lambda test\lambda test.cpp(26) : error C2039: 'second' : is not a member of 'std::map<_Kty,_Ty>' with [ _Kty=int, _Ty=int ] c:\vc\temp\lambda test\lambda test.cpp(26) : error C2065: 'second' : undeclared identifier c:\vc\temp\lambda test\lambda test.cpp(26) : error C2039: 'second' : is not a member of 'std::map<_Kty,_Ty>' with [ _Kty=int, _Ty=int ] c:\vc\temp\lambda test\lambda test.cpp(26) : 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 - 4 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Olaf van der Spek schrieb:
On 8/8/07, chun ping wang <cablepuff@gmail.com> wrote:
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));
Does that compile for you? It doesn't for me. Note that second is not a function.
Change the last line to bll::bind(&countries_t::second, bll::_1) < bll::bind(&countries_t::second, bll::_2)); and it should compile. Regards, Christian [snip]
If you need multiple indexes over your data structures you could also consider to use boost::multi_index containers. In that case you can put all your data members (key and value) in a struct and define two (or more) indexes over it. Greets, Andrej --- 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
___________________________________________________________ Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm...
sorry, my bad. you should use std::pair<int, int> country_kv; replace countries_t in the lambda code with country_kv; this should work. On 8/8/07, Andrej van der Zee <mavdzee@yahoo.co.uk> wrote:
If you need multiple indexes over your data structures you could also consider to use boost::multi_index containers. In that case you can put all your data members (key and value) in a struct and define two (or more) indexes over it. Greets, Andrej
--- 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
___________________________________________________________ Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 8/9/07, chun ping wang <cablepuff@gmail.com> wrote:
sorry, my bad.
you should use std::pair<int, int> country_kv;
replace countries_t in the lambda code with country_kv;
this should work.
This doesn't compile either: int main() { 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); typedef std::pair<int, int> country_kv; sort(countries1.begin(), countries1.end(), bll::bind(&country_kv::second, _1) < bll::bind(&country_kv::second, _2)); return 0; } ------ Build started: Project: Lambda Test, Configuration: Debug Win32 ------ Compiling... Lambda Test.cpp c:\vc\misc\include\boost\lambda\detail\actions.hpp(87) : error C2665: 'boost::lambda::function_adaptor<Func>::apply' : none of the 8 overloads could convert all the argument types with [ Func=int std::pair<int,int>::* ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(117): could be 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,Object &)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(121): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,const Object &)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(125): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,volatile Object &)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(129): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,volatile const Object &)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(133): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,Object *)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(137): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,const Object *)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(141): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,volatile Object *)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] c:\vc\misc\include\boost\lambda\detail\function_adaptors.hpp(145): or 'RET boost::lambda::function_adaptor<Func>::apply<RET>(T std::pair<_Ty1,_Ty2>::* ,volatile const Object *)' with [ RET=int &, Func=int std::pair<int,int>::* , T=int, _Ty1=int, _Ty2=int, Object=std::pair<int,int> ] while trying to match the argument list '(rt0 , std::_Tree<_Traits>::const_iterator)' with [ _Traits=std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false> ] c:\vc\misc\include\boost\lambda\detail\lambda_functor_base.hpp(408) : see reference to function template instantiation 'RET boost::lambda::function_action<I>::apply<RET,const U,std::_Tree<_Traits>::const_iterator>(A1 &,A2 &)' being compiled with [ RET=int &, I=2, U=rt0, _Traits=std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>, A1=rt0, A2=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator ] c:\vc\misc\include\boost\lambda\detail\select_functions.hpp(30) : see reference to function template instantiation 'RET boost::lambda::lambda_functor_base<Act,Args>::call<int&,A,B,C,Env>(A &,B &,C &,Env &) const' being compiled with [ RET=int &, Act=boost::lambda::action<2,boost::lambda::function_action<2>>, Args=boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>, A=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, B=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, C=const boost::tuples::null_type, Env=const boost::tuples::null_type ] c:\vc\misc\include\boost\lambda\detail\operator_lambda_func_base.hpp(218) : see reference to function template instantiation 'int &boost::lambda::detail::select<boost::lambda::lambda_functor_base<Act,Args>,A,B,C,Env>(const boost::lambda::lambda_functor<T> &,A &,B &,C &,Env &)' being compiled with [ Act=boost::lambda::action<2,boost::lambda::function_action<2>>, Args=boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>, A=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, B=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, C=const boost::tuples::null_type, Env=const boost::tuples::null_type, T=boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>> ] c:\vc\misc\include\boost\lambda\detail\lambda_functors.hpp(156) : see reference to function template instantiation 'RET boost::lambda::lambda_functor_base<Act,Args>::call<bool,A,B,const boost::tuples::null_type,const boost::tuples::null_type>(A &,B &,C &,Env &) const' being compiled with [ RET=bool, Act=boost::lambda::relational_action<boost::lambda::less_action>, Args=boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>, A=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, B=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, C=const boost::tuples::null_type, Env=const boost::tuples::null_type ] c:\program files\microsoft visual studio 8\vc\include\algorithm(3181) : see reference to function template instantiation 'bool boost::lambda::lambda_functor<T>::operator ()<std::_Tree<_Traits>::const_iterator,std::_Tree<_Traits>::const_iterator>(A &,B &) const' being compiled with [ T=boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>, _Traits=std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>, A=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, B=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator ] c:\program files\microsoft visual studio 8\vc\include\algorithm(3237) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2> std::_Unguarded_partition<_RanIt,_Pr>(_RanIt,_RanIt,_Pr)' being compiled with [ _Ty1=std::_Vector_iterator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator,std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>>, _Ty2=std::_Vector_iterator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator,std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>>, _RanIt=std::_Vector_iterator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator,std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>>, _Pr=boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>> ] c:\program files\microsoft visual studio 8\vc\include\algorithm(3261) : see reference to function template instantiation 'void std::_Sort<std::_Vector_iterator<_Ty,_Alloc>,__w64 int,_Pr>(_RanIt,_RanIt,_Diff,_Pr)' being compiled with [ _Ty=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, _Alloc=std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>, _Pr=boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>>, _RanIt=std::_Vector_iterator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator,std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>>, _Diff=__w64 int ] c:\vc\temp\lambda test\lambda test.cpp(27) : see reference to function template instantiation 'void std::sort<std::_Vector_iterator<_Ty,_Alloc>,boost::lambda::lambda_functor<T>>(_RanIt,_RanIt,_Pr)' being compiled with [ _Ty=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator, _Alloc=std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>, T=boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>, _RanIt=std::_Vector_iterator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator,std::allocator<std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::const_iterator>>, _Pr=boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<1>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<int std::pair<int,int>::* const ,const boost::lambda::lambda_functor<boost::lambda::placeholder<2>>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>> ] Lambda Test - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
On 8/9/07, Andrej van der Zee <mavdzee@yahoo.co.uk> wrote:
If you need multiple indexes over your data structures you could also consider to use boost::multi_index containers. In that case you can put all your data members (key and value) in a struct and define two (or more) indexes over it.
That would work, but it wouldn't be good. I just need to sort it once, I don't need an extra index. Updating the second index each time would be expensive.
Greets, Andrej
--- 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
___________________________________________________________ Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 8/9/07, Peter Dimov <pdimov@pdimov.com> wrote:
Olaf van der Spek wrote:
sort(countries1.begin(), countries1.end(), _1->second > _2->second);
sort( countries1.begin(), countries1.end(),
bind( &countries_t::value_type::second, *_1 ) > bind( &countries_t::value_type::second, *_2 )
Thanks, that did the trick. I didn't know you could use bind like this too. But why does the simpler syntax not work?
From my guess, reason is that second is a member value of a complex class. Naturally you need the address of target member function. Lambda by itself is not a particular type. It doesn't have any members function or data. The only thing it knows its value semantics.
On 8/9/07, Olaf van der Spek <olafvdspek@gmail.com> wrote:
On 8/9/07, Peter Dimov <pdimov@pdimov.com> wrote:
Olaf van der Spek wrote:
sort(countries1.begin(), countries1.end(), _1->second > _2->second);
sort( countries1.begin(), countries1.end(),
bind( &countries_t::value_type::second, *_1 ) > bind( &countries_t::value_type::second, *_2 )
Thanks, that did the trick. I didn't know you could use bind like this too. But why does the simpler syntax not work? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Olaf van der Spek wrote:
On 8/9/07, Peter Dimov <pdimov@pdimov.com> wrote:
Olaf van der Spek wrote:
sort(countries1.begin(), countries1.end(), _1->second > _2->second);
sort( countries1.begin(), countries1.end(),
bind( &countries_t::value_type::second, *_1 ) > bind( &countries_t::value_type::second, *_2 )
Thanks, that did the trick. I didn't know you could use bind like this too. But why does the simpler syntax not work?
Due to the way operator-> overloading works, it's hard to make _1->second do what you want (and impossible for arbitrary identifiers and not just 'second'.) The closest you can get with Lambda is _1 ->* &countries_t::value_type::second.
participants (6)
-
Andrej van der Zee
-
Christian Rössel
-
chun ping wang
-
Cory Nelson
-
Olaf van der Spek
-
Peter Dimov