mp-units
mp-units copied to clipboard
fix: equality_comparable_with across equivalent dimensions
The last assertion fails:
static_assert(fps::length<fps::foot>(1 * cgs_cm) == 1 * cgs_cm);
static_assert(std::equality_comparable_with<decltype(fps::length<fps::foot>(1 * cgs_cm)), decltype(1 * cgs_cm)>);
static_assert(1 * cgs_cm == 1 * cm);
static_assert(std::equality_comparable_with<decltype(1 * cgs_cm), decltype(1 * cm)>);
Their common type is not associative because the dimension of the lhs is preferred. Considering how the unit is always of the si rather than cgs, I believe it reasonable to make the dimension of the si, too.
quantity_kind_test.cpp:191:20: error: static assertion failed
191 | static_assert(std::equality_comparable_with<decltype(1 * cgs_cm), decltype(1 * cm)>);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
quantity_kind_test.cpp:191:20: note: constraints not satisfied
In file included from /home/johel/Documents/C++/Forks/mpusz/units/src/src/include/units/bits/external/hacks.h:25,
from /home/johel/Documents/C++/Forks/mpusz/units/src/src/include/units/bits/external/downcasting.h:25,
from /home/johel/Documents/C++/Forks/mpusz/units/src/src/include/units/bits/basic_concepts.h:25,
from /home/johel/Documents/C++/Forks/mpusz/units/src/src/include/units/bits/equivalent.h:25,
from test_tools.h:25,
from quantity_kind_test.cpp:23:
/usr/include/c++/10.2.0/concepts:57:15: required for the satisfaction of ‘__same_as<_Tp, _Up>’ [with _Tp = units::quantity<units::physical::si::cgs::dim_length, units::physical::si::centimetre, int>; _Up = units::quantity<units::physical::si::dim_length, units::physical::si::centimetre, int>]
/usr/include/c++/10.2.0/concepts:62:13: required for the satisfaction of ‘same_as<typename std::common_reference<_Tp1, _Tp2>::type, typename std::common_reference<_Up, _Tp>::type>’ [with _Tp2 = const units::quantity<units::physical::si::dim_length, units::physical::si::centimetre, int>&; _Tp1 = const units::quantity<units::physical::si::cgs::dim_length, units::physical::si::centimetre, int>&; _Tp = const units::quantity<units::physical::si::cgs::dim_length, units::physical::si::centimetre, int>&; _Up = const units::quantity<units::physical::si::dim_length, units::physical::si::centimetre, int>&]
/usr/include/c++/10.2.0/concepts:79:13: required for the satisfaction of ‘common_reference_with<const typename std::remove_reference<_Tp>::type&, const typename std::remove_reference<_Arg>::type&>’ [with _Tp = units::quantity<units::physical::si::cgs::dim_length, units::physical::si::centimetre, int>; _Arg = units::quantity<units::physical::si::dim_length, units::physical::si::centimetre, int>]
/usr/include/c++/10.2.0/concepts:57:32: note: the expression ‘is_same_v<_Tp, _Up> [with _Tp = units::quantity<units::physical::si::cgs::dim_length, units::physical::si::centimetre, int>; _Up = units::quantity<units::physical::si::dim_length, units::physical::si::centimetre, int>]’ evaluated to ‘false’
57 | concept __same_as = std::is_same_v<_Tp, _Up>;
| ~~~~~^~~~~~~~~~~~~~~~~~~
The former works because fps::foot is a named_scaled_unit, whereas cgs::centimetre is an alias for si::centimetre.
This second assertion fails.
static_assert(std::equality_comparable_with<si::fps::area<si::fps::square_foot, long int>, si::area<si::square_metre, long double>>);
static_assert(std::equality_comparable_with<si::fps::area<si::fps::square_foot>, si::area<si::square_metre>>);
Addressed with V2.