Re: constraint on variadic template

2016-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 17:32:14 UTC, Alex wrote: enum hasRun(T) = __traits(hasMember, T, "run"); This is strange... I expect this to work... but it does not... hasRun there ONLY takes types, whereas T... can take types, values, aliases, etc. Try making it hasRun(T...) and

Re: constraint on variadic template

2016-12-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 17:05:11 UTC, H. S. Teoh wrote: Try this: import std.meta : allSatisfy; enum hasRun(T) = __traits(hasMember, T, "run"); mixin template S(T...) if (allSatisfy!(hasRun, T)) { void run() {

Re: constraint on variadic template

2016-12-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 17:08:09 UTC, Gary Willoughby wrote: Will some like this work? import std.range.primitives; mixin template S(T...) if(__traits(hasMember, ElementType!(T), "run")) { ... } https://dlang.org/phobos/std_range_primitives.html#ElementType

Re: constraint on variadic template

2016-12-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 07, 2016 at 04:35:52PM +, Alex via Digitalmars-d-learn wrote: > 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) > { > stati

Re: constraint on variadic template

2016-12-07 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 16:35:52 UTC, Alex wrote: 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

Re: constraint on variadic template

2016-12-07 Thread Alex via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 16:48:08 UTC, Adam D. Ruppe wrote: On Wednesday, 7 December 2016 at 16:35:52 UTC, Alex wrote: void run() { foreach(s; T) { static assert(__traits(hasMember, s, "run")); } } Just put that in a function: bool test(

Re: constraint on variadic template

2016-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 16:35:52 UTC, Alex wrote: void run() { foreach(s; T) { static assert(__traits(hasMember, s, "run")); } } Just put that in a function: bool test(T...)() { foreach(s; T) if(!__traits(hasMember, s, "run"))

constraint on variadic template

2016-12-07 Thread Alex via Digitalmars-d-learn
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 for