Thread overview
Struct template
Nov 03, 2014
deed
Nov 03, 2014
John Colvin
Nov 03, 2014
deed
Nov 04, 2014
Meta
November 03, 2014
struct Internal { int i; double d; string s; }

struct External_int {
  Internal internal;
  @property Internal* ptr () { return &internal; }
	
  this (int a)
  {
    internal.s = "int";
    internal.i = a;
  }
}

struct External (T) {
  Internal internal;
  @property Internal* ptr () { return &internal; }
	
  static if (is(typeof(T) == int))
  {
    this (T a)
    {
      internal.s = "int";
      internal.i = a;
    }
  }
}

void main ()
{
  auto e1 = External_int(1); // Ok
  auto e2 = External!int(1); // Nope, cannot implicitly
                             // convert expression (1)
                             // of type int to Internal
}


Why? And how is this fixed? Thanks.
November 03, 2014
On Monday, 3 November 2014 at 17:03:33 UTC, deed wrote:
> struct Internal { int i; double d; string s; }
>
> struct External_int {
>   Internal internal;
>   @property Internal* ptr () { return &internal; }
> 	
>   this (int a)
>   {
>     internal.s = "int";
>     internal.i = a;
>   }
> }
>
> struct External (T) {
>   Internal internal;
>   @property Internal* ptr () { return &internal; }
> 	
>   static if (is(typeof(T) == int))
>   {
>     this (T a)
>     {
>       internal.s = "int";
>       internal.i = a;
>     }
>   }
> }
>
> void main ()
> {
>   auto e1 = External_int(1); // Ok
>   auto e2 = External!int(1); // Nope, cannot implicitly
>                              // convert expression (1)
>                              // of type int to Internal
> }
>
>
> Why? And how is this fixed? Thanks.

static if (is(typeof(T) == int))

should be

static if (is(T == int))


T is already a type.
November 03, 2014
> static if (is(typeof(T) == int))
>
> should be
>
> static if (is(T == int))
>
>
> T is already a type.

Ahh. Thanks!
November 04, 2014
On Monday, 3 November 2014 at 17:05:21 UTC, John Colvin wrote:
> static if (is(typeof(T) == int))
>
> should be
>
> static if (is(T == int))
>
>
> T is already a type.

I thought this was supposed to produce an error message rather than fail silently... I'm positive this used to be an error. Did it change?