|
Boost : |
From: Victor A. Wagner, Jr. (vawjr_at_[hidden])
Date: 2002-06-28 10:15:57
"missed"? Unnamed return value optimization has been around longer.
Scott Meyers (I left his books at the office, so I can't quote which)
talked at length about why naming the temporary was likely to generate
WORSE code on most (at the time he wrote it) compilers.
Though, as I recall, he used something equivalent to:
friend T operator*(const T& x, const U& y) { return T(x) *= y; }
which is an explicit call to the constructor leaving an UNnamed thing to
return, and hence optimize
At Friday 2002/06/28 00:01, you wrote:
>Hi,
>
>I noticed that boost libraries sometimes implement some operators in a
>way that prevents optimizations. Example from boost/operators.hpp:
>
>template <class T, class U, class B = ::boost::detail::empty_base>
>struct multipliable2 : B
>{
> friend T operator*(T x, const U& y) { return x *= y; }
> friend T operator*(const U& y, T x) { return x *= y; }
>};
>
>This works, but it prevents the NRVO (named return value optimization).
>An implemenation that solves this is:
>
>template <class T, class U, class B = ::boost::detail::empty_base>
>struct multipliable2 : B
>{
> friend T operator*(const T& x, const U& y)
> { T nrv( x ); nrv *= y; return nrv; }
>
> friend T operator*(const U& y, const T& x)
> { T nrv( x ); nrv *= y; return nrv; }
>};
>
>For further details, see also the thread "Temporaries and optimization?"
>in csc++. (A message not yet approved explains why the name should be
>'nrv', it should show up on csc++ in the next hours).
>
>Or is there anything I missed?
>
>Regards, Daniel
>
>--
>Daniel Frey
>
>aixigo AG - financial training, research and technology
>Schloß-Rahe-Straße 15, 52072 Aachen, Germany
>fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
>eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
>_______________________________________________
>Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com
PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
The five most dangerous words in the English language:
"There oughta be a law"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk