Error with constraints on a templated fuction
Jeremy DeHaan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 25 08:48:10 PDT 2014
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 str[0..strlen(str)].idup; //I have strlen defined for
each *string
}
I was going to add some || sections for the other string types,
but this one won't even compile.
src/dsfml/system/string.d(34): Error: found ')' when expecting
'.' following dchar
src/dsfml/system/string.d(35): Error: found '{' when expecting
identifier following 'dchar.'
src/dsfml/system/string.d(36): Error: found 'return' when
expecting ')'
src/dsfml/system/string.d(36): Error: semicolon expected
following function declaration
src/dsfml/system/string.d(36): Error: no identifier for
declarator str[0 .. strlen(str)]
src/dsfml/system/string.d(36): Error: no identifier for
declarator .idup
src/dsfml/system/string.d(37): Error: unrecognized declaration
It compiles if I remove the 'if(typeof(T) is dchar)' section. Any
thoughts?
More information about the Digitalmars-d-learn
mailing list