Re: function template specialization question D vs. C++

2018-01-14 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 02:24:52 UTC, Adam D. Ruppe wrote: On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis wrote: If you're using template constraints rather than template specializations, then you can't have any unconstrained templates. Not true: see the tip of the week

Re: function template specialization question D vs. C++

2018-01-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 13, 2018 19:32:06 Jonathan M Davis via Digitalmars-d- learn wrote: > On Sunday, January 14, 2018 02:24:52 Adam D. Ruppe via Digitalmars-d-learn > wrote: > > On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis > > > > wrote: > > > If you're using template constraints

Re: function template specialization question D vs. C++

2018-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 January 2018 at 00:09:42 UTC, kdevel wrote: The compiler does not allow me to specialize the primary function template for double: Yes, it does., and it works for float and double. Just `real` matches both equally, so that's the error for that type. Let me quote the spec:

Re: function template specialization question D vs. C++

2018-01-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, January 14, 2018 02:24:52 Adam D. Ruppe via Digitalmars-d-learn wrote: > On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis > > wrote: > > If you're using template constraints rather than template > > specializations, then you can't have any unconstrained > > templates. > >

Re: function template specialization question D vs. C++

2018-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis wrote: If you're using template constraints rather than template specializations, then you can't have any unconstrained templates. Not true: see the tip of the week here http://arsdnet.net/this-week-in-d/2016-sep-04.html

Re: function template specialization question D vs. C++

2018-01-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, January 14, 2018 01:02:46 kdevel via Digitalmars-d-learn wrote: > On Sunday, 14 January 2018 at 00:30:37 UTC, Nicholas Wilson wrote: > > The usual way to do what you are trying to do is with template > > constraints. > > > > void foo(T)() if (is(T== float)) { ...} > > Thanks. That works

Re: function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 00:30:37 UTC, Nicholas Wilson wrote: The usual way to do what you are trying to do is with template constraints. void foo(T)() if (is(T== float)) { ...} Thanks. That works but looks a bit ugly. Am I right that I have to leave out the primary (unconstrained)

Re: function template specialization question D vs. C++

2018-01-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 14 January 2018 at 00:09:42 UTC, kdevel wrote: fusp.d ``` import std.stdio; import std.typecons; void foo (T) () { writeln ("(1) foo T = ", T.stringof); } void foo (T : float) () { writeln ("(2) foo T = ", T.stringof); } // void foo (T : double) () // { //writeln ("(2)

function template specialization question D vs. C++

2018-01-13 Thread kdevel via Digitalmars-d-learn
fusp.d ``` import std.stdio; import std.typecons; void foo (T) () { writeln ("(1) foo T = ", T.stringof); } void foo (T : float) () { writeln ("(2) foo T = ", T.stringof); } // void foo (T : double) () // { //writeln ("(2) foo T = ", T.stringof); // } void main () { foo!float;