Summary: Add isOneOf to std.traits
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Andrej Mitrovic <> 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;
        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:
------- You are receiving this mail because: -------

Reply via email to