On Friday, 23 November 2012 at 16:11:25 UTC, Joshua Niehus wrote:
A bit messy, but im sure there is some room for cleanup
somewhere...
Errata... (what i get for copy/pasting)
import std.stdio, std.conv, std.traits, std.complex;
template isComplexNumeric(T)
{
static if(isNumeric!T) {
enum bool isComplexNumeric = true;
}
else static if (is(T == Complex!double))
{
enum bool isComplexNumeric = true;
}
else {
enum bool isComplexNumeric = false;
}
}
class Example(T) if (isComplexNumeric!T)
{
T k = to!T(1);
}
void main()
{
auto x = new Example!(Complex!double)();
writeln(x.k);
auto y = new Example!double();
writeln(y.k);
auto z = new Example!string();
writeln(z.k);
}
i did have to reference Philippe Sigaud's excellent book on
Templates several times:
https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf