http://d.puremagic.com/issues/show_bug.cgi?id=6573
Summary: Add isOneOf to std.traits
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Andrej Mitrovic <[email protected]> 2011-08-29
19:15:23 PDT ---
I think Steven Schveighoffer came up with this originally:
template isOneOf(X, T...)
{
static if (!T.length)
enum bool isOneOf = false;
else static if (is (X == T[0]))
enum bool isOneOf = true;
else
enum bool isOneOf = isOneOf!(X, T[1..$]);
}
It's very useful as a replacement for multiple checks on a single type
parameter, e.g.:
void foo(T)(T t) if (is(T == Type1) || is(T == Type2) || is(T == Type3))
turns into:
void foo(T)(T t) if (isOneOf!(T, Type1, Type2, Type3))
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------