www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - struct =?UTF-8?B?c3Rhwq10aWMgaW5pwq10aWFswq0=?= =?UTF-8?B?aXplcg==?=

reply learnfirst1 <learnfirst1 gmail.com> writes:
my question is how to easy use struct sta­tic ini­tial­izer 
method with UDA.

Fake code:

struct DbColumn {
          string name;
	bool	unique ;
	bool	signed ;
	bool	nullable ;
}

struct Order {
	uint id;
	
	 DbColumn({ .nullable= true}) // not working
	string order_id;

	 DbColumn({ :nullable= true}) // not working
	string order_time;

	 DbColumn(nullable= true) // not working
	string order_time;
}
Dec 06 2018
parent reply Basile B. <b2.temp gmx.com> writes:
On Thursday, 6 December 2018 at 11:04:23 UTC, learnfirst1 wrote:
 my question is how to easy use struct sta­tic ini­tial­izer 
 method with UDA.

 Fake code:

 struct DbColumn {
          string name;
 	bool	unique ;
 	bool	signed ;
 	bool	nullable ;
 }

 struct Order {
 	uint id;
 	
 	 DbColumn({ .nullable= true}) // not working
 	string order_id;

 	 DbColumn({ :nullable= true}) // not working
 	string order_time;

 	 DbColumn(nullable= true) // not working
 	string order_time;
 }
Looks like what you want is named parameters.
Dec 06 2018
parent reply Radu <void null.pt> writes:
On Thursday, 6 December 2018 at 11:09:47 UTC, Basile B. wrote:
 On Thursday, 6 December 2018 at 11:04:23 UTC, learnfirst1 wrote:
 my question is how to easy use struct sta­tic ini­tial­izer 
 method with UDA.

 Fake code:

 struct DbColumn {
          string name;
 	bool	unique ;
 	bool	signed ;
 	bool	nullable ;
 }

 struct Order {
 	uint id;
 	
 	 DbColumn({ .nullable= true}) // not working
 	string order_id;

 	 DbColumn({ :nullable= true}) // not working
 	string order_time;

 	 DbColumn(nullable= true) // not working
 	string order_time;
 }
Looks like what you want is named parameters.
Actually he's looking for in-place struct initialization https://github.com/dlang/DIPs/blob/b1283b455b635d7dcbc2c871d2aa47cc67190059/DIPs/DIP1xxx-sw.md Which would be a real nice feature to have.
Dec 06 2018
parent learnfirst1 <learnfirst1 gmail.com> writes:
On Thursday, 6 December 2018 at 12:50:34 UTC, Radu wrote:
 On Thursday, 6 December 2018 at 11:09:47 UTC, Basile B. wrote:

 Which would be a real nice feature to have.
this is what I need, I guess I has to wait.
Dec 06 2018