I want to create my own Tuple type
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Jan 12 12:14:59 UTC 2021
Ok, so I now have this, but I think maybe the switch could be
turned into a static array by an reinterpret cast of
"&expand[0]"? I would assume the layout would typically be
"expand_field_0, expand_field_1 etc...
template Tuple(Types...){
template same(){
static foreach (i, dummy; Types) {
static if (i + 1 < Types.length && !is(typeof(same)
== bool)
&& !is(Types[i] == Types[i + 1])) {
enum bool same = false;
}
}
static if (!is(typeof(same) == bool)) {
enum bool same = true;
}
}
struct Tuple {
Types expand;
alias expand this;
static if (same!()) {
auto opIndex(size_t i) {
switch (i) {
static foreach (j; 0 .. Types.length) {
case j: return this.expand[j];
}
default: assert(0);
}
}
}
}
}
More information about the Digitalmars-d-learn
mailing list