Skip to content

Unit types not being enforced in Common::Vector2d

In vector2d.h:

template <typename T, class = typename std::enable_if<units::traits::is_unit<T>::value>>
class OPENPASSCOMMONEXPORT Vector2d final { ... };

It appears that Vector2d is meant to only be used with unit types, but with the above declaration, any type is allowed. This is because std::enable_if is always a valid type. Its member typedef type on the other hand may or may not be declared.

The intended behavior can be achieved by replacing the second template parameter with class = typename std::enable_if<units::traits::is_unit<T>::value>::type or class = std::enable_if_t<units::traits::is_unit<T>::value> or my personal favorite std::enable_if_t<units::traits::is_unit<T>::value, bool> = true.

However, doing so would break the current Dynamics_TireModel, which is the only component using a non-unit template type Vector2d (Vector2d<double>), and would have to be replaced with unit-based Vector2ds.

Edited by Noah Schick