Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2002-10-22 13:58:39

On Tue, 22 Oct 2002 19:12:55 +0200, Andrei Alexandrescu wrote:

> Just to eliminate any potential confusion on my part, I assume you
> merely repeat in English what the code says.


>>Multiple returns are indeed a problem, but it's usually possible to keep
> that in mind and design functions to be (N)RVO-friendly.<
> So if my understanding above is correct (and I have to say that your
> post didn't give me any clue on whether that's the case or not), it's
> better to return temporaries rather than named values, because URVO is
> likely to be much more widespread and reliable than NRVO.

URVO is preferable, yes. It works almost everywhere, but sometimes - like
for operator+ - the URVO can't help, you need the NRVO. In these cases I
think it's essential to help the compiler:

T f()
  T nrv;
  // add your code here ...
  return nrv;

where your code in between shouldn't contain any 'return' statements.
('throw' is AFAIK OK). That way you can rely on the compiler to apply the
NRVO (if the compiler implements it, so this obviously needs to be
checked first). I cut the rest of the message to prevent further
confusion :o)

Regards, Daniel

Boost list run by bdawes at, gregod at, cpdaniel at, john at