Ok, I may found the reference.
It isn't the special case of "return value optimization", but "copy elision", which is the name of the more general concept where compilers are allowed to skip copying of objects.
Wikipedia:
http://en.wikipedia.org/wiki/Copy_elision
Interesting is the sentence "The optimization can not be applied to a temporary object that has been bound to a reference."
I am still not quite sure whether my example is a valid one. (And whether the temporary Foobar from "foobarCreator" can be created on the memory location of "Barfoo_byvalue" directly without any copy constructor call.)
Thanks hanst99, I already skimmed over the RVO article, but thanks to you, I now found the link to copy elision ;)
@moorecm: Yes, line 14 and 20 are copy constructors. Of course, *if* they are called, they *will* copy something ;). But they are not required to be called all the time. That's what RVO (and in general, elision) is about ;)
@PanGalactic: Yep, I know of the move semantic and std::move, but I am restricted to pre-C++0x for now and still want to save on copies. :)
And well... it doesn't matter whether I could theoretically save on copies, if my !"&// compiler don't implement it. I hope to figure out in which cases copies are avoidable and maybe I get some better result...
At the end of the day, I'll probably use this anyway:
1 2 3 4
|
createFoobar(Foobar* createMeHere) { ... }
...
Barfoo b();
createFoobar(&b.f);
|
;-)