const and phobos string functions
    Regan Heath 
    regan at netmail.co.nz
       
    Thu Aug  2 08:02:18 PDT 2007
    
    
  
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).
True.
> I also had some fancy ideas for a CoW wrapper, which looks something like:
<snip>
I wrote something like that once too.
Regan
    
    
More information about the Digitalmars-d
mailing list