www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Static Initialization of Structs syntax

reply Antonio <antonio abrevia.net> writes:
I'm so sorry, I know that the above example doesn't work:

```d

main(){
   Struct PersonDTO {
     string name;
     string surname;
   }

   void create(PersonDTO personData){
    // ...
   }
   create( {name: "Peter", surname: "Ustinov"} );

}

```

-Is it there any alternative to initialize "inline" de struct 
(using the name:value syntax for the properties) without 
declaring an intermediate variable?

Thanks
Antonio
Jun 22 2022
parent reply Antonio <antonio abrevia.net> writes:
On Wednesday, 22 June 2022 at 09:41:55 UTC, Antonio wrote:
 I'm so sorry, I know that the above example doesn't work:

 ```d

 main(){
   Struct PersonDTO {
     string name;
     string surname;
   }

   void create(PersonDTO personData){
    // ...
   }
   create( {name: "Peter", surname: "Ustinov"} );

 }

 ```

 -Is it there any alternative to initialize "inline" de struct 
 (using the name:value syntax for the properties) without 
 declaring an intermediate variable?

 Thanks
 Antonio
I see now: DIP 1033 will solve this (i.e., using named arguments in struct constructor... similar to how dart/flutter works)
Jun 22 2022
parent Mike Parker <aldacron gmail.com> writes:
On Wednesday, 22 June 2022 at 11:19:59 UTC, Antonio wrote:

 I see now:  DIP 1033 will solve this (i.e., using named 
 arguments in struct constructor...  similar to how dart/flutter 
 works)
That would be DIP 1030: https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md Max Haughton was working on an implementation of it, but ran into trouble with template parameters, IIRC.
Jun 22 2022