Boost logo

Boost :

Subject: Re: [boost] Temporary objects
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-11-03 12:26:48


DE wrote
> on 31.10.2009 at 17:12
> Mathias Gaunard wrote :
>>> afaik nrvo is not implemented in msvc80
>> RVO is implemented since MSVC6, NRVO since MSVC7.
> you might know better
> however afaik these are of very limited use

They do what the name says.

> i mean that in an example like
>
> type foo(const type &to_be_processed)
> {
> type ret;
> //processing
> return ret;
> }
>
> semantics of the copy constructor does matter

No, they don't.

> here nrvo likely not to take place (actually it should NOT take place)

That's exactly the case where it will.

> afaik by the standard a compiler only allowed to directly construct a
> temporary only in case like
>
> type bar(const other &a)
> {
> intermediate i;
> //???
> return type(i);
> }
> //...
> res = bar(input);

This is a bad example of RVO which doesn't actually work. There will
still be a temporary here.

> well, to this point i still think that a temporary<type> better
> reflects the underlying semantics than, i guess, BOOST_RV_REF(type) (looks extremely ugly)

The point of the macro is that it can use type&& (rvalue references) or
temporary<type> depending on what is available.

> i have a picture of that and you can't imagine how hard i wait for
> the new standard
> but for now i try to exploit existing tools
> that's why all these perversions exist

The right approach is to design systems that look that those of the
future, that can use the future features when available and that
fallback on emulation techniques when they're not.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk