digitalmars.D.learn - assign to property 2 values
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (28/28) Jul 09 2021 I want this feature in D:
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (6/34) Jul 09 2021 I undestand what
- Dennis (11/12) Jul 09 2021 If you `import std.typecons` you can do:
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (4/18) Jul 09 2021 Yes.
I want this feature in D: ``` element.border = 1, solid; struct Element { property void border( int width, BorderStyle style ) { this.borderWidth = width; this.borderStyle = style; } } ``` Description: ``` element.border = 1, solid; ``` will rewriten to the ``` element.border(1, solid); ``` This is same as property. ``` element.color = 0xCCC; property void color( uint a ) { this._color = a; } ``` but with 2 arguments, and more. It possible in current version 2.097 ?
Jul 09 2021
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote:I want this feature in D: ``` element.border = 1, solid; struct Element { property void border( int width, BorderStyle style ) { this.borderWidth = width; this.borderStyle = style; } } ``` Description: ``` element.border = 1, solid; ``` will rewriten to the ``` element.border(1, solid); ``` This is same as property. ``` element.color = 0xCCC; property void color( uint a ) { this._color = a; } ``` but with 2 arguments, and more. It possible in current version 2.097 ?I undestand what element.border = 1, solid; is element.border = 1; solid();
Jul 09 2021
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote:It possible in current version 2.097 ?If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling the function regularly, or combing all settings in a single struct: ```D element.border = Border(/*width:*/ 1, /*solid*/ true); ``` Named arguments are not implemented yet, hence the comments.
Jul 09 2021
On Friday, 9 July 2021 at 11:04:23 UTC, Dennis wrote:On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote:Thank.It possible in current version 2.097 ?If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling the function regularly, or combing all settings in a single struct: ```D element.border = Border(/*width:*/ 1, /*solid*/ true); ``` Named arguments are not implemented yet, hence the comments.But it's not pretty.Yes.Named arguments are not implemented yet, hence the comments.+1
Jul 09 2021