double vector2d::* const vector2d::_v[] = { &vector2d::x,
&vector2d::y };
and suppose we have an object "vector2d v;" . The purpose of using
pointer to member here is to make v[0] and v.x have exactly the same
run-time efficiency, provided that the compiler is capable of
necessary optimization. (I didn't invent this technique, but I forgot
where I learned it).
Suppose now for some reason, I want to build a 5D vector class out of
this 2D vector class, say like this.
class vector5d
{
vector2d v1, v2;
double z;
};
and we have an object "vector5d w;"
What I want is, with as little run-time overhead as possible (maybe
using a similar method that's used by vector2d), that w[0] gives me
w.v1.x , w[1] gives w.v1.y , w[2] gives w.v2.x , w[3] gives w.v2.y ,
and w[4] gives me w.z .
Is it possible? If yes, how?
I mean, is it possible to achieve zero run-time overhead (assuming
proper optimization) in accessing members (and their members) via an
index? If we don't have a vector5d::z (in which case it's actually a
4D vector), we might want to use an array of pointers to member of a
member (I don't know how even if they do exist). Having vector5d::z
makes this even more complicated in that a pointer to vector5d::z and
a (may or may not existing) pointer to vector5d::v1.x certainly would
have different types, so they cannot be put into an array.
Thanks!