|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-10-22 17:23:59
Daniel Frey <d.frey_at_[hidden]> writes:
> On Tue, 22 Oct 2002 22:14:26 +0200, David Abrahams wrote:
>
> > Daniel Frey <d.frey_at_[hidden]> writes:
> >
> >> this is equivalent to:
> >>
> >> T operator+( const T& lhs, const T& rhs ) {
> >> return T( lhs ).operator+=( rhs );
> >> }
> >
> > Not neccessarily. It's possible to implement += as a free function. I'm
> > not sure if that's relevant to your argument or just a red herring.
>
> Well, OK, it could be a free function, but
>
> return operator+=( T( lhs ), rhs );
>
> doesn't look any better wrt RVO, does it? ;)
My attention is divided at the moment, so I can't answer with
authority. I trust your analysis.
> > I don't know how well that works. You need to know that T
> > implements the appropriate constructor, which AFAICT isn't
> > possible for a generic function.
>
> Are you talking about a Mojo-friendly implementation?
Yeah.
> > I offered to run any test program posted, but nobody gave me one to try.
>
> Oh, I think I can change that:
>
> #include <iostream>
> using namespace std;
>
> struct X
> {
> X() { cout << "X"; }
> X( const X& ) { cout << "C"; }
> };
>
> X f()
> {
> return X();
> }
>
> X g()
> {
> X x;
> return x;
> }
>
> int main()
> {
> X x1( f() ); cout << endl;
> X x2( g() ); cout << endl;
> }
gcc-2.95.3
X
XC
gcc-3.0.4
XC
XCC
gcc-3.2:
X
X
cwpro7.2:
XC
XCC
cwpro8.2
X
XC
cwpro8.3:
X
X
vc6:
X
XC
vc7:
X
XC
vc7.1:
X
XC
intel C++ 5.0
XC
XC
intel-6.0
XC
XC
intel 7 beta (no optimization - release mode fails to link):
XC
XC
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Building C/C++ Extensions for Python: Dec 9-11, Austin, TX http://www.enthought.com/training/building_extensions.html
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk