const debacle

Christopher Wright dhasenan at gmail.com
Sun Mar 23 16:29:50 PDT 2008


Janice Caron wrote:
> 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.

In that case, the following should, in theory, work:

class A {}
class B
{
    A opImplicitCast()
    {
       // ...
    }
}

template Template(T : A){}
Template!(B);

Of course, that fails.



More information about the Digitalmars-d mailing list