On 06/03/2012 08:43 PM, Namespace wrote:
I think this should work:
[code]
import std.stdio;
class Foo(T) {
public:
T Num;
@property
Foo!(U) ConvertTo(U)() inout {
return cast(Foo!(U)) this;
}
alias ConvertTo this;
}
void Call(const Foo!(float) FFoo) {
}
void main() {
Foo!(ubyte) UbFoo = new Foo!(ubyte)();
Call(UbFoo);
readln();
}
[/code]
Why it doesn't?
Making this generally work as you expect would be too hard.
The compiler would have to reverse-engineer the 'ConvertTo' template
which is an undecidable problem in general. Some clever heuristics
might suffice for most practical instances though, but those are
very open-ended and therefore it is hard to incorporate them into the
language definition. If you think it should be done you could file a
suggestion (enhancement request) into the bug tracker.