Boost logo

Boost Users :

Subject: Re: [Boost-users] [bimap] How to erase a single association in a many-to-many bimap?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-05-15 06:43:02


Le 15/05/12 12:09, Vicente J. Botet Escriba a écrit :
> Hi,
>
> I have a bimap
>
> typedef bimap<
> multiset_of< tagged< Person*, consultant> >,
> multiset_of< tagged< Company*, client> >,
> with_info< tagged< ConsultancyContract*, contract> >
> > Consultancy;
>
> initialized as follows
>
> Consultancy consultancy;
> Person John("John"), Jane("Jane");
> Company Dell("Dell"), HP("HP");
> ConsultancyContract JohnContractD(10,1);
> ConsultancyContract JaneContractD(20, 2);
> ConsultancyContract JaneContractH(30, 3);
>
> consultancy.insert(Consultancy::value_type(&Jane, &Dell,
> &JaneContractD));
> consultancy.insert(Consultancy::value_type(&Jane, &HP,
> &JaneContractH));
>
> and I want to remove only the specific association Jane<->Dell and so
> I'm using
>
> consultancy.erase(Consultancy::value_type(&Jane, &Dell));
>
> but then the resulting consultancy bimap is empty, while I expect the
> association Jane<->HP to be there yet.
>
> If I add before erasing
> consultancy.insert(Consultancy::value_type(&John, &Dell,
> &JohnContractD));
>
> and then
> consultancy.erase(Consultancy::value_type(&Jane, &Dell));
>
> all the associations concerning Jane are removed.
>
> What I'm doing wrong? How to erase a single association?
>
I have reached to get what I was locking for.

I have added set_of_relation<> to the bimap definition

typedef bimap<
     multiset_of< tagged< Person*, consultant> >,
     multiset_of< tagged< Company*, client> >,
     with_info< tagged< ConsultancyContract*, contract> > ,
     multiset_of_relation<>
> Consultancy;

Is there another way when the collection of relation is the default
|left_based?
|I find the default behavior a little bit surprising. Why provide a
erase function requesting the value_type if only the left side is taken
in account?
|
What is the rationale to have the default left_based? Space optimization?

It works also with multiset_of_relation. I don't see a use case for
this. When the user could want the same association to be several times?
Could some one give me an example?

Best,
Vicente
|



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