Boost logo

Boost :

Subject: Re: [boost] [interprocess][multi_index] emplace() is not sufficient for maps
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-08-20 09:21:10


Joaquin M Lopez Munoz skrev:

>>
>> The situation is characterized by the need to calculate the key after
>> the mapped value (a heavy object) has been placed in the pair. To
>> calculate the key the mapped value needs to be modified (the key is
>> calculated as a side-effect).
>>
>> I therefore suggest that we add a new function:
>>
>> typedef ... map;
>> map m;
>> map::node_ptr p = m.get_node_ptr(<like emplace, but only for
>> constructing the mapped value>);
>> p->pair.first = modify( p->pair.second );
>> m.insert( boost::move(p) );
>>
>> Thoughts?
>
> Why can't you just do the following?
>
> map::mapped_type x=...;
> map::key_type k=modify(x);
> m.emplace(boost::move(k),boost::move(x));
>

I could, but moving the mapped object is just as expensive as
copy-construction, and it is exactly this I want to avoid.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk