Converting a number to complex
Joshua Niehus
jm.niehus at gmail.com
Thu Nov 22 08:09:45 PST 2012
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);
}
More information about the Digitalmars-d-learn
mailing list