Hi there,

Is there a way to emplace (key, value) in boost multi_index hashed index in such a way that the value is not moved/stolen if the key is already present?
As far as I checked the implementation for emplace (and emplace_) the node is eagerly created and the key and the value are moved into the node and then the insertion operation takes place. If the insertion fails the node is destroyed but the outside value is lost/stolen in all cases.
What I actually need is to create the value only if the key is not present, because the creation is expensive, and I'd like to avoid the find+emplace or insert empty value + modify call. (As far as I checked, the value can't be modified directly from the returned iterator because it's const and will need const_cast to work).
I thought to use emplace with some machinery for lazy creation
struct creator
{
operator value_type () { return ...; } // create the value lazily, on demand
};
The creator is passed to emplace instead of the actual value. However, this doesn't help because the node is eagerly created and the above operator is always called.

Thanks,
Pavel.