Bug 6740 – Can't call variadic type argument as a template function

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-09-28T11:25:00Z
Last change time
2013-02-10T09:10:37Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-09-28T11:25:03Z
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; }
Comment #1 by andrej.mitrovich — 2013-02-10T09:10:37Z
*** This issue has been marked as a duplicate of issue 6474 ***