August 02, 2007 Re: const and phobos string functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Reiner Pope | 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 |
Copyright © 1999-2021 by the D Language Foundation