Boost logo

Boost :

From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2020-06-02 13:55:07


Am 02.06.20 um 15:38 schrieb Peter Dimov via Boost:
> Alexander Grund wrote:
>
>> With an API like `result<Foo> do() noexcept` instead of `Foo do()`
>> you won't get (N)RVO when you return a `Foo` (in the happy case) as
>> the standard only allows it when the types are exactly the same.
>
> This doesn't matter much nowadays. E.g. in
> https://godbolt.org/z/zC-Cah if you remove x.f(), x goes away.
Not sure if that really proves the point. I think you need to compare a
result<X> function to a function returning X directly. Like so:
https://godbolt.org/z/JFmn_j

And for that there is a difference: There are 4 main memory accesses in
the result<X> function and none in the "regular" one.

Writing and reading those values likely influences performance for the
worse. However it looks like for large objects (like Y above) there
seems to be no difference indeed and it very much looks like RVO is
happening. Didn't expect that.

So there is only a difference for small and trivial types which will be
passed through RAM instead of registers.




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