Boost logo

Boost Users :

From: Olaf van der Spek (olafvdspek_at_[hidden])
Date: 2007-08-09 04:01:57


On 8/9/07, Andrej van der Zee <mavdzee_at_[hidden]> 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_at_[hidden]> 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_at_[hidden]
> >
> 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.html
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net