View mode: basic / threaded / horizontal-split · Log in · Help
August 02, 2007
Re: const and phobos string functions
Reiner Pope wrote:
> I must say, I *like* the simplicity of overloading with a mutable and a 
> readonly version, although we have established that it can certainly 
> lead to some confusion. 

Provided it always performs a .dup when it modifies the input it should 
be fine.  i.e. take the existing tolower in std.string and simply change 
the function signature to:

T tolower(T)(T s)

and make no other changes and your example:

char[] s = "Hello World!".dup;
int a = howManyLettersDiffer(tolower(s), s);
assert (a == 2); // assert failed, a is actually 0

will work as expected.

> Mind you, D arrays ignore that potential
> confusion (in the .sort and .reverse properties).


> I also had some fancy ideas for a CoW wrapper, which looks something like:


I wrote something like that once too.

Next ›   Last »
1 2
Top | Discussion index | About this forum | D home