
Michael Fawcett escribió:
On 10/18/07, Kevin Sopp <baraclese@googlemail.com> wrote:
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).
Thanks for your comments. Both options seems reasonable. I think the user of a splay_tree expects splaying as the default option, so I'm starting to think that avoiding const versions could be a better choice (generic code using non-const containers would work). Users that are sure about thread-safety can uncast the container before passing it to the algorithm. Anyway, I'm afraid my opinion might change again ;-) Thanks, Ion