Boost Users :
Subject: Re: [Boost-users] shared_ptr as reference argument
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-03-19 20:56:58
On Thu, Mar 19, 2009 at 4:29 PM, Ovanes Markarian
> What about RVO and NRVO?
> You still can bind a temporary to a const reference. This is a simple
> example on how it is possible to do optimizations. Or am I mistaken?
> std::string foo();
> void bar()
> std::string const& bound_temporary = foo();
> std::cout << bound_temporary;
> whereas this is invalid:
> void invalid_bar()
> std::string& bound_temporary = foo(); //will not work, but AFAIK some
> compilers support it
Right, your first snippet is valid and the second is ill-formed.
> So compilers can do optimizations based on constness.
What optimizations do you have in mind? The second snippet is simply
illegal C++ (should not compile.)
Reverge Studios, Inc.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net