Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 21, 2015 19:54:53 Shriramana Sharma via Digitalmars-d-learn wrote: > Thanks all for your replies. One question: > > Jonathan M Davis wrote: > > Alternatively, you can use static if, though you're only dealing > > with one template in that case. e.g. > > But if we wanted to depr

Re: Template specialization using traits?

2015-12-21 Thread Shriramana Sharma via Digitalmars-d-learn
Thanks all for your replies. One question: Jonathan M Davis wrote: > Alternatively, you can use static if, though you're only dealing > with one template in that case. e.g. But if we wanted to deprecate one of the alternatives, then we necessary need to declare two templates with the same name a

Re: Template specialization using traits?

2015-12-21 Thread tcak via Digitalmars-d-learn
On Monday, 21 December 2015 at 11:12:10 UTC, Jonathan M Davis wrote: On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis wrote: For your example to work with template constraints, the most straightforward solution would be void func(T)(T t) if(!isIntegral!T) { writeln(1); }

Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis wrote: For your example to work with template constraints, the most straightforward solution would be void func(T)(T t) if(!isIntegral!T) { writeln(1); } void func(T)(T t) if(isIntegral!T) { writeln(2); } Alternati

Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 21, 2015 15:14:20 Shriramana Sharma via Digitalmars-d-learn 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)

Re: Template specialization using traits?

2015-12-21 Thread rumbu via Digitalmars-d-learn
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 ge

Template specialization using traits?

2015-12-21 Thread Shriramana Sharma via Digitalmars-d-learn
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 w