Re: Template constraint and specializations

2012-03-24 Thread Philippe Sigaud
On Fri, Mar 23, 2012 at 23:19, Andrej Mitrovic wrote: > Yes but check the isA template. It seems there's something causing a > nested variadic template to fail. This won't work in a template > constraint (it returns false): > But if you change "Args..." to "Args" then it works, although only for

Re: Template constraint and specializations

2012-03-23 Thread Andrej Mitrovic
On 3/23/12, Philippe Sigaud wrote: > It works for me Yes but check the isA template. It seems there's something causing a nested variadic template to fail. This won't work in a template constraint (it returns false): template isA(alias Foo) { template isA(T) { enum bool isA = __trai

Re: Template constraint and specializations

2012-03-23 Thread Philippe Sigaud
On Fri, Mar 23, 2012 at 21:27, Andrej Mitrovic wrote: > That can't work. For a Foo!int your code will expand like so: > See for yourself: ? It works for me: template isBar(T) { enum isBar = __traits(compiles, { vo

Re: Template constraint and specializations

2012-03-23 Thread Andrej Mitrovic
On 3/23/12, Philippe Sigaud wrote: > testFoo is a function that accepts any Foo!( ... ) for any ... The > second line tests it on a value of type T (T.init). That can't work. For a Foo!int your code will expand like so: // original code void tester(Args...)(Foo!Args args); tester(T.init); void

Re: Template constraint and specializations

2012-03-23 Thread Philippe Sigaud
On Fri, Mar 23, 2012 at 10:17, Ed McCardell wrote: >>> Is there a way to write a template constraint that matches any >>> >>> specialization of a given type? >> >> >> Nope. But there are simple workarounds: >> >> class Foo(bool feature1, bool feature2) { enum _isFoo = true; } >> >> template isFoo

Re: Template constraint and specializations

2012-03-23 Thread bearophile
Andrej Mitrovic: Nope. But there are simple workarounds: Why isn't something similar to this working? import std.traits: Unqual; class Foo(bool feature1, bool feature2) {} template isFoo(T) { static if (is(Unqual!T Unused : Foo!Features, Features...)) { enum isFoo = true; }

Re: Template constraint and specializations

2012-03-23 Thread Ed McCardell
On 03/23/2012 04:14 AM, Andrej Mitrovic wrote: On 3/23/12, Ed McCardell wrote: Is there a way to write a template constraint that matches any specialization of a given type? Nope. But there are simple workarounds: class Foo(bool feature1, bool feature2) { enum _isFoo = true; } template isFo

Re: Template constraint and specializations

2012-03-23 Thread Andrej Mitrovic
On 3/23/12, Ed McCardell wrote: > Is there a way to write a template constraint that matches any > specialization of a given type? Nope. But there are simple workarounds: class Foo(bool feature1, bool feature2) { enum _isFoo = true; } template isFoo(T) { enum bool isFoo = __traits(hasMember

Template constraint and specializations

2012-03-23 Thread Ed McCardell
Is there a way to write a template constraint that matches any specialization of a given type? For example can the following be done without having to write out every combination of feature1 and feature2: class Foo(bool feature1, bool feature2) { ... } void useFoo(T)(T foo) if (is(T ==