From 47cd2fffcc759dd8623fba224f58047e57338b37 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 12 Feb 2025 08:40:06 +0100 Subject: [PATCH] refactor: `math_concepts.h` removed and concepts replaced with explicit expression in constraints --- src/core/CMakeLists.txt | 1 - .../include/mp-units/bits/math_concepts.h | 33 ------------------- .../include/mp-units/bits/unit_magnitude.h | 3 +- .../include/mp-units/framework/dimension.h | 2 +- .../mp-units/framework/quantity_spec.h | 2 +- .../include/mp-units/framework/reference.h | 2 +- .../mp-units/framework/symbolic_expression.h | 9 +++-- src/core/include/mp-units/framework/unit.h | 2 +- .../mp-units/framework/unit_magnitude.h | 2 +- src/core/include/mp-units/math.h | 2 +- 10 files changed, 11 insertions(+), 47 deletions(-) delete mode 100644 src/core/include/mp-units/bits/math_concepts.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c30657a7..2a1dedd3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -35,7 +35,6 @@ add_mp_units_module( include/mp-units/bits/core_gmf.h include/mp-units/bits/get_associated_quantity.h include/mp-units/bits/hacks.h - include/mp-units/bits/math_concepts.h include/mp-units/bits/module_macros.h include/mp-units/bits/quantity_spec_hierarchy.h include/mp-units/bits/ratio.h diff --git a/src/core/include/mp-units/bits/math_concepts.h b/src/core/include/mp-units/bits/math_concepts.h deleted file mode 100644 index 087ea485..00000000 --- a/src/core/include/mp-units/bits/math_concepts.h +++ /dev/null @@ -1,33 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2018 Mateusz Pusz -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -namespace mp_units::detail { - -template -concept gt_zero = (N > 0); - -template -concept non_zero = (N != 0); - -} // namespace mp_units::detail diff --git a/src/core/include/mp-units/bits/unit_magnitude.h b/src/core/include/mp-units/bits/unit_magnitude.h index e84da6ea..94bbade3 100644 --- a/src/core/include/mp-units/bits/unit_magnitude.h +++ b/src/core/include/mp-units/bits/unit_magnitude.h @@ -25,7 +25,6 @@ // IWYU pragma: private, include #include #include -#include #include #include #include @@ -593,7 +592,7 @@ using common_magnitude_type = decltype(common_magnitude_type_impl(M)); // Helper to perform prime factorization at compile time. template - requires gt_zero + requires(N > 0) struct prime_factorization { [[nodiscard]] static consteval std::intmax_t get_or_compute_first_factor() { diff --git a/src/core/include/mp-units/framework/dimension.h b/src/core/include/mp-units/framework/dimension.h index 287b0593..95371ae5 100644 --- a/src/core/include/mp-units/framework/dimension.h +++ b/src/core/include/mp-units/framework/dimension.h @@ -187,7 +187,7 @@ MP_UNITS_EXPORT_BEGIN * @return Dimension The result of computation */ template - requires detail::non_zero + requires(Den != 0) [[nodiscard]] consteval Dimension auto pow(D d) { return detail::expr_pow(d); diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index e498f3b2..724669ed 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -626,7 +626,7 @@ MP_UNITS_EXPORT_BEGIN * @return QuantitySpec The result of computation */ template - requires detail::non_zero + requires(Den != 0) [[nodiscard]] consteval QuantitySpec auto pow(Q q) { return detail::clone_kind_of( diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 0f767f0b..69b0c233 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -152,7 +152,7 @@ struct reference { * @return The result of computation */ template - requires detail::non_zero + requires(Den != 0) [[nodiscard]] friend consteval detail::reference_t(Q{}))), MP_UNITS_EXPRESSION_WORKAROUND((pow(U{})))> pow(reference) diff --git a/src/core/include/mp-units/framework/symbolic_expression.h b/src/core/include/mp-units/framework/symbolic_expression.h index 237a6460..884ea11f 100644 --- a/src/core/include/mp-units/framework/symbolic_expression.h +++ b/src/core/include/mp-units/framework/symbolic_expression.h @@ -22,7 +22,6 @@ #pragma once -#include #include #include #include @@ -86,10 +85,10 @@ template<> MP_UNITS_INLINE constexpr bool valid_ratio<0, 0> = false; template -constexpr bool positive_ratio = gt_zero; +constexpr bool positive_ratio = Num > 0; template -constexpr bool positive_ratio = gt_zero; +constexpr bool positive_ratio = Num * Den > 0; template constexpr bool ratio_one = false; @@ -494,7 +493,7 @@ template typename To, SymbolicArg OneType, typename T> template typename To, SymbolicArg OneType, template typename Pred, typename... Nums, typename... Dens> - requires detail::non_zero + requires(Den != 0) [[nodiscard]] consteval auto expr_pow_impl(type_list, type_list) { return detail::get_optimized_expression...>, @@ -514,7 +513,7 @@ template typename To */ template typename To, SymbolicArg OneType, template typename Pred = type_list_name_less, typename T> - requires detail::non_zero + requires(Den != 0) [[nodiscard]] consteval auto expr_pow(T v) { if constexpr (Num == 0 || is_same_v) diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 5b9463a3..3dae2d99 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -616,7 +616,7 @@ MP_UNITS_EXPORT_BEGIN * @return Unit The result of computation */ template - requires detail::non_zero + requires(Den != 0) [[nodiscard]] consteval Unit auto pow(U u) { return detail::expr_pow(u); diff --git a/src/core/include/mp-units/framework/unit_magnitude.h b/src/core/include/mp-units/framework/unit_magnitude.h index 17a21855..0659c7c5 100644 --- a/src/core/include/mp-units/framework/unit_magnitude.h +++ b/src/core/include/mp-units/framework/unit_magnitude.h @@ -73,7 +73,7 @@ template constexpr UnitMagnitude auto mag = detail::make_magnitude(); template - requires detail::gt_zero + requires(N > 0) constexpr UnitMagnitude auto mag_ratio = detail::prime_factorization_v / detail::prime_factorization_v; /** diff --git a/src/core/include/mp-units/math.h b/src/core/include/mp-units/math.h index b5838b76..5fcf72c1 100644 --- a/src/core/include/mp-units/math.h +++ b/src/core/include/mp-units/math.h @@ -76,7 +76,7 @@ template * @return Quantity The result of computation */ template - requires detail::non_zero && requires(Rep v) { + requires(Den != 0) && requires(Rep v) { representation_values::one(); requires requires { pow(v, 1.0); } || requires { std::pow(v, 1.0); }; }