xxxxxxxxxx
struct Vec {
float x, y, z;
}
void setPosition(float x, float y, float z) {
import std.stdio: writeln;
writeln(x, ", ", y, ", ", z);
}
void main() {
Vec posS = Vec(10, 20, 30);
setPosition(posS.tupleof); // pass
float[3] posA = [10, 20, 30];
setPosition(tupleOf!posA); // Error: no property `tupleof` for type `float[3]`
}
import std.traits: isStaticArray;
template Iota(size_t n)
{
import std.meta: AliasSeq;
static if (n == 0)
alias Iota = AliasSeq!();
else
alias Iota = AliasSeq!(Iota!(n - 1), n - 1);
}
template tupleOf(alias array)
if (isStaticArray!(typeof(array)))
{
import std.meta: Map = staticMap;
ref element(size_t i)()
{
return array[i];
}
alias tupleOf = Map!(element, Iota!(array.length));
}