Return type deduction
Rory McGuire via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 7 00:02:31 PDT 2016
On Mon, Sep 5, 2016 at 11:59 AM, Andrea Fontana via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> 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
>
user.name = json.get!(info.name);
or
user.name = json!(info.name);
possible right now. No language changes. Shorter. No strings. compile time
type verification.
limitation:
can't do runtime loading of unknown json structure (but then neither does
your proposal).
R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160907/fc4d5374/attachment.html>
More information about the Digitalmars-d
mailing list