I am in need of mixing C code with C++ code in a computer simulation.
A C library has functions which take references to a regular array of doubles:
void position(double[3])
Another C library defines its own vector
type:
void do_something(*custom_vector)
And my front-end (in C++) uses boost::numeric::ublas::vector
.
In the first case, I have a lot of places with this kind of code:
double tmp[3];
position(tmp)
boostvec r(3);
r(0) = tmp[0]; r(1) = tmp[1]; r(2) = tmp[2];
// continue working with r
also
custom_vector *v;
do_something(v);
boostvec r(3);
r(0) = v[0]; r(1) = v[1]; r(2) = v[2];
Internally, all the types are ultimately vector containers, but their slight implementation differences are causing a lot of boilerplate explosion. I am also dealing with a lot different versions of double
(some define realtype
(which is a double), others define number
(which is a double), etc).
How do you deal with this situation?
Thank you.