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: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Andrej Mitrovic <[email protected]> 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: -------