Boost logo

Boost Users :

Subject: Re: [Boost-users] multi_index_container for composite key
From: joaquin_at_[hidden]
Date: 2010-09-09 05:21:23


Uthpal Urubail escribió:
> Joaquín,
> My question is:
> Can I define container like below?
> typedef multi_index_container<
> ElemShell*,
> indexed_by<
> //non-unique as some might have more than ids
> ordered_non_unique<
> composite_key<
> ElemShell*,
> member<ElemShell,int,&ElemShell::N1>,
> member<ElemShell,int,&ElemShell::N2>,
> member<ElemShell,int,&ElemShell::N3>,
> member<ElemShell,int,&ElemShell::N4>
> >
> >,
> ordered_unique<
> member<GeneralElement,int,&GeneralElement::EID>
> >
> >
>
>> beambook;
>>

Yes, you can (except that the second index seems to be wrongly keyed
on GeneralElement rather than ElemShell, but I understand this is a typo.)

> When I retrieve,
> beambook::iterator it=(pb.find(boost::make_tuple(obj->N1,obj->N2,obj->N3,node4)));
> int val = (*it)->N4;
> Application is crashing.
>

Almost surely because there's no element with the provided N1,N2,N3,N4
and hence the iteraror it is pb.end().

> About: If you use ordered_unique then there cannot be two elements with the same node[0], node[1], node[2] values.
> Its TRUE. Two elements cannot have same node[0], node[1], node[2] values. How should be the container?
>

Use ordered_unique then, as your own statements imply.

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