import std.datetime, std.algorithm, std.typecons, std.stdio; auto either(Keys...)(Keys keys) { static struct Result { bool opIn_r(Key)(Key key) { foreach (k; keys) { if (k == key) { return true; } } return false; } private Keys keys; } return Result(keys); } struct ctEither(keys...) { @safe bool opBinaryRight(string op:"in", T)(in T x) const pure nothrow { foreach (k; keys) if (x == k) return true; return false; } } struct ctEither2(keys...) { @safe bool opBinaryRight(string op:"in", T)(in T x) const pure nothrow { switch (x) { default: return false; foreach (k; keys) { case k: return true; } } return false; } } __gshared int p = 1234567890; void a() { assert(p !in ctEither!(1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789)() ); } void b() { assert(p !in either(1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789)); } void c() { assert(![1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789].canFind(p)); } void d() { assert(!(p == 1 || p == 12 || p == 123 || p == 1234 || p == 12345 || p == 123456 || p == 1234567 || p == 12345678 || p == 123456789)); } void e() { assert(p !in ctEither2!(1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789)() ); } void main() { writeln( benchmark!c(1_000_000)[0].to!("msecs", int) ); writeln( benchmark!a(1_000_000)[0].to!("msecs", int) ); writeln( benchmark!b(1_000_000)[0].to!("msecs", int) ); writeln( benchmark!d(1_000_000)[0].to!("msecs", int) ); writeln( benchmark!e(1_000_000)[0].to!("msecs", int) ); }