So you can use templates, something like this:

bool isConvertableToFoo(T)
{
    T i = void;
    return is(typeof(Foo(i)) == Foo);
}

void bar(T)(T i) if (is(T : Foo))
{
    //some code
}

void bar(T)(T i) if (!is(T : Foo) && isConvertableToFoo!T)
{
    bar(Foo(i));
}


I do not test it so it is maybe not completly correct :).
On Wednesday, 4 September 2013 at 19:54:44 UTC, ilya-stromberg wrote:
On Wednesday, 4 September 2013 at 19:44:17 UTC, Namespace wrote:

What's about:

void bar(int i) {
   bar(Foo(i));
}

?

No, I wrote very simple example. I have 10 "from" types and a lot of different "bar" functions. Your way will be more painful then explicit conversion.

Reply via email to