Limiting template functions to template instantiations of a struct

Atila Neves atila.neves at gmail.com
Wed Nov 6 05:00:16 PST 2013


The title isn't very clear but I wasn't sure how to phrase it 
without code. Basically what I want to do is this (won't compile):

struct Foo(int N) {
}

void func(T)(T obj) if(is(T:Foo)) {
}

void func(T)(T obj) if(!is(T:Foo)) {
}

Foo by itself isn't a type, but I don't want to limit func 
instantiation in the 1st case to just e.g. Foo!3 but to _any_ Foo 
regardless of N. I came up with two workarouds: make Foo a class 
that derives from an empty FooBase (then is(T:FooBase) works), or 
adding a "secret" enum within Foo that I can check with 
std.traits.hasMember in a static if. I don't really like either 
of them. Is what I want to do possible?

Atila


More information about the Digitalmars-d-learn mailing list