Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: equality_comparable_with across equivalent dimensions #205

Closed
JohelEGP opened this issue Jan 14, 2021 · 3 comments
Closed

fix: equality_comparable_with across equivalent dimensions #205

JohelEGP opened this issue Jan 14, 2021 · 3 comments

Comments

@JohelEGP
Copy link
Collaborator

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>;
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~
@JohelEGP
Copy link
Collaborator Author

The former works because fps::foot is a named_scaled_unit, whereas cgs::centimetre is an alias for si::centimetre.

@JohelEGP
Copy link
Collaborator Author

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>>);

@mpusz mpusz added this to the v0.9.0 (V2 framework) milestone Dec 5, 2022
@mpusz mpusz mentioned this issue Dec 17, 2022
18 tasks
@mpusz
Copy link
Owner

mpusz commented Jun 15, 2023

Addressed with V2.

@mpusz mpusz closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants