Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws. immutable(T)[] toString(T)(const(T)* str) if(typeof(T) is dchar)//this is where the error is { return

Re: Error with constraints on a templated fuction

2014-08-25 Thread bearophile via Digitalmars-d-learn
Jeremy DeHaan: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? Try: if (is(T == dchar)) Bye, bearophile

Re: Error with constraints on a templated fuction

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? is should be used as function. here. i.e.: `if (is(T == dchar))` signature.asc Description: PGP

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:59:38 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? is should be used as

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:52:20 UTC, bearophile wrote: Jeremy DeHaan: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? Try: if (is(T == dchar)) Bye, bearophile That one compiles, and I'm assuming it works. I didn't know you could use is this way. I've

Re: Error with constraints on a templated fuction

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 Aug 2014 16:11:27 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is its ability to be used as a function like this documented anywhere? I looked and could not find it. http://dlang.org/concepts.html template constraints is a special case. is not

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 16:20:24 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 25 Aug 2014 16:11:27 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is its ability to be used as a function like this documented anywhere? I looked and could not find

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws.

Re: Error with constraints on a templated fuction

2014-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws. immutable(T)[] toString(T)(const(T)*

Re: Error with constraints on a templated fuction

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:05:48 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors

Re: Error with constraints on a templated fuction

2014-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 25, 2014 at 05:10:18PM +, via Digitalmars-d-learn wrote: On Monday, 25 August 2014 at 17:05:48 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits

Re: Error with constraints on a templated fuction

2014-08-25 Thread Artur Skawina via Digitalmars-d-learn
On 08/25/14 18:52, Jonathan M Davis via Digitalmars-d-learn wrote: Another commonly used one is is(typeof(foo)). typeof(foo) gets the type of foo and will result in void if foo doesn't exist, and is(void) is false, whereas D is not quite that simple. ;) static assert(is(void)==true); (a)