refactor: the rest of the systems refactored for V2

This commit is contained in:
Mateusz Pusz
2022-12-29 18:59:10 +01:00
parent a9c190a7bf
commit 97da55edfa
62 changed files with 1179 additions and 3442 deletions
+2
View File
@@ -52,6 +52,7 @@
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
#define UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT UNITS_DIAGNOSTIC_IGNORE("-Wzero-as-nullpointer-constant")
#define UNITS_DIAGNOSTIC_IGNORE_DEPRECATED UNITS_DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
#else
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push))
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop))
@@ -65,6 +66,7 @@
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459)
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702)
#define UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
#define UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
#endif
#if _LIBCPP_VERSION
+16 -4
View File
@@ -25,6 +25,7 @@
#include <units/bits/algorithm.h>
#include <units/bits/expression_template.h>
#include <units/bits/external/fixed_string.h>
#include <units/bits/external/type_name.h>
#include <units/bits/external/type_traits.h>
#include <units/bits/magnitude.h>
#include <units/bits/ratio.h>
@@ -523,12 +524,23 @@ template<Unit T, typename... Us>
template<Unit Lhs, Unit Rhs>
[[nodiscard]] consteval bool less(Lhs, Rhs)
{
if ((is_derived_from_specialization_of_constant_unit<Lhs> && is_derived_from_specialization_of_constant_unit<Rhs>) ||
(!is_derived_from_specialization_of_constant_unit<Lhs> && !is_derived_from_specialization_of_constant_unit<Rhs>))
return Lhs::symbol < Rhs::symbol;
else
if constexpr ((is_derived_from_specialization_of_constant_unit<Lhs> &&
is_derived_from_specialization_of_constant_unit<Rhs>) ||
(!is_derived_from_specialization_of_constant_unit<Lhs> &&
!is_derived_from_specialization_of_constant_unit<Rhs>)) {
if constexpr (requires {
Lhs::symbol;
Rhs::symbol;
})
// prefer symbols comparison if possible as it gives typically better results
// i.e. it puts upper case in from so `N m` is correct
return Lhs::symbol < Rhs::symbol;
else
return type_name<Lhs>() < type_name<Rhs>();
} else {
// put constants at the front of units list in the expression
return is_derived_from_specialization_of_constant_unit<Lhs>;
}
}