Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created April 3, 2018 06:37
Show Gist options
  • Save run-dlang/2e9f990323afd2c48b29ca3d56178c06 to your computer and use it in GitHub Desktop.
Save run-dlang/2e9f990323afd2c48b29ca3d56178c06 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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