Fully transitive const is not necessary
Sean Kelly
sean at invisibleduck.org
Sun Apr 27 09:52:49 PDT 2008
Janice Caron wrote:
> On 27/04/2008, Sean Kelly <sean at invisibleduck.org> wrote:
>> what do they achieve that could not have been
>> achieved via plain old const strings?
>
> In a word: (OK - in three words): Copy On Write.
>
> For example, one could write a function
>
> string escape(string s);
>
> which escaped certain characters (by preceding them with '\' or
> whatever). Because s is an array of invariant chars, if nothing needs
> to be escaped, the function is able to return s.
So this is predicated on the idea that the optimal strategy is to assume
that library functions will not actually need to make any changes the
majority of the time, and that they do COW internally. Fair enough. I
agree that this makes it a clear win for Phobos, which is designed
around this assumption.
Sean
More information about the Digitalmars-d
mailing list