Limiting template functions to template instantiations of a struct

Namespace rswhite4 at googlemail.com
Wed Nov 6 05:19:30 PST 2013


On Wednesday, 6 November 2013 at 13:00:17 UTC, Atila Neves wrote:
> 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

This works:
http://dpaste.dzfl.pl/f98f4783


More information about the Digitalmars-d-learn mailing list