Puzzled
monkyyy
crazymonkyyy at gmail.com
Wed Dec 13 18:40:53 UTC 2023
On Tuesday, 12 December 2023 at 19:02:11 UTC, Don Allen wrote:
>> __traits, __traits, __traits, __traits,
you should use a mixin instead of traits that use strings to
store references.
The issue with either is that strings in different contexts may
not keep referencing the same thing. The mixin will just be
smaller.
```d
void bletch(string field)(ref Foo s,int x){
mixin("s."~field~"=x;");
}
```
if you want to be *idiomatic* you should figure out how to make
an alias survive the compiler warnings for your use case and
given I started an argument I suggest this is better and least
prone to failure
```d
void bletch(alias f, string s)(int x){
mixin("f."~s)= x;
}
bletch!(s,"bar")(2);
```
More information about the Digitalmars-d
mailing list