Create constraint for each parameter in template arg pack
vit
vit at vit.vit
Tue Aug 28 13:28:40 UTC 2018
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote:
> Hello,
> Let we have two variadic templates:
>> template Qwerty(Values...) {}
>> template Qaz(alias type, Data...) {}
>
> Now I want to add a constraint to "Qwerty" so that each type in
> "Values" pack must be a "Qaz" template. I don't care about
> values of "type" or "Data" in "Qaz".
> How to do it in D?
Generic solution:
template Qwerty(Values...)
if(allSatisfy!(isInstanceOf!Qaz, Values)){
}
class Qaz(alias type, Data...) {}
import std.meta : allSatisfy;
public import std.traits : isInstanceOf;
template isInstanceOf(alias T){
import std.traits : impl = isInstanceOf;
static enum isInstanceOf(alias X) = impl!(T, X);
static enum isInstanceOf(X) = impl!(T, X);
}
More information about the Digitalmars-d-learn
mailing list