ambiguation between char[] and dchar[]
Sean Kelly
sean at f4.ca
Tue Jul 10 08:18:51 PDT 2007
Oskar Linde wrote:
>
> I strongly prefer making char literals always pick the char[] overload.
> Changing the source code encoding should not affect its behavior imho.
I agree.
> In fact, I would like to make a suggest a slightly different fix to this
> problem, for D 2.0.
>
> - Make string literals be dynamic instead of static arrays. I.e.
> invariant char[], instead of invariant char[n].
>
> There is no loss of function, but it will resolve several issues:
>
> 1. ambiguous overload of foo(char[]), foo(dchar[]), foo(wchar[])
>
> 2. template function issues, such as:
>
> void foo(T)(T x) {...}
>
> foo("a"), foo("ab"), foo("abc"), foo("abcd"), foo("abcde")
I would love this, for the above reason. Currently, I tend to use
forwarding functions for array routines just to avoid code bloat from
static strings. Fortunately, I think the template mechanism is now
smart enough to pick dynamic array specializations if you pass static
arrays (it wasn't when I wrote my array routines), but that still requires:
void foo(T)(T[] x) {...}
Which obviously isn't always possible for template routines.
> will all (with static array string literals) result in distinct template
> instantiations and object file bloat.
>
> typeof("123") == typeof("abc"), but != typeof("abcd") ?
That one is annoying too.
Sean
More information about the Digitalmars-d
mailing list