Template specialization using traits?

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 21 01:44:20 PST 2015


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?

-- 
Shriramana Sharma, Penguin #395953


More information about the Digitalmars-d-learn mailing list