mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 13:14:29 +02:00
refactor: constexpr
replaced with consteval
This commit is contained in:
@@ -66,7 +66,7 @@ struct power<F, Num, Den> {
|
||||
namespace detail {
|
||||
|
||||
template<typename T, int Num, int Den>
|
||||
constexpr auto power_or_T_impl()
|
||||
consteval auto power_or_T_impl()
|
||||
{
|
||||
constexpr ratio r{Num, Den};
|
||||
if constexpr (r.den == 1) {
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
};
|
||||
|
||||
template<typename NumList, typename DenList, typename OneType, template<typename...> typename To>
|
||||
[[nodiscard]] constexpr auto expr_expression_impl()
|
||||
[[nodiscard]] consteval auto expr_expression_impl()
|
||||
{
|
||||
constexpr std::size_t num = type_list_size<NumList>;
|
||||
constexpr std::size_t den = type_list_size<DenList>;
|
||||
@@ -312,7 +312,7 @@ using expr_expression = decltype(expr_expression_impl<NumList, DenList, OneType,
|
||||
|
||||
template<typename NumList, typename DenList, typename OneType, template<typename, typename> typename Pred,
|
||||
template<typename...> typename To>
|
||||
[[nodiscard]] constexpr auto get_optimized_expression()
|
||||
[[nodiscard]] consteval auto get_optimized_expression()
|
||||
{
|
||||
using num_list = expr_consolidate<NumList>;
|
||||
using den_list = expr_consolidate<DenList>;
|
||||
@@ -332,7 +332,7 @@ template<typename NumList, typename DenList, typename OneType, template<typename
|
||||
*/
|
||||
template<typename T1, typename T2, typename OneType, template<typename, typename> typename Pred,
|
||||
template<typename...> typename To>
|
||||
[[nodiscard]] constexpr auto expr_multiply()
|
||||
[[nodiscard]] consteval auto expr_multiply()
|
||||
{
|
||||
if constexpr (is_same_v<T1, OneType>) {
|
||||
return T2{};
|
||||
@@ -356,7 +356,7 @@ template<typename T1, typename T2, typename OneType, template<typename, typename
|
||||
|
||||
template<typename T1, typename T2, typename OneType, template<typename, typename> typename Pred,
|
||||
template<typename...> typename To>
|
||||
[[nodiscard]] constexpr auto expr_divide()
|
||||
[[nodiscard]] consteval auto expr_divide()
|
||||
{
|
||||
if constexpr (is_same_v<T1, T2>) {
|
||||
return OneType{};
|
||||
@@ -378,7 +378,7 @@ template<typename T1, typename T2, typename OneType, template<typename, typename
|
||||
}
|
||||
|
||||
template<typename T, typename OneType, template<typename...> typename To>
|
||||
[[nodiscard]] constexpr auto expr_invert()
|
||||
[[nodiscard]] consteval auto expr_invert()
|
||||
{
|
||||
if constexpr (is_specialization_of<T, To>)
|
||||
return expr_expression<typename T::den, typename T::num, OneType, To>{};
|
||||
|
@@ -48,7 +48,7 @@ concept TypeList = detail::is_type_list<T>;
|
||||
namespace detail {
|
||||
|
||||
template<template<typename...> typename List, typename... Ts>
|
||||
constexpr std::size_t type_list_size_impl(List<Ts...>)
|
||||
consteval std::size_t type_list_size_impl(List<Ts...>)
|
||||
{
|
||||
return sizeof...(Ts);
|
||||
}
|
||||
|
@@ -140,28 +140,28 @@ using dim_type = dim_type_impl<T>::type;
|
||||
} // namespace detail
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] constexpr Dimension auto operator*(D1, D2)
|
||||
[[nodiscard]] consteval Dimension auto operator*(D1, D2)
|
||||
{
|
||||
return detail::expr_multiply<detail::dim_type<D1>, detail::dim_type<D2>, struct one_dim,
|
||||
detail::type_list_of_base_dimension_less, derived_dimension>();
|
||||
}
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] constexpr Dimension auto operator/(D1, D2)
|
||||
[[nodiscard]] consteval Dimension auto operator/(D1, D2)
|
||||
{
|
||||
return detail::expr_divide<detail::dim_type<D1>, detail::dim_type<D2>, struct one_dim,
|
||||
detail::type_list_of_base_dimension_less, derived_dimension>();
|
||||
}
|
||||
|
||||
template<Dimension D>
|
||||
[[nodiscard]] constexpr Dimension auto operator/(int value, D)
|
||||
[[nodiscard]] consteval Dimension auto operator/(int value, D)
|
||||
{
|
||||
gsl_Assert(value == 1);
|
||||
return detail::expr_invert<detail::dim_type<D>, struct one_dim, derived_dimension>();
|
||||
}
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] constexpr bool operator==(D1, D2)
|
||||
[[nodiscard]] consteval bool operator==(D1, D2)
|
||||
{
|
||||
return is_same_v<detail::dim_type<D1>, detail::dim_type<D2>>;
|
||||
}
|
||||
|
@@ -121,14 +121,14 @@ template<typename T>
|
||||
concept Reference = is_specialization_of<T, reference>;
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] constexpr reference<decltype(R1::dimension * R2::dimension), decltype(R1::unit * R2::unit)> operator*(R1,
|
||||
[[nodiscard]] consteval reference<decltype(R1::dimension * R2::dimension), decltype(R1::unit * R2::unit)> operator*(R1,
|
||||
R2)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] constexpr reference<decltype(R1::dimension / R2::dimension), decltype(R1::unit / R2::unit)> operator/(R1,
|
||||
[[nodiscard]] consteval reference<decltype(R1::dimension / R2::dimension), decltype(R1::unit / R2::unit)> operator/(R1,
|
||||
R2)
|
||||
{
|
||||
return {};
|
||||
@@ -153,7 +153,7 @@ struct system_reference {
|
||||
|
||||
template<Unit U>
|
||||
// requires same_unit_reference<CoU, U>
|
||||
[[nodiscard]] constexpr reference<Child, U> operator[](U) const
|
||||
[[nodiscard]] consteval reference<Child, U> operator[](U) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@@ -221,26 +221,26 @@ using type_list_of_unit_less = expr_less<T1, T2, unit_less>;
|
||||
} // namespace detail
|
||||
|
||||
template<Unit U1, Unit U2>
|
||||
[[nodiscard]] constexpr Unit auto operator*(U1, U2)
|
||||
[[nodiscard]] consteval Unit auto operator*(U1, U2)
|
||||
{
|
||||
return detail::expr_multiply<U1, U2, struct one, detail::type_list_of_unit_less, derived_unit>();
|
||||
}
|
||||
|
||||
template<Unit U1, Unit U2>
|
||||
[[nodiscard]] constexpr Unit auto operator/(U1, U2)
|
||||
[[nodiscard]] consteval Unit auto operator/(U1, U2)
|
||||
{
|
||||
return detail::expr_divide<U1, U2, struct one, detail::type_list_of_unit_less, derived_unit>();
|
||||
}
|
||||
|
||||
template<Unit U>
|
||||
[[nodiscard]] constexpr Unit auto operator/(int value, U)
|
||||
[[nodiscard]] consteval Unit auto operator/(int value, U)
|
||||
{
|
||||
gsl_Assert(value == 1);
|
||||
return detail::expr_invert<U, struct one, derived_unit>();
|
||||
}
|
||||
|
||||
template<Unit U1, Unit U2>
|
||||
[[nodiscard]] constexpr bool operator==(U1, U2)
|
||||
[[nodiscard]] consteval bool operator==(U1, U2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user