Re: Struct fields and properties as alias members

2021-12-08 Thread Ben Jones via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 18:23:25 UTC, Adam D Ruppe wrote: On Wednesday, 8 December 2021 at 18:07:32 UTC, Ben Jones wrote: I went with the mixin approach, which seems to work fine except that I couldn't declare the mixin inside a function, so the definition is pretty far away from

Re: Struct fields and properties as alias members

2021-12-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 18:07:32 UTC, Ben Jones wrote: Since I reuse the field a few times I tried to alias the result: `alias theProp = __traits(child, s, field);` yeah won't work since the alias again drops the `this`, this is the same thing as the template param. You could make

Re: Struct fields and properties as alias members

2021-12-08 Thread Ben Jones via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:44:47 UTC, Adam D Ruppe wrote: On Wednesday, 8 December 2021 at 17:19:32 UTC, Ben Jones wrote: Gotcha, thanks. I tried using `S.field` before and that didn't work, `__traits(child)` was the key. Since I reuse the field a few times I tried to alias the

Re: Struct fields and properties as alias members

2021-12-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:19:32 UTC, Ben Jones wrote: It seems like maybe I'd have to pass s as a runtime parameter to get it to work? yes, you do. the alias param passes the abstract idea of the variable instead of the variable: void main(){ S s; func!(s.a)(); See, you

Re: Struct fields and properties as alias members

2021-12-08 Thread Ben Jones via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:29:19 UTC, H. S. Teoh wrote: On Wed, Dec 08, 2021 at 05:19:32PM +, Ben Jones via Digitalmars-d-learn wrote: I'm trying to use a property member of a struct as a template alias parameter and I don't really understand how to fix the error message I'm

Re: Struct fields and properties as alias members

2021-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 08, 2021 at 05:21:49PM +, Ben Jones via Digitalmars-d-learn wrote: [...] > I considered just having a `ref int` parameter, but I didn't think > that would work if I was actually calling a property function, rather > than just modifying a struct member. [...] Why not pass the

Re: Struct fields and properties as alias members

2021-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 08, 2021 at 05:19:32PM +, Ben Jones via Digitalmars-d-learn wrote: > I'm trying to use a property member of a struct as a template alias > parameter and I don't really understand how to fix the error message > I'm seeing (I also tried the simpler case of a plain struct member, >

Re: Struct fields and properties as alias members

2021-12-08 Thread Ben Jones via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 17:19:32 UTC, Ben Jones wrote: I considered just having a `ref int` parameter, but I didn't think that would work if I was actually calling a property function, rather than just modifying a struct member. I also tried to use a template mixin, but couldn't