Created
April 3, 2018 06:37
-
-
Save run-dlang/2e9f990323afd2c48b29ca3d56178c06 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Test(T...) | |
{ | |
T field; | |
this (T t) { field = t; } | |
bool opEquals(R...)(const auto ref R rhs) inout | |
{ | |
static foreach (i, _; T) | |
if (field[i] != rhs[i]) | |
return false; | |
return true; | |
} | |
} | |
struct Bad | |
{ | |
int a; | |
bool opEquals(Bad b) | |
{ | |
return a == b.a; | |
} | |
} | |
void main() | |
{ | |
import std.meta; | |
auto t = Test!(int, Bad, string)(1, Bad(1), "asdf"); | |
assert(t == AliasSeq!(1, Bad(1), "asdf")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment