Template specialization using traits?
rumbu via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Dec 21 01:52:04 PST 2015
On Monday, 21 December 2015 at 09:44:20 UTC, Shriramana Sharma
wrote:
> Hello. I want to define a template specialization using traits:
>
> import std.stdio, std.traits;
> void func(T)(T t) { writeln(1); }
> void func(T)(T t) if(isIntegral!T) { writeln(2); }
> void main()
> {
> func(1);
> }
>
> But I'm getting an error saying that the called function
> matches both. If it were a single type, I know I have to put
> the specialization as in:
>
> void func(T: int)(T t) { writeln(2); }
>
> and that works, but how to make it more generic than that?
void func(T)(T t) if(!isIntegral!T) { writeln(1); }
void func(T)(T t) if(isIntegral!T) { writeln(2); }
:)
More information about the Digitalmars-d-learn
mailing list