Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-08-09 09:03:07

From: David Abrahams <dave_at_[hidden]>
> Rob Stewart <stewart_at_[hidden]> writes:
> > From: Tylo <tylo_at_[hidden]>
> >>
> >> I propose this usage (for shared_ptr):
> >>
> >> shared_ptr<Widget> wp1 = NULL; // 1a
> <snip>
> >> Current shared_ptr usage:
> >>
> >> shared_ptr<Widget> wp1( NULL ); // 2a
> >
> > Lines 1a and 2a are just the difference between assignment and
> > initialization syntax.
> It's the difference between copy initialization and direct
> initialization.

Sure. I'd forgotten the terms and didn't look them up. Thanks
for the clarification.

> > The former can be slower than the latter, though the difference may
> > be optimized away.
> On many compilers where there is a difference, copy initialization is
> actually faster than direct initialization.

Call me confused. copy-initialization results in the
construction of an object that is then used to direct-initialize
the object (wp1, in this case). Of course, the compiler is
permitted to elide the extra step, so copy-initialization can
degenerate into direct-initialization.

How, then, can copy-initialization be faster than
direct-initialization on some compilers and which are they?

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

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