Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2007-08-10 09:10:42


Martin Bonner wrote:
> loufoque wrote:
>> Libraries that produce needless copies are simply ill-designed,
> The obvious case is return by value. I know that there are some compiler optimizations that can help here, but we have to work with the compilers we have.

No exisiting decent C++ compiler doesn't perform NRVO.
The only compiler I know that performs RVO and not NRVO is MSVC6, and it
certainly isn't decent.

NRVO is such an obvious optimization that a C++ compiler that doesn't do
it is no good in my opinion.

Returning by copy still implies copying (or moving) when it is not the
initialization of a variable, but nothing can really be done about that
unless the function is nothrow (in that case, we could destruct then
re-initialize the variable, but the C++ standard doesn't allow that anyway).

> The other case is standard containers (and yes, I know I snipped your comment that the standard library is badly designed). Until we have a C++09 compiler that supports move, maps etc involve a lot of copying.

Move is NOT the solution at all. Move only reduces the cost of copying
in a few cases.
While useful for std::vector is the case of resizing, the problem is not
here. The problem is that it is not possible to construct objects in
place in the container. It would be trivial to do so by generalizing use
of something similar to boost in-place, but it's only used by boost
optional AFAIK.

>> - Sharing, if used, works way better with immutable objects.
> Well yes. I don't know about Hervé, but I would have thought a shared string class would indeed be immutable

Actually I was more replying to "why std::string does not use sharing" here.


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