Converting a number to complex

Frederik Vagner vnataneg.jykhan at gmail.com
Fri Nov 23 04:39:58 PST 2012


On Thursday, 22 November 2012 at 16:09:46 UTC, Joshua Niehus 
wrote:
> On Thursday, 22 November 2012 at 15:47:11 UTC, Frederik Vagner 
> wrote:
>> I am trying to make a templated class to accept any numeric 
>> type:
>>
>> class example(Type) if (isNumeric(Type))
>> {
>>    Type k = to!Type(1);
>>    ....
>> }
>>
>> however I always get a compiler erro stating I cannot make 
>> that conversion. How do I fix it?
>
> // phobos
> import std.stdio, std.conv, std.traits;
> class Example(T) if (isNumeric!T)
> {
>     T k = to!T(1);
> }
>
> void main()
> {
>     auto x = new Example!double();
>     writeln(x.k);
> }

Now do it for complex number please ^^


More information about the Digitalmars-d-learn mailing list