Boost logo

Boost :

From: Corrado Zoccolo (czoccolo_at_[hidden])
Date: 2008-04-18 04:16:56

On Sat, Apr 12, 2008 at 11:58 AM, Thorsten Ottosen <
thorsten.ottosen_at_[hidden]> wrote:

> Corrado Zoccolo skrev:
> > On Fri, Apr 11, 2008 at 9:38 AM, Sebastian Redl <
> > sebastian.redl_at_[hidden]> wrote:
> >
> >> If this variant of swap() is really more efficient, perhaps
> >> metaprogramming could be used to support it *if* the type has a default
> >> constructor. But I don't know how to detect this. TypeTraits doesn't
> >> contain a has_default_constructor trait. It may be that this will only
> >> work with 09 concepts - DefaultConstructible.
> >>
> >
> > We can use has_nothrow_default_constructor .
> > This will also exclude the specialization when the default constructor
> > performs some allocation, and could result in lower performance.
> I can't imagine that it would result in lower performance in general ...
> have you seen many types for which default construction was more
> expensive than copy-construction?

For example shared-pimpl objects (mentioned by Andrey), will only increment
a reference count on copy construction, but may need to allocate memory on
default construction.

> has_nothrow_default_constructor is certainly useable, albeit it requires
> compiler inrinsics. Do we know how many compilers that do support them?

I think boost could provide some specializations it for stl types that
require it, and the user is allowed to specialize it for his types.
I think variant has a similar optimization for exception safety purposes,
that works under similar assumptions.


> -Thorsten
> _______________________________________________
> Unsubscribe & other changes:

dott. Corrado Zoccolo mailto:zoccolo_at_[hidden]
PhD - Department of Computer Science - University of Pisa, Italy
The self-confidence of a warrior is not the self-confidence of the average
man. The average man seeks certainty in the eyes of the onlooker and calls
that self-confidence. The warrior seeks impeccability in his own eyes and
calls that humbleness.
Tales of Power - C. Castaneda

Boost list run by bdawes at, gregod at, cpdaniel at, john at