Nick Hounsome wrote:
And if you also need them as a,b,c just add inline access methods
OR
if you have plenty of space add a ctor and references (ugh!)
struct s
{
double data[3];
double& a;
double& b;
double& c;
s() : a(&data[0]), ..... {}
};
If care about memory but you don't care about performances you can write
this:
struct s {
double a;
double b;
double c;
double& operator[](int n)
{
return n == 0 ? a : n == 1 ? b : c;
}
double operator[](int n) const
{
return n == 0 ? a : n == 1 ? b : c;
}
};
If you invoke [] with constants, the compiler may be able to optimize
the tests away so you shouldn't even incur in a performance loss.
Alberto