Deduce type of struct in function arguments

Seb seb at wilzba.ch
Mon Aug 20 17:45:25 UTC 2018


On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote:
> On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote:
>> Create an overload of foo that takes two arguments and 
>> combines them into a `Data` struct internally:
>>
>> void foo(int a, string text)
>> {
>>     Data data = {a, text};
>>     foo(data);
>> }
>
> Hmm, not very good solution. In C++ you can not to write type 
> and compiler will deduce it automatically. In D, as I 
> understand, this feature isn't supported.

... yet. Though you can vote for this DIP and show your support 
there:

https://github.com/dlang/DIPs/pull/71

It even comes with an implementation in DMD already:

https://github.com/dlang/dmd/pull/8460


More information about the Digitalmars-d-learn mailing list