DH
Size: a a a
DH
OB
EP
OB
import std;
struct Bools(string[] names)
{
enum N = names.length;
union
{
bool[N] arr;
struct
{
static foreach (name; names)
mixin("bool " ~ name ~ ";");
}
}
this(bool[N] v...) pure { arr[] = v[]; }
}
alias B1 = Bools!(["one", "two"]);
void main()
{
auto b1 = B1(true, false);
writeln(b1.one);
writeln(b1.two);
b1.one = false;
b1.two = true;
writeln(b1.one);
writeln(b1.two);
}
OB
import std;
struct Bools(string[] names)
{
enum N = names.length;
union
{
bool[N] arr;
struct
{
static foreach (name; names)
mixin("bool " ~ name ~ ";");
}
}
this(bool[N] v...) pure { arr[] = v[]; }
}
alias B1 = Bools!(["one", "two"]);
void main()
{
auto b1 = B1(true, false);
writeln(b1.one);
writeln(b1.two);
b1.one = false;
b1.two = true;
writeln(b1.one);
writeln(b1.two);
}
unionstruct Bools(string[] names)
{
enum N = names.length;
bool[N] arr;
static foreach (i, name; names)
mixin("ref inout(bool) " ~ name ~ "() @property inout { return arr[" ~ i.to!string ~ "]; }");
this(bool[N] v...) pure { arr[] = v[]; }
}
EP