Request: a more logical static array behavior

Tommi tommitissari at hotmail.com
Thu Aug 15 09:23:51 PDT 2013


On Thursday, 15 August 2013 at 15:07:23 UTC, Tommi wrote:
> The only time when the compiler is willing to consider the 
> possible implicit conversions during type deduction is with 
> static arrays: hence... "magic".

Barring this special case which I mentioned in my original post:

On Thursday, 15 August 2013 at 00:57:26 UTC, Tommi wrote:
> NOTE:
> Subtypes can implicitly convert to their supertype during type 
> deduction, there's nothing magical about that.

Here's an example of that:

class SuperClass(T) { }

class SubClass(T) : SuperClass!T { }

struct Supertype(T) { }

struct Subtype(T)
{
     Supertype!T s;
     alias s this;
}

void foo(T)(SuperClass!T superc) { }

void bar(T)(Supertype!T supert) { }

void main()
{
     SubClass!int subc;
     foo(subc); // OK

     Subtype!int subt;
     bar(subt); // OK
}

Although, it might be a bit misleading to call that implicit 
conversion, because nothing is actually converted: it's just that 
an entity is interpreted as something else, which it also is.


More information about the Digitalmars-d mailing list