constraint on variadic template

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 7 08:55:23 PST 2016


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(T...)() {
>    foreach(s; T)
>       if(!__traits(hasMember, s, "run"))
>           return false;
>    return true;
> }
>
> and use that as the constraint:
>
> S(T...) if (test!T()) {}

Ah! An own constraint... Thanks! :)


More information about the Digitalmars-d-learn mailing list