[Issue 6740] New: Can't call variadic type argument as a template function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 28 11:25:40 PDT 2011
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: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at 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: -------
More information about the Digitalmars-d-bugs
mailing list