Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 09, 2015 AliasSeq + isExpression type specialization behavior | ||||
---|---|---|---|---|
| ||||
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? |
November 10, 2015 Re: AliasSeq + isExpression type specialization behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Schott | 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
|
November 10, 2015 Re: AliasSeq + isExpression type specialization behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | 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.
|
November 10, 2015 Re: AliasSeq + isExpression type specialization behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Schott | 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.
|
November 10, 2015 Re: AliasSeq + isExpression type specialization behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Schott | 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.
|
Copyright © 1999-2021 by the D Language Foundation