Comparing two AliasSeq

Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 24 21:57:26 PDT 2017


On Saturday, 25 March 2017 at 04:23:31 UTC, Jonathan M Davis 
wrote:
> On Saturday, March 25, 2017 03:25:27 Yuxuan Shui via 
> Digitalmars-d-learn wrote:
>> In this example:
>>
>>      import std.range;
>>      template expandRange(alias R) if 
>> (isInputRange!(typeof(R))) {
>>          static if (R.empty)
>>       alias expandRange = AliasSeq!();
>>          else
>>       alias expandRange = AliasSeq!(R.front(),
>> expandRange!(R.drop(1)));
>>      }
>>
>>      ///
>>      unittest {
>>          import std.range;
>>          static assert (is(expandRange!(iota(0,5)):
>> AliasSeq!(0,1,2,3,4)));
>>      }
>>
>> The static assert fails, why?
>
> Well, is expressions normally compare types, not values, and 
> AliasSeq!(0, 1, 2, 3, 4), isn't a type and doesn't contain 
> types.
>
> static assert(is(AliasSeq!int == AliasSeq!int));
>
> passes, whereas
>
> static assert(is(AliasSeq!0 == AliasSeq!0));
>
> does not. So, I expect that the issue is that you're dealing 
> with values rather than types. You're also using : instead of 
> ==, and : _definitely_ is for types (since it checks for 
> implicit conversion, not equality), so it wouldn't have 
> entirely surprised me if == worked when : didn't, but == 
> doesn't either.
>
> What you proobably should do is either convert the AliasSeq's 
> to dynamic
> arrays or ranges - e.g. [AliasSeq!(0, 1, 2, 3, 4)] or
> only(AliasSeq!(0, 1, 2, 3, 4)) - though in both cases, that 
> really only
> makes sense when you already have an AliasSeq, since [] and 
> only will take
> the values directly.
>
> - Jonathan M Davis

I see. I always thought tuple() is a type...

So a tuple of types is a type, but a tuple of mixed types and 
values is not a type. Doesn't seem very consistent.

Here is the solution I will go with:

	struct test(T...) { }
	import std.range;
	static assert (is(test!(expandRange!(iota(0,5))) == test!(0, 1, 
2, 3, 4)));




More information about the Digitalmars-d-learn mailing list