A reference to separate pairs of values
C++ has a complex class which has overloaded the basic arithmetic operators.
That's nice but there are some issues with regards to assignment of complex values.
Suppose you have another class that implements a complex array internally as two separate arrays of real and imaginary parts.
Code:
class carr {
double *rval ;
double *ival ;
unsigned len ;
....
public:
}
I wrote part of an iterator for a class like this. But I want my iterators * operator to return a reference to a complex number. While I can easily create such an iterator I can not assign to the * operator. In fact there is no way to return a complex reference to an element of this 'array' that I can see.
For example wouldn't it be nice if I could,
Code:
carr c1(100) ;
c1[25] = std::complex<double>(1.0, -1.0) ;
There is no [] operator that I can construct that would support these semantics as far as I can tell. I think if I had a single flat double array of twice the size, it could be done with a cast, but otherwise am I out of luck? Do I require a separate set value function?