mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
refactor: math_concepts.h
removed and concepts replaced with explicit expression in constraints
This commit is contained in:
@@ -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
|
||||
|
@@ -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<auto N>
|
||||
concept gt_zero = (N > 0);
|
||||
|
||||
template<auto N>
|
||||
concept non_zero = (N != 0);
|
||||
|
||||
} // namespace mp_units::detail
|
@@ -25,7 +25,6 @@
|
||||
// IWYU pragma: private, include <mp-units/framework.h>
|
||||
#include <mp-units/bits/constexpr_math.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/ratio.h>
|
||||
#include <mp-units/bits/text_tools.h>
|
||||
@@ -593,7 +592,7 @@ using common_magnitude_type = decltype(common_magnitude_type_impl(M));
|
||||
|
||||
// Helper to perform prime factorization at compile time.
|
||||
template<std::intmax_t N>
|
||||
requires gt_zero<N>
|
||||
requires(N > 0)
|
||||
struct prime_factorization {
|
||||
[[nodiscard]] static consteval std::intmax_t get_or_compute_first_factor()
|
||||
{
|
||||
|
@@ -187,7 +187,7 @@ MP_UNITS_EXPORT_BEGIN
|
||||
* @return Dimension The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1, Dimension D>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] consteval Dimension auto pow(D d)
|
||||
{
|
||||
return detail::expr_pow<Num, Den, derived_dimension, struct dimension_one>(d);
|
||||
|
@@ -626,7 +626,7 @@ MP_UNITS_EXPORT_BEGIN
|
||||
* @return QuantitySpec The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] consteval QuantitySpec auto pow(Q q)
|
||||
{
|
||||
return detail::clone_kind_of<Q{}>(
|
||||
|
@@ -152,7 +152,7 @@ struct reference {
|
||||
* @return The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND((pow<Num, Den>(Q{}))),
|
||||
MP_UNITS_EXPRESSION_WORKAROUND((pow<Num, Den>(U{})))>
|
||||
pow(reference)
|
||||
|
@@ -22,7 +22,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/math_concepts.h>
|
||||
#include <mp-units/bits/ratio.h>
|
||||
#include <mp-units/bits/type_list.h>
|
||||
#include <mp-units/ext/type_name.h>
|
||||
@@ -86,10 +85,10 @@ template<>
|
||||
MP_UNITS_INLINE constexpr bool valid_ratio<0, 0> = false;
|
||||
|
||||
template<int Num, int... Den>
|
||||
constexpr bool positive_ratio = gt_zero<Num>;
|
||||
constexpr bool positive_ratio = Num > 0;
|
||||
|
||||
template<int Num, int Den>
|
||||
constexpr bool positive_ratio<Num, Den> = gt_zero<Num * Den>;
|
||||
constexpr bool positive_ratio<Num, Den> = Num * Den > 0;
|
||||
|
||||
template<int Num, int... Den>
|
||||
constexpr bool ratio_one = false;
|
||||
@@ -494,7 +493,7 @@ template<template<typename...> typename To, SymbolicArg OneType, typename T>
|
||||
|
||||
template<std::intmax_t Num, std::intmax_t Den, template<typename...> typename To, SymbolicArg OneType,
|
||||
template<typename, typename> typename Pred, typename... Nums, typename... Dens>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] consteval auto expr_pow_impl(type_list<Nums...>, type_list<Dens...>)
|
||||
{
|
||||
return detail::get_optimized_expression<type_list<power_or_T<Nums, ratio{Num, Den}>...>,
|
||||
@@ -514,7 +513,7 @@ template<std::intmax_t Num, std::intmax_t Den, template<typename...> typename To
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den, template<typename...> typename To, SymbolicArg OneType,
|
||||
template<typename, typename> typename Pred = type_list_name_less, typename T>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] consteval auto expr_pow(T v)
|
||||
{
|
||||
if constexpr (Num == 0 || is_same_v<T, OneType>)
|
||||
|
@@ -616,7 +616,7 @@ MP_UNITS_EXPORT_BEGIN
|
||||
* @return Unit The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1, Unit U>
|
||||
requires detail::non_zero<Den>
|
||||
requires(Den != 0)
|
||||
[[nodiscard]] consteval Unit auto pow(U u)
|
||||
{
|
||||
return detail::expr_pow<Num, Den, derived_unit, struct one>(u);
|
||||
|
@@ -73,7 +73,7 @@ template<detail::MagArg auto V>
|
||||
constexpr UnitMagnitude auto mag = detail::make_magnitude<V>();
|
||||
|
||||
template<std::intmax_t N, std::intmax_t D>
|
||||
requires detail::gt_zero<N>
|
||||
requires(N > 0)
|
||||
constexpr UnitMagnitude auto mag_ratio = detail::prime_factorization_v<N> / detail::prime_factorization_v<D>;
|
||||
|
||||
/**
|
||||
|
@@ -76,7 +76,7 @@ template<auto R, typename Rep>
|
||||
* @return Quantity The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1, auto R, typename Rep>
|
||||
requires detail::non_zero<Den> && requires(Rep v) {
|
||||
requires(Den != 0) && requires(Rep v) {
|
||||
representation_values<Rep>::one();
|
||||
requires requires { pow(v, 1.0); } || requires { std::pow(v, 1.0); };
|
||||
}
|
||||
|
Reference in New Issue
Block a user