Deduce type of struct in function arguments

Paul Backus snarwin at gmail.com
Mon Aug 20 11:38:39 UTC 2018


On Monday, 20 August 2018 at 09:23:27 UTC, Andrey wrote:
> Hello,
>
> I have a function and a struct:
>> void foo(ref Data data) { ... }
>
>> struct Data
>>{
>>    int a;
>>    string text;
>>}
>
> How to pass struct into function without naming its type?
>
> This doesn't work:
>
>> foo({1234, "Hello!"});

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);
}


More information about the Digitalmars-d-learn mailing list