On Friday, 23 November 2012 at 12:39:59 UTC, Frederik Vagner wrote:
Now do it for complex number please ^^

touche!

import std.stdio, std.conv, std.traits, std.complex;

template isComplexNumeric(T)
{
    static if(is(NumericTypeOf!T)) {
        enum bool isComplexNumeric = is(NumericTypeOf!T);
    }
    else static if (is(T == Complex!double))
    {
        enum bool isComplexNumeric = is(Complex!double);
    }
// fillin real and float here... (e.g. is(Complex!real); etc...
}

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(); // fail
    writeln(z.k);
}

A bit messy, but im sure there is some room for cleanup somewhere...


Reply via email to