Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 10:11:59 UTC, realhet wrote: On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer wrote: On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: mixin("int[",

Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer wrote: On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: A month ago I discovered that mixinDeclarations can be used for types

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:     mixin("@property auto ", k, "() const { return ", v, "; }"); Wow, string mixin can process comma separated list, I gotta remember this,

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:37:25 UTC, Stanislav Blinov wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: Try UDAs instead of a map: struct A { struct G { @("hauteur") int height; } Good idea, thx! I already using UDA's for range and measurement units.

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: mixin("@property auto ", k, "() const { return ", v, "; }"); Wow, string mixin can process comma separated list, I gotta remember this, thanks!

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: I did it that way: private enum fieldMap = [ // simple names for descriptive and structured fields "hauteur" : "general.height", "rayon" : "profile.radius", "plage" : "profile.plage", "offsetv"

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: static foreach(k, v; fieldMap){ mixin("@property auto $() const{ return #; }".replace("$", k).replace("#", v)); } //I know, i know -> AliasSeq :D You can use std.format.format to do it in one function call: mixin("@property auto

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: Oh and I can put that function generator mixin thing into a template as well, that way it is reusable and much nicer. There are a lot of

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: > struct A{ >struct B{ int c; } >B b; > >auto f(){ > alias d = b.c; The spec explicitly says it's not legal: "Aliases cannot be used for expressions" (Item 10):

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Ali Çehreli via Digitalmars-d-learn
On 6/2/20 1:56 AM, realhet wrote: > struct A{ >struct B{ int c; } >B b; > >auto f(){ > alias d = b.c; The spec explicitly says it's not legal: "Aliases cannot be used for expressions" (Item 10): https://dlang.org/spec/declaration.html#alias I use nested functions for such

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:07:08 UTC, Basile B. wrote: On Tuesday, 2 June 2020 at 08:56:13 UTC, realhet wrote: [...] There's a language rule, expressions cant be aliased, however D has a bug, some expressions that look like type can be aliased, then when you use them you have an error

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 08:56:13 UTC, realhet wrote: Hello, I have a 2 level nested struct structure with nice descriptive field names. And I thought it will be easy to alias those identifierLists with a few letter names and do some calculations on them. But I'm having an error. struct

Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
Hello, I have a 2 level nested struct structure with nice descriptive field names. And I thought it will be easy to alias those identifierLists with a few letter names and do some calculations on them. But I'm having an error. struct A{ struct B{ int c; } B b; auto f(){ alias d =