[Issue 6573] New: Add isOneOf to std.traits
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 29 19:15:26 PDT 2011
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: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 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: -------
More information about the Digitalmars-d-bugs
mailing list