Boost logo

Boost Users :

From: Igor R (boost.lists_at_[hidden])
Date: 2008-08-04 18:49:03


Hi Joaquín,

Thank you very much for your response.

Have a nice vacation!

> Hi Igor,
>
> Excuse my late answering, I'm away on vacation and with little access to Internet.
> Your problem is not particualrly related to Boost.MultiIndex, since it is entirely
> analogous to the same issue as posed with std::sets. You can use
> std::set_difference, but the interface of this function forces you yo create a
> fresh copy with the result of the difference rather than doing the subtraction in place.
> Another alternative would be to use std::for_each more or less like this:
>
> typedef multi_index_container<int,...> multi_t;
>
> struct multi_t_erase
> {
> multi_t_erase(multi_t& m):pm(&pm){}
> void operator()(int n){pm->erase(n);}
>
> private:
> multi_t* pm;
> };
>
> std::for_each(c2.begin(),c2.end(),multi_t_erase(c1));
>
> Yet another alternative consists in traversing both containers
> more or less in the same way as std::set_difference does:
>
> multi_t::iterator f1=c1.begin(),l1=c1.end(),f2=c2.begin(),l2=c2.end();
> while(f1!=l1&&f2!=l2){
> if(c1.value_comp()(*f1,*f2))c1.erase(f1++);
> else if(c1.value_comp()(*f2,*f1))++f2;
> else ++f1,++f2;
> }
> c1.erase(f1,l1);


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