Error with constraints on a templated fuction
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 25 10:27:00 PDT 2014
On Mon, Aug 25, 2014 at 05:10:18PM +0000, 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 +0000, 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)* str)
> >> if(typeof(T) is dchar)//this is where the error is
> >
> >The correct syntax is:
> >
> > if (is(typeof(T) == dchar))
>
> Almost... T is already a type; typeof(T) doesn't compile.
Ah, right, it should be simply: if (is(T == dchar))
Should've read more carefully before replying. :-P
T
--
It only takes one twig to burn down a forest.
More information about the Digitalmars-d-learn
mailing list