Boost logo

Boost :

Subject: Re: [boost] GSoC 2010: Heaps and Queues
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-04-08 22:42:02


Dan Larkin wrote:
> Andrew Sutton wrote:
>> Maybe this approach allows too much freedom. I suppose you could also
>> offer
>> a method:
>>
>> void update(iterator pos, const T& x); // *pos = x; update(pos);
>>
>> That would prevent modifying operations in between updates.
>
> This runs into the reference copying issue again. This assumes that T
> has a well-behaved and efficient copy-constructor, and does a full
> replacement of x rather than allowing for a partial update. I'm not
> convinced that the extra safety offers enough of a benefit over
> allowing the user to update it on their own:
>
> *x = newValue;
> update(x);
>
> Or, perhaps some more complex structure that would drive my point home
> a bit more effectively:
>
> x->field[999] = newValue;
> update(x);
>
> As long as the library is explicit about the fact that updating data
> will temporarily void the heap property until an update() call is made
> on the data in question, it should work much better this way.

Boost.MultiIndex uses the following interface

"template<typename Modifier> bool modify(iterator position,Modifier mod);

    Requires: Modifier is a model of Unary Function accepting arguments
        of type value_type&. position is a valid dereferenceable iterator
        of the index..."

http://www.boost.org/libs/multi_index/doc/reference/ord_indices.html#modifiers

In Christ,
Steven Watanabe


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