
4 Mar
2005
4 Mar
'05
12:30 a.m.
Pavel Chikulaev wrote:
Do you know that well-known Herb Sutter's assignment operator in most cases does unnecessary copying?
I don't know that it's "Herb's" assignment operator. He certainly popularized the idiom with his book, but it may have existed before that.
[...] Matrix func (); Matrix a; //... Matrix = func();
Result of func() is copied to temporary objectand then operator = copies it again. So assigning to result of function creates one useless object. [...]
I would like to see compiler tests that show that neither RVO nor NRVO work in these cases first. Dave