
4 Oct
2011
4 Oct
'11
7:22 p.m.
On 10/4/2011 12:16 PM, Nathan Ridge wrote:
If the operations return "type&&" instead of "type", they can potentially be more efficient, but I'm a little cautious to do that without giving it some thought because the choice implies subtle differences. I'm sure Daniel has already taken this all into consideration.
Return by value please. Otherwise:
type const& x = type() + type(); std::cout << x; // BOOM; x is dangling
Won't the following fail too, making it completely useless?
void foo(type const& x) { ... }
foo(type() + type());
No, because the temporary created by "type() + type()" is guaranteed to live until after foo returns. -- Eric Niebler BoostPro Computing http://www.boostpro.com