Boost logo

Boost :

From: Maksym Motornyy (mmotorny_at_[hidden])
Date: 2005-05-31 06:14:54


Hello All,

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).

Consider following code:

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;
}

// somewhere else
std::cout << *concatenate( "Hello,", " world!" ) << std::endl;

Here no string copy occurs.

One can invent a lot of different applications of copy-on-write
techinque (strings, iterators, memory pages). I have an implementation,
now let community decide if this can be a part of Boost.

Sincerely yours,
Maksym Motornyy.


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