Return type deduction

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 5 02:59:16 PDT 2016


I asked this some time (years?) ago. Time for a second try :)

Consider this:

---

T simple(T)() { return T.init; }


void main()
{
	int test = simple!int(); // it compiles
	int test2 = simple();    // it doesn't
}

---

Is there any chance to implement this kind of deduction?
Please notice that it doesn't break any existing code, I guess.

For example using my json wrapper [1] this sounds a bit pedantic:

----
user.name = json.get!string("info/name");
user.age  = json.get!int("info/age");
----

If return type deduction could be implemented it would be:

----
user.name = json.get("info/name");
user.age  = json.get("info/age");
----

[1] https://code.dlang.org/packages/jsonwrap

Andrea


More information about the Digitalmars-d mailing list