constraint on variadic template
Alex via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 7 08:35:52 PST 2016
Hi people,
have searched the history, but didn't find something similar:
say I have a template like
mixin template S(T...)
{
void run()
{
foreach(s; T)
{
static assert(__traits(hasMember, s, "run"));
}
}
}
How to formulate the check inside the foreach as a template
constraint with
mixin template S(T...) if(???)
have tried so far:
mixin template S(T...) if(__traits(hasMember, T, "run"))
but the compiler complies about
Error: expected 2 arguments for hasMember but had 3
which says to me, that the input is not taken value by value, but
all values as entirety.
tried:
if(T.each!(s => __traits(hasMember, s, "run")))
but it complies about
cannot deduce function from argument types !()(void, void)
which is ok, as the the provided types are templates by
themselves.
The formulation at the beginning works, but the intention is a
little bit different.
Thanks in advance
Alex
More information about the Digitalmars-d-learn
mailing list