Boost logo

Boost :

From: Maxim Yegorushkin (maxim.yegorushkin_at_[hidden])
Date: 2006-07-07 03:28:50


Jody Hagins wrote:

> I'm the one asking YOU for reasons why immutable interfaces should be
> used over mutable ones ;-) You are the one making a proposal in favor
> of immutable interfaces. Aside from being able to represent the
> functional paradigm in C++, what are the benefits from your point of
> view? I've read several papers, and I've used several similar
> libraries, but I want your experience stories because I respect your
> talent and experience.
>
> Why should the interfaces for string (or other boost libraries) be
> immutable? I am unaware of an immutable implementation that provides
> transparent performance cost. I'd be most interested if you know of
> one.

Because it is desirable to have cheap string copying. The most effective
solution is to use reference counted string with copy-on-write. AFAIK,
no one has come up with a thread safe implementation for COW
std::basic_string, it's interface is too leaky (operator[] returns a
bare char&, for example). Although GNU C++ std::basic_string is
reference counted and COW they say it is not thread safe in some corner
cases.
http://groups.google.com/group/comp.lang.c++.moderated/msg/0aa848d97e205d72

Cheap copy is the only motivation behind an immutable string. One
implementation has been reported to perform well as a drop-in
replacement for std::basic_string.
http://article.gmane.org/gmane.comp.lib.boost.devel/110029


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