Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-11-18 16:06:12


"Thorsten Ottosen" <nesotto_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:ur7mr133a.fsf_at_boost-consulting.com...
> | "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
>
> | The enclosed will show the difference on any compiler I can get my
> | hands on. I'd be happy to show you the output if you need proof. On
> | most compilers it's a factor of 2.
>
> indeed. Thanks for fixing the bugs :-)
>
> | for( int i = 0; i != sz; ++i )
> | {
> | Foo< std::vector<int> > f;
> | f.v = foo();
>
> If you try to write
>
> Foo< std::vector<int> > f = { foo() };
> l += print( f.v );
>
> there should be no difference again.

Depends on how many optimizations your compiler is willing to do.
*Entirely* implementation-dependent!

> I'm still a little puzzled about why

Because what you wrote is a vector construction, not an assignment. I
told you, assignments are not elidable.

> 1. adding an inline constructor to Foo
> 2. using assignment syntax
>
> is not leading to any optimization when the above syntax does.

I think I'll leave you to puzzle it out. This has left the realm of
relevance to the thread.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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