Support implicit conversion between types
Kozzi
kozzi11 at gmail.com
Wed Sep 4 13:14:04 PDT 2013
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.
More information about the Digitalmars-d-learn
mailing list