www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - AliasSeq + isExpression type specialization behavior

reply Brian Schott <briancschott gmail.com> writes:
Given the following code:
```
import std.meta;

static assert(is(char : dchar));
static assert(is(AliasSeq!(int, char) : AliasSeq!(int, char)));
static assert(is(AliasSeq!(int, char) : AliasSeq!(int, dchar)));
```

The third static assert fails. Should it, given that the first 
and second pass?
Nov 09 2015
next sibling parent reply Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
On Monday, 9 November 2015 at 22:41:50 UTC, Brian Schott wrote:
 Given the following code:
 ```
 import std.meta;

 static assert(is(char : dchar));
 static assert(is(AliasSeq!(int, char) : AliasSeq!(int, char)));
 static assert(is(AliasSeq!(int, char) : AliasSeq!(int, dchar)));
 ```

 The third static assert fails. Should it, given that the first 
 and second pass?
This fails, too: static assert(is(AliasSeq!(char) : AliasSeq!(dchar))); Which makes sense IMO, because it can be thought of as an unnamed struct, cp. the following: struct A { char c; } struct B { dchar c; } static assert(is(A : B)); // fails, as expected
Nov 10 2015
parent reply Brian Schott <briancschott gmail.com> writes:
On Tuesday, 10 November 2015 at 10:28:45 UTC, Marc Schütz wrote:
 This fails, too:
 static assert(is(AliasSeq!(char) : AliasSeq!(dchar)));

 Which makes sense IMO, because it can be thought of as an 
 unnamed struct, cp. the following:

 struct A { char c; }
 struct B { dchar c; }
 static assert(is(A : B)); // fails, as expected
You're talking about Tuple. I'm talking about AliasSeq.
Nov 10 2015
parent Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
On Tuesday, 10 November 2015 at 13:47:23 UTC, Brian Schott wrote:
 On Tuesday, 10 November 2015 at 10:28:45 UTC, Marc Schütz wrote:
 This fails, too:
 static assert(is(AliasSeq!(char) : AliasSeq!(dchar)));

 Which makes sense IMO, because it can be thought of as an 
 unnamed struct, cp. the following:

 struct A { char c; }
 struct B { dchar c; }
 static assert(is(A : B)); // fails, as expected
You're talking about Tuple. I'm talking about AliasSeq.
A Tuple is just a struct with an AliasSeq member. Or seen from a different POV, an AliasSeq can be interpreted as the "innards" of the struct. IMO it therefore makes sense to expect an AliasSeq to behave analogously to a struct. The only exception to that is that AliasSeq auto-expands, of course.
Nov 10 2015
prev sibling parent Alex Parrill <initrd.gz gmail.com> writes:
On Monday, 9 November 2015 at 22:41:50 UTC, Brian Schott wrote:
 Given the following code:
 ```
 import std.meta;

 static assert(is(char : dchar));
 static assert(is(AliasSeq!(int, char) : AliasSeq!(int, char)));
 static assert(is(AliasSeq!(int, char) : AliasSeq!(int, dchar)));
 ```

 The third static assert fails. Should it, given that the first 
 and second pass?
`:` in `is` is for testing whether the left type is implicitly convertible to the right type. `char` is implicitly convertible to `dchar` by promoting it. But `AliasSeq`s are collections; they're only implicitly convertible to themselves.
Nov 10 2015