I wrote a small stand-alone library (it depends only on the standard C ++ library), which has its own built-in three-dimensional vector class:
namespace mylibrary {
struct Vector {
double x, y, z;
Vector(double x, double y, double z);
};
}
It should interact with other code that creates / uses 3D vectors.
Now suppose another library that has:
namespace otherlibrary {
struct Vector3 {
Vector3(double x, double y, double z);
};
doSomething(const Vector3& point);
}
This other library may be a plugin API for a 3D modeling tool or a 3D engine. It also has a concept for a 3D vector, but it certainly differs from my library vector, although the semantics are identical. Think of the Python duck set: a type doesn't matter if it behaves as expected.
Question:
, Vector
otherlibrary::doSomething()
?
, :
otherlibrary::doSomething( mylibrary::Vector(...) );
, , Vector
, , T "x, y, z" operator[]
, , . ?
EDIT:
, , 3D- . , , , , Eigen:: Vector3d , , Eigen.
:
:
struct Vector {
using value_type = double;
template<class T,
class = typename enable_if<
is_constructible<T, value_type,value_type,value_type>::value
>::type>
operator T() const
{
return T{x, y, z};
}
};
enable_if
; Eigen - , .