|
Boost : |
Subject: Re: [boost] [interprocess][multi_index] emplace() is not sufficient for maps
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2009-09-24 10:27:18
On Sep 24, 2009, at 10:02 AM, Thorsten Ottosen wrote:
> Howard Hinnant skrev:
>> On Sep 19, 2009, at 4:18 AM, Thorsten Ottosen wrote:
>>> Ion Gaztañaga skrev:
>>>> Thorsten Ottosen escribió:
>
>> Suggestion:
>> Using std::map as an example as I am not familiar with
>> [interprocess][multi_index]. Also using C++0X notation (to be
>> emulated in C++03).
>> Add to the container:
>> template <class Key, class T, class Compare, class Allocator>
>> class map
>> {
>> public:
>> ...
>> typedef /details/ node_ptr;
>> node_ptr remove(const_iterator p);
>> pair<iterator, bool> insert(node_ptr&& nd);
>> iterator insert(const_iterator p, node_ptr&& nd);
>> ...
>> };
>> map::node_ptr is a move-only smart pointer which holds an
>> Allocator* and a map::node* (or equivalent smart pointer as
>> interprocess may need?). node_ptr roughly looks like:
>> template <class Key, class T, class Allocator>
>> class node_ptr
>> {
>> node_ptr(const node_ptr&);
>> node_ptr& operator=(const node_ptr&);
>> public:
>> typedef pair<Key, T> value_type;
>> node_ptr();
>> ~node_ptr();
>> node_ptr(node_ptr&& n);
>> node_ptr& operator=(node_ptr&& n);
>> void reset();
>> value_type& operator*() const;
>> value_type* operator->() const;
>> };
>
> I'm fine with this interface, and it seems less complicated compared
> to Joaquin's modify_key().
>
> It doesn't quite address my first issue though, namely that I need
> to construct the mapped value in the node, and then compute the key
> from this mapped value (after some modification).
>
> I think if the node_ptr class had
>
> a) a forwarding (Key,Value) constructor
>
> b) an emplacing constructor that
> constructed the pair with (Key,...)
>
> then I could do exactly what I needed :-)
With what allocator would the node_ptr allocate the node?
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk