I work in robotics, which means that I use a large number of open source projects related to 3D geometry. Since classes and math tend to be fairly simple, everyone seems to implement their own version of Vector3D, Quaternion, etc., each with slight variations, for example. vec.x, vec.X, vec.x (). Therefore, within the framework of one project, conversion between Eigen, ROS, Assimp, Bullet and other versions of the same base classes may be required. Is there a simple or elegant way to do this in C ++ that does not require n ^ 2 mapping from each library to every other library?
Similarly: This question is SO , but I cannot edit any of the source libraries.
Example:
namespace a
{
class Vector
{
public:
double x, y, z;
};
}
namespace b
{
class Vector
{
public:
double X, Y, Z;
};
}
namespace c
{
class Vector
{
public:
double& x() { return mx; }
double& y() { return my; }
double& z() { return mz; }
private:
double mx, my, mz;
};
}
int main()
{
a::Vector va;
b::Vector vb;
c::Vector vc = va + vb;
return 0;
}
EDIT : If there are ~ 10 different geometry libraries, a particular project can use only 2-4 of them, so I would like to avoid introducing a dependency on all unused libraries. I was hoping for something like static_cast<b::Vec>(a::Vec)
or maybe
c::Vec vc = my_cvt<c::Vec>(vb + my_cvt<b::Vec>(va));
but my understanding of patterns and type_traits is pretty weak.
source
share