http://d.puremagic.com/issues/show_bug.cgi?id=4239



--- Comment #2 from Simen Kjaeraas <simen.kja...@gmail.com> 2010-05-26 15:20:55 
PDT ---
(In reply to comment #1)
> This seems to work fine:
> 
> struct X(T...) { }
> 
> static assert(is(X!(int, int) == X!(int, int)));
> static assert(is(X!(int, "foo") == X!(int, "foo")));
> static assert(!is(X!(int, "foo") == X!("foo", int)));

Indeed it does. I do however still feel it should be included in Phobos as
something more obvious.
Simplified version, with newly acquired knowledge:

/**
Compares tuples that might contain a mixture of types and values.

Example:
----
static assert(SameTuple!(int, int).As!(int, int));
static assert(SameTuple!(int, "foo").As!(int, "foo"));
static assert(!SameTuple!(int, "foo").As!("foo", int));
----
 */

struct SameTupleImpl(T...) {
}

template SameTuple(T...) {
    template As(U...) {
        enum As = is( SameTupleImpl!T == SameTupleImpl!U );
    }
}

unittest {
    static assert(SameTuple!(int, int).As!(int, int));
    static assert(SameTuple!(float).As!(float));
    static assert(SameTuple!("foo").As!("foo"));
    static assert(!SameTuple!("foo").As!("bar"));
    static assert(!SameTuple!(int ).As!("bar"));
    static assert(!SameTuple!(int ).As!(float));
    static assert(SameTuple!(int, "foo").As!(int, "foo"));
    static assert(!SameTuple!(int, "foo").As!("foo", int));
    static assert(SameTuple!().As!());
    static assert(!SameTuple!(int).As!());
    static assert(!SameTuple!().As!(int));
    static assert(!SameTuple!("foo").As!());
    static assert(!SameTuple!().As!("foo"));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to