Boost logo

Boost Users :

Subject: Re: [Boost-users] multi index container [solved]
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2010-02-03 13:46:50


Dejan <xamiw <at> arcor.de> writes:

>
>
> > That's right, but did you consider what I commented in my
> > previous post?
>
> Yeah, I did but the variable id is coming from outside (user) and not
> from inside (software). So p->id is never used.

The idea is to implement it the other way around, i.e.
sorting by id:

 * When a user enters an id, you just look for it.
 * When the software has a pointer p to look for, it simply
   has to find(p->id)

Clearer now?

>
> [...]
>
> But I have again a problem. I can't get the member variable (like id in
> this example) directly. I have to use get_id(). When defining:
>
> typedef multi_index_container
> <
> employee*,
> indexed_by
> <
> ordered_unique<identity<employee*> >,
>
> // next line does not work
> ordered_unique<member<employee, int, &employee::get_id()> >
> >
> > employee_set;
>
> The code does not compile:
> error: ‘Employee::get_id() const’ cannot appear in a constant-expression
> error: a function call cannot appear in a constant-expression

You have to use const_mem_fun rather than member:

http://www.boost.org/libs/multi_index/doc/tutorial/key_extraction.html#const_mem_fun

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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