|
Boost : |
From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2005-05-31 09:40:46
On 5/31/05, Maksym Motornyy <mmotorny_at_[hidden]> wrote:
> I know that my idea is trivial but this thing is missing in Boost. In
> some cases it is useful to have copy-on-write objects. For example,
> everybody knows that returning std::string from a function is not very
> efficient (actually that's why in Qt strings are implemented as
> copy-on-write ones).
There's a pretty nice implementation of COW objects in the Adobe Open
Source library (http://opensource.adobe.com). You might take a look
at that.
> copy_on_write< std::string > concatenate(
> const std::string &first, const std::string &second )
> {
> copy_on_write< std::string > result;
> result->assign( first );
> result->append( second );
> return result;
> }
Not that COW wouldn't be a nice tool to have in the Boost arsenel,
this is not a great example of how and when to use it. A compiler
that implements NRVO (Named Return Value Optimization) can return an
object (essentially) by const reference without any special COW
wrapper classes. Also, some C++ Standard Library implementations use
a reference-counted std::string implementation, so this extra effort
would be wasted.
-- Caleb Epstein caleb dot epstein at gmail dot com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk