Comparing TypeTuples
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 2 03:18:14 PDT 2014
On Tuesday, 2 September 2014 at 08:27:14 UTC, Tudor Berariu wrote:
> How can I check if two TypeTuples containing both types and
> values are the same?
> This fails:
>
> static assert(is(TypeTuple!(3, int, "Zorro") == TypeTuple!(3,
> int, "Zorro")));
>
> Thank you!
> Tudor
Yeah, this fails because you can't use "is(a == b)" with values.
However, *you* use "is(a)" to check if a is an actual type. Then,
you can do something like:
alias Args1 = TypeTuple!(3, int, "Zorro");
alias Args2 = TypeTuple!(3, int, "Zorro");
static assert(Args1.length == Args2.length);
foreach (I, _; Args1)
{
pragma(msg, I);
static assert(is(Args1[I]) == is(Args2[I]));
static if (is(Args1[I]))
static assert(is(Args1[I] == Args2[I]));
else
static assert(Args1[I] == Args2[I]);
}
More information about the Digitalmars-d-learn
mailing list