Merge 2 structs together (into a single struct)?

james.p.leblanc james.p.leblanc at gmail.com
Thu Sep 16 20:12:03 UTC 2021


Dear All,

I really thought that this would be a simple enough
small project in meta programming/reflection.  Consisely,
merge two structures, which are coming from two different
elements of the code base.  (One contains standard input
options for getopt, and the other is for user customization
for getopt.)

And while there are many hints, and partial solutions among
forum posts, and books, my many attempts have not been
successful.

Is there some obvious, and simple solution to this
conundrum of mine?

```d
struct A
{
    int alpha;
    float x = 1.23;
}

struct B
{
    int beta;
    float y = 4.4;
    string s = "this is fine.";
}

```
  .... some static foreach magic, and mixins later ... we have the 
merger

```d
  struct AB
{
    int alpha;
    float x = 1.23;
    int beta;
    float y = 4.4;
    string s = "this is fine.";
}
```
... the point of this is really to use the struct AB
for getopt reading of command line options.

All pointers, tips and info are greatly appreciated.
Best Regards,
James




More information about the Digitalmars-d-learn mailing list