On Friday, 6 September 2013 at 10:33:07 UTC, ilya-stromberg wrote:
Do you have any plans to support implicit conversion between
types?
I have some code like this:
struct Foo
{
this(int i)
{
//do something useful
}
}
void bar(Foo f)
{
//do something else
}
void main()
{
Foo f = 5;//works
bar(f);//works
bar(Foo(5));//works
bar(5);//Error: function app.bar (Foo f) is not callable using
argument types (int)
}
Actually D has this feature for classes:
class A
{
this(int) {}
}
void foo(A a ...) {}
void main()
{
foo(5);
}
This compiles and runs as expected. By the way, the code was
fixed recently - before 2.063 this was allocating class on stack
(so in D there were some kind of scoped stack classes), now this
allocates on heap as usual. I don't see the rationale behind not
working with structs.