
"Thorsten Ottosen" <nesotto@cs.auc.dk> writes:
"David Abrahams" <dave@boost-consulting.com> wrote in message news:ur7mr133a.fsf@boost-consulting.com... | "Thorsten Ottosen" <nesotto@cs.auc.dk> 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