I just thought of a good way of checking the way the Eigen developers would want you to solve this problem. Eigen comes with a cross
function on MatrixBase
, but this function, like yours, is only sensible for 3D vectors - so I dug up the relevant part from the Eigen3 source: (cf Eigen/src/Geometry/OrthoMethods.h
)
...
inline typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
...
and indeed, Eigen itself uses asserts (albeit its own flavor) to check for dimensions in generalized functions.