Merge 2 structs together (into a single struct)?
jfondren
julian.fondren at gmail.com
Fri Sep 17 05:19:23 UTC 2021
On Friday, 17 September 2021 at 05:01:36 UTC, james.p.leblanc
wrote:
> Again, thanks to you and many of the D community with helping
> to learn and
> appreciate the capabilities of D. It is nice to be here.
Yeah. The improved joinStruct is nice enough that I think it's
probably a good thing to do.
And there's this, some kind of Jai innovation:
```d
struct Object {
float[2] position, velocity, facing;
float size;
}
struct Player {
mixin parent!Object;
int hp;
}
mixin template parent(Struct) {
static foreach (i, alias f; Struct.tupleof) {
mixin("typeof(f) ", __traits(identifier, f), " =
Struct.init.tupleof[i];");
}
}
void main() {
import std.stdio : writeln;
writeln(Player([0, 0], [0, 0], [0, -1], 5.0, 100));
}
```
More information about the Digitalmars-d-learn
mailing list