[Issue 6573] Add isOneOf to std.traits
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Aug 29 20:16:53 PDT 2011
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=6573
--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-08-29 20:16:51 PDT ---
However the code will have to be slightly improved.
If you accidentally pass a tuple followed by a single type things can get
weird.
E.g.:
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..$]);
}
void test(T...)(T t)
{
    static assert (isOneOf!(T, double));  // passes by mistake
    static assert (isOneOf!(double, T));  // ok, fails properly
}
void main()
{
    test(1, 2, 3);
}
So that's something to improve.
-- 
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