`alias x = v.x;` not working in struct bodies?
evilrat
evilrat666 at gmail.com
Sat Jan 20 11:19:26 UTC 2024
On Saturday, 20 January 2024 at 10:00:15 UTC, Danilo wrote:
> All of this advanced stuff in D seems to be implemented for
> very specific and very limited use cases only.
> It could be much more better if it would be implemented for
> general and broader use cases.
In your vec3 example, while it is tempting to automate this using
cool smart features, you will end up regretting using it.
And in this example you can use union to join vec2 and add extra
synonyms members.
I see there is a lot of libraries that using similar smart
metaprogramming for basic types in D, but when I tried to do
"smart" things using alias this in the end I often got bitten by
it and regretting using templates and stuff.
Alias this has annoying property to mess up with your RAII
wrappers.
The fancy metaprogramming engineering results in poor IDE
experience and slower compilation(neglectible in this case) times
along with even more horrible debugging.
```d
struct Vec3 {
union {
struct {
float x = 0;
float y = 0;
float z = 0;
}
struct {
Vec2 _xy;
float _z;
}
float[3] values;
}
// ...
}
```
More information about the Digitalmars-d
mailing list