
On 5/31/05, Maksym Motornyy <mmotorny@yandex.ru> 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