Comparing two AliasSeq
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Mar 24 21:23:31 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list