Boost logo

Boost :

From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2007-10-18 17:00:34


On 10/18/07, Kevin Sopp <baraclese_at_[hidden]> wrote:
> > const_iterator it = const_splay_tree.find(a); //Splaying performed
> >
> > would break usual de-facto thread-safety guarantees for STL and
> > Intrusive containers (read-only access from different threads is
> > thread-safe).
>
> In other words, this is dangerous and misleading.
>
> > So the main question is: what approach do you think would be better?
> > ¿Just splay in const operations and put a thread-safety warning? ¿Make
> > const versions non-splaying? ¿Don't offer const versions of search
> > functions?
>
> Making the const versions non-splaying would destroy the functional
> equivalence between const and non-const search functions which might
> come as a surprise for programmers that did not read the documentation
> well. So i would opt for "don't offer const versions of search
> functions".
> IMO using
> iterator it = splay_tree.find(a, dont_splay);//No splay
> is superior.

How about reversing that? Offer the const find as a non-splaying
operation, and offer a non-const find overload that explicitly asks
for splaying?

iterator it = splay_tree.find(a);//No splay
iterator it = splay_tree.find(a, splay);//Splay operation performed

or maybe spell out all splaying functions as *_and_splay (e.g. find_and_splay).

--Michael Fawcett


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