Template method and type resolution of return type
Andrej Mitrovic via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 19 15:31:00 PDT 2014
On 4/19/14, matovitch via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
> This won't compile :
>
> import std.stdio;
>
> void main()
> {
> Test t;
> t.data = [152, 32, 64, 28, 95];
> float b = t.get;
> writefln("%s", b);
> }
Because it's probably overkill. At some point it becomes too much
magic. The following currently works but it might be considered an
ambiguity with return type inference:
-----
struct S
{
int get() { return 0; }
T get(T)() { return T.init; }
}
void main()
{
S s;
float x = s.get(); // which overload? (currently int get())
}
-----
More information about the Digitalmars-d-learn
mailing list