import std;
void main()
{
struct Foo {
string s = "string";
alias s this;
string toString() { return s.format!"Foo(%s)"; }
}
Foo().to!string.writeln; // string
Foo().format!"%s".writeln; // Foo(string)
struct Bar {
int s = 3;
alias s this;
T opCast(T)() { return 43; }
}
Bar().to!int.writeln; // 3
(cast(int) Bar()).writeln; // 43
struct Baz {
T opCast(T)() { return 43; }
}
Bar().to!int.writeln; // 43
(cast(int) Bar()).writeln; // 43
}
Is this the intended behavior of std.conv : to
?
Shouldn't it only fallback to the alias this
if none of those work?