const debacle

Janice Caron caron800 at googlemail.com
Sun Mar 23 12:02:38 PDT 2008


On 23/03/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
>  >    T strchr(T : const(char)[])(T s, char c)
>
> It isn't broken because the return type T is const.

Is it? In that case, I've misunderstood template syntax. I thought that

    (T : U)

meant any kind of T which could be implicitly cast to U, and that, therefore:

    (T : const(char)[])

would mean any kind of T which could be implicitly cast to
const(char)[] - which clearly includes char[]. If T can be char[] (as
I assumed) then the return type isn't necessarily const; if T cannot
be char[] (as you seem to be saying) then does that mean (T : U)
doesn't work as I thought it did?

I guess, if I've misunderstood template syntax that badly then
template syntax is /definitely/ too confusing.



More information about the Digitalmars-d mailing list