http://d.puremagic.com/issues/show_bug.cgi?id=6740

           Summary: Can't call variadic type argument as a template
                    function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-09-28 
11:25:03 PDT ---
template test(T, Preds...)
{
    enum bool test = Preds[0]!T;  // error: semicolon expected, not '!'
}

Example use-case:

import std.traits;
template anyPredicateSatisfy(T, Preds...) 
{
   static if (Preds.length)
       enum bool anyPredicateSatisfy = (Preds[0]!T) || anyPredicateSatisfy!(T,
Preds[1 .. $]);
   else
       enum bool anyPredicateSatisfy = false;
}

void main()
{
    assert(anyPredicateSatisfy!(int, isFloatingPoint, isIntegral));
}

A workaround (by Bearophile) is:

template satisfies(T, alias P) { enum satisfies = P!T; }

template anyPredicateSatisfy(T, Preds...) 
{
   static if (Preds.length)
       enum bool anyPredicateSatisfy = satisfies!(T, Preds[0]) ||
anyPredicateSatisfy!(T, Preds[1 .. $]);
   else
       enum bool anyPredicateSatisfy = false;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to