V2 string
Regan Heath
regan at netmail.co.nz
Fri Jul 6 01:23:32 PDT 2007
Bruno Medeiros wrote:
> It doesn't make sense to template it, because you'd still have two
> different function versions, that would work differently. The one that
> receives a string does a dup, the one that receives a char[] does not
> dup. The return type of tolower(string str) might also be char[] and not
> string, if tolower(string str) would allways does a dup, even if no
> character modifications are necessary.
If the template is
T tolower(T)(T input) {}
then you have
string tolower(string input) {}
char[] tolower(char[] input) {}
and you cases are:
1. input string, output same string (no dup)
2. input string, output string (dup)
3. input char[], output same char[] (no dup)
Case #2 is admitedly not ideal because it may cause a later dup in your
code. But case #1 handles the efficient no modification case of string
and case #3 handles both modification and non-modification without any
call to dup.
I think the above is better than the current implementation as it avoids
a dup in case #3.
Regan
More information about the Digitalmars-d
mailing list