I want to create my own Tuple type
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sun Jan 10 16:52:30 UTC 2021
I want to create my own Tuple type, and I don't like the messy
implementation of the one in D's standard lib, or the one in
Clang++'s standard lib. The concept is very simple so it is
disheartening if it cannot be done in a simple way that does not
impact compile times... :-/
The requirements are:
1. It should not lead to slower compile times than fixed arity
templates (if so, then I would just list all sizes from 0..64
instead).
2. If all types are similar then it should be implemented as a
static array with indexing. If not, then all fields should have
the names __0, __1 etc.
Something along the lines of, but not with fixed arity:
struct Tuple(){}
struct Tuple(T0){
T0[1] __v;
const ref opIndex(size_t i){ return __v[i]; }
}
struct Tuple(T0,T1){
static if (is(T0==T1)) {
T0[2] __v;
this(T0 a, T1 b){__v[0]=a; __v[1]=b; }
const ref opIndex(size_t i){ return __v[i]; }
} else {
T0 __0;
T1 __1;
}
}
auto _tuple(Ts...)(Ts args){
return __Tuple!Ts(args);
}
More information about the Digitalmars-d-learn
mailing list