Re: Is it possible to check if a type is an instance of a template?

2014-05-06 Thread Andrej Mitrovic via Digitalmars-d-learn
On 5/6/14, bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: There is now std.traits.isInstanceOf that could do what you need. Someone resurrected a thread from 2011. Of course there's isInstanceOf when I added it myself at the end of 2012.

Re: Is it possible to check if a type is an instance of a template?

2014-05-05 Thread Nordlöw
template IsAFoo(T) { static if (is(T t == Foo!U, U)) { enum IsAFoo = true; } else { enum IsAFoo = false; } } Can we make Foo a template parameters aswell, here? I tried this template IsA(T, K) { static if (is(T t == K!U, U)) { enum IsA = true; }

Re: Is it possible to check if a type is an instance of a template?

2014-05-05 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 5 May 2014 at 23:28:58 UTC, Nordlöw wrote: template IsAFoo(T) { static if (is(T t == Foo!U, U)) { enum IsAFoo = true; } else { enum IsAFoo = false; } } Can we make Foo a template parameters aswell, here? I tried this template IsA(T, K) { static if (is(T

Re: Is it possible to check if a type is an instance of a template?

2014-05-05 Thread bearophile via Digitalmars-d-learn
Andrej Mitrovic: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? There is now std.traits.isInstanceOf that could do what you need. Its

Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently having to hardcode via: template bar(T) if (isOneOf!(T, Foo!int,

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:24:50 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do?

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Timon Gehr
On 09/15/2011 10:24 PM, Andrej Mitrovic wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently having to hardcode

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
Cool, that works, thanks. Is this in Phobos by any chance? Otherwise I'll just use a more flexible version of that.

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 13:24 Andrej Mitrovic wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
On 9/15/11, Timon Gehr timon.g...@gmx.ch wrote: template bar(T : Foo!S,S){ } Yeah, that should do it too. Thanks.

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 13:45 Andrej Mitrovic wrote: Cool, that works, thanks. Is this in Phobos by any chance? How could it be? It's specific to the template that you're testing. - Jonathan M Davis

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
On 9/15/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Every template instantiation is a new set of code with _zero_ assocation with any other template instantation. Yeah, I know. But I don't think this has to be set in stone. Having some specific compile-time type information about a

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:45:21 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Cool, that works, thanks. Is this in Phobos by any chance? Otherwise I'll just use a more flexible version of that. No more flexible version available, sadly. I wish this worked (I think it's in Bugzilla

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 14:17 Andrej Mitrovic wrote: On 9/15/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Every template instantiation is a new set of code with _zero_ assocation with any other template instantation. Yeah, I know. But I don't think this has to be set in stone.