Subject: Re: [boost] [submission] STL-compliant containers with copy-on-write
From: Jeremy Maitin-Shepard (jeremy_at_[hidden])
Date: 2011-03-31 17:07:23
On 03/31/2011 01:48 PM, Alexandr Sterligov wrote:
> Yes, sorry... I will be more careful with calling anything STL-compliant. It
> is only STL-like.
It seems that using a generic COW wrapper might be more suitable.
Internally it would maintain a pointer to a reference-counted instance
of the base type. It would provide a method for getting a const
reference to the type (e.g. get(), operator*() and operator->()), and
also a method for obtaining a non-const reference to a unique copy of
the type (e.g. get_unique()), which would take care of copying if the
reference count is greater than 1.
I believe this interface is better than a specialized type that tries to
mimic the interface of a particular container because generally if there
is a need to mutate the type, it will be done by a series of possibly
many mutating operations on the type/iterations, and it is inefficient
to check if there is a need to copy e.g. on each iterator dereference or
on each invocation of operator.
It also avoids the need to create the specialized types in the first
place; a single quite simple wrapper type will solve the problem for all
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk