digitalmars.D.learn - Struct template
- deed (32/32) Nov 03 2014 struct Internal { int i; double d; string s; }
- John Colvin (5/37) Nov 03 2014 static if (is(typeof(T) == int))
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.
Nov 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.
Nov 03 2014
static if (is(typeof(T) == int)) should be static if (is(T == int)) T is already a type.Ahh. Thanks!
Nov 03 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?
Nov 04 2014









"deed" <none none.none> 