Re: Limiting template functions to template instantiations of a struct

2013-11-07 Thread Marco Leise
Am Wed, 06 Nov 2013 14:22:13 +0100 schrieb simendsjo simend...@gmail.com: template isFoo(T) { static if(is(T:Foo!U, int U)) enum isFoo = true; else enum isFoo = false; } enum isFoo(T) = is(T:Foo!U, int U); correct ? -- Marco

Re: Limiting template functions to template instantiations of a struct

2013-11-07 Thread simendsjo
On Thursday, 7 November 2013 at 15:46:53 UTC, Marco Leise wrote: Am Wed, 06 Nov 2013 14:22:13 +0100 schrieb simendsjo simend...@gmail.com: template isFoo(T) { static if(is(T:Foo!U, int U)) enum isFoo = true; else enum isFoo = false; }

Re: Limiting template functions to template instantiations of a struct

2013-11-07 Thread Timon Gehr
On 11/07/2013 12:07 AM, H. S. Teoh wrote: // This is possibly the single nastiest bit of syntax in all of D: static if (is(func X == __parameters)) { // Quick, without looking at the docs: what does X refer // to? Nothing.

Limiting template functions to template instantiations of a struct

2013-11-06 Thread Atila Neves
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

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread simendsjo
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)) {

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Namespace
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)) {

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Atila Neves
Wow. It didn't even occur to me that `is` could be used like that. I think that operator is the hardest part of the language for me to grok. Thanks guys!

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 21:49:52 UTC, Atila Neves wrote: Wow. It didn't even occur to me that `is` could be used like that. I think that operator is the hardest part of the language for me to grok. Thanks guys! http://dlang.org/expression.html#IsExpression ;)

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Atila Neves
On Wednesday, 6 November 2013 at 21:52:04 UTC, Dicebot wrote: On Wednesday, 6 November 2013 at 21:49:52 UTC, Atila Neves wrote: Wow. It didn't even occur to me that `is` could be used like that. I think that operator is the hardest part of the language for me to grok. Thanks guys!

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 22:41:08 UTC, Atila Neves wrote: I know, but I keep having to refer back to that and even then I didn't know about the syntax these guys just posted! ;) Well, it is mentioned in the list of `is` usage cases down that link. It is very ugly part of the language

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread Namespace
On Wednesday, 6 November 2013 at 22:43:18 UTC, Dicebot wrote: On Wednesday, 6 November 2013 at 22:41:08 UTC, Atila Neves wrote: I know, but I keep having to refer back to that and even then I didn't know about the syntax these guys just posted! ;) Well, it is mentioned in the list of `is`

Re: Limiting template functions to template instantiations of a struct

2013-11-06 Thread H. S. Teoh
On Wed, Nov 06, 2013 at 11:52:56PM +0100, Namespace wrote: On Wednesday, 6 November 2013 at 22:43:18 UTC, Dicebot wrote: On Wednesday, 6 November 2013 at 22:41:08 UTC, Atila Neves wrote: I know, but I keep having to refer back to that and even then I didn't know about the syntax these guys