function template specialization question D vs. C++
kdevel
kdevel at vogtner.de
Sun Jan 14 11:27:36 UTC 2018
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 here
> http://arsdnet.net/this-week-in-d/2016-sep-04.html
Thanks for that hint (self specialization).
cppcompat.d
```
import std.stdio;
void foo (T) ()
{
writeln ("(1) ", __PRETTY_FUNCTION__);
}
void foo (T: T) () if (is (T == float))
{
writeln ("(2) ", __PRETTY_FUNCTION__);
}
void foo (T: T) () if (is (T == double))
{
writeln ("(3) ", __PRETTY_FUNCTION__);
}
void main ()
{
foo!int;
foo!float;
foo!double;
foo!real;
foo!string;
}
```
$ ./cppcomat
(1) void cppcompat.foo!int.foo()
(2) void cppcompat.foo!float.foo()
(3) void cppcompat.foo!double.foo()
(1) void cppcompat.foo!real.foo()
(1) void cppcompat.foo!string.foo()
More information about the Digitalmars-d-learn
mailing list