Boost logo

Boost :

From: Herve Bronnimann (hbr_at_[hidden])
Date: 2000-10-18 14:22:42


A [side] note which may help some on the boost list:

On Wed, Oct 18, 2000 at 10:52:48AM +0200, Ullrich Koethe wrote:
> > I've been trying to work out a general method for using STL-style algorithms
> > on containers of pointers.
> Dietmar Kuehl has written a worthwhile paper on this subject. See
> http://oonumerics.org/tmpw00/kuehl.pdf

Thanks for the reference. That article addresses many concerns, one of
them is the extra copy constructors called when using the STL (which is
value-, not reference-, oriented).

This problem is not restricted to polymorphism. I encountered the
problem with function objects, and found a solution in Nicolai's book
and it helped me avoid wrapping my objects inside reference-counted
objects. Nicolai's trick, which avoids useless copy constructors in STL,
is to explicitly qualify the STL algorithm to use a reference type. For
instance, when using predicate objects which you don't want to copy:

   std::find<Iterator,Iterator, Compare const&>(first, last, comp);

A word of warning: if your STL algorithm uses internal functions, and
those function calls haven't been qualified (happens with GNU libstdc++,
but not all STL implementations), you're at a loss.

Unfortunately for Ullrich, even this approach wouldn't work for
containers of polymorphic objects, since the containee would be a
reference (fall back onto the classical reference of a reference
problem). Dietmar's article articulates the problems very well, I
thought.

Cheers,

-- 
Hervé

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