diff --git a/example/include/ranged_representation.h b/example/include/ranged_representation.h index aa5eb7256f..0ffd5d70d4 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -65,10 +65,6 @@ class ranged_representation : public validated_type constexpr bool mp_units::is_scalar> = mp_units::is_scalar; -template -constexpr bool mp_units::treat_as_floating_point> = - mp_units::treat_as_floating_point; - template struct MP_UNITS_STD_FMT::formatter, Char> : formatter { template diff --git a/example/include/validated_type.h b/example/include/validated_type.h index ec42f89388..c8b5dc6a71 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -116,9 +116,6 @@ class validated_type { template constexpr bool mp_units::is_scalar> = mp_units::is_scalar; -template -constexpr bool mp_units::treat_as_floating_point> = mp_units::treat_as_floating_point; - template std::basic_ostream& operator<<(std::basic_ostream& os, diff --git a/example/measurement.cpp b/example/measurement.cpp index b0cf594b0b..5963611327 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -131,12 +131,9 @@ class measurement { } // namespace -template -constexpr bool mp_units::treat_as_floating_point> = mp_units::treat_as_floating_point; - -template +template constexpr bool mp_units::is_scalar> = true; -template +template constexpr bool mp_units::is_vector> = true; static_assert(mp_units::RepresentationOf, mp_units::quantity_character::scalar>); diff --git a/src/core/include/mp-units/bits/core_gmf.h b/src/core/include/mp-units/bits/core_gmf.h index f5392c21cc..5566bc923f 100644 --- a/src/core/include/mp-units/bits/core_gmf.h +++ b/src/core/include/mp-units/bits/core_gmf.h @@ -55,6 +55,7 @@ #if MP_UNITS_HOSTED #include #ifndef MP_UNITS_IMPORT_STD +#include #include #include #include diff --git a/src/core/include/mp-units/ext/type_traits.h b/src/core/include/mp-units/ext/type_traits.h index 965444f527..01d3780d25 100644 --- a/src/core/include/mp-units/ext/type_traits.h +++ b/src/core/include/mp-units/ext/type_traits.h @@ -29,6 +29,7 @@ #ifdef MP_UNITS_IMPORT_STD import std; #else +#include #include #include #endif @@ -100,44 +101,29 @@ constexpr bool is_derived_from_specialization_of = requires(T* t) { detail::to_b template typename Type> constexpr bool is_derived_from_specialization_of_v = requires(T* t) { detail::to_base_specialization_of_v(t); }; -namespace detail { - -template -struct get_value_type { - using type = T::value_type; -}; - template -struct get_element_type { - using type = std::remove_reference_t; -}; - -} // namespace detail + requires(!std::is_pointer_v && !std::is_array_v) && + requires { typename std::indirectly_readable_traits::value_type; } +using wrapped_type_t = std::indirectly_readable_traits::value_type; -template - requires requires { typename T::value_type; } || requires { typename T::element_type; } -struct wrapped_type { - using type = - conditional, detail::get_element_type>::type; -}; - -template - requires requires { typename T::value_type; } || requires { typename T::element_type; } -using wrapped_type_t = wrapped_type::type; +namespace detail { template -struct value_type { +struct value_type_impl { using type = T; }; template requires requires { typename wrapped_type_t; } -struct value_type { +struct value_type_impl { using type = wrapped_type_t; }; +} // namespace detail + template -using value_type_t = value_type::type; + requires std::is_object_v +using value_type_t = detail::value_type_impl::type; template concept one_of = (false || ... || std::same_as); diff --git a/src/core/include/mp-units/framework/customization_points.h b/src/core/include/mp-units/framework/customization_points.h index 6b40e83338..43ca02014b 100644 --- a/src/core/include/mp-units/framework/customization_points.h +++ b/src/core/include/mp-units/framework/customization_points.h @@ -33,6 +33,9 @@ import std; #include #include #include +#if MP_UNITS_HOSTED +#include +#endif #endif #endif @@ -50,11 +53,12 @@ MP_UNITS_EXPORT_BEGIN * @tparam Rep a representation type for which a type trait is defined */ template -constexpr bool treat_as_floating_point = std::is_floating_point_v; - -template - requires requires { typename wrapped_type_t; } -constexpr bool treat_as_floating_point = treat_as_floating_point>; +constexpr bool treat_as_floating_point = +#if MP_UNITS_HOSTED + std::chrono::treat_as_floating_point_v>; +#else + std::is_floating_point_v>; +#endif /** * @brief Specifies a type to have a scalar character diff --git a/src/core/include/mp-units/framework/dimension.h b/src/core/include/mp-units/framework/dimension.h index 72b15dd65e..24a1e7b843 100644 --- a/src/core/include/mp-units/framework/dimension.h +++ b/src/core/include/mp-units/framework/dimension.h @@ -52,20 +52,23 @@ import std; namespace mp_units { -template +template struct derived_dimension; MP_UNITS_EXPORT struct dimension_one; namespace detail { +template +struct is_dimension_one : std::false_type {}; + template struct base_dimension_less : std::bool_constant() < type_name()> {}; template using type_list_of_base_dimension_less = expr_less; -template +template struct derived_dimension_impl : expr_fractions {}; struct dimension_interface { @@ -165,7 +168,7 @@ struct base_dimension : detail::dimension_interface { * @note User should not instantiate this type! It is not exported from the C++ module. The library will * instantiate this type automatically based on the dimensional arithmetic equation provided by the user. */ -template +template struct derived_dimension final : detail::dimension_interface, detail::derived_dimension_impl {}; /** @@ -250,14 +253,14 @@ constexpr auto dimension_symbol_impl(Out out, const power&, cons return copy_symbol_exponent(fmt.encoding, negative_power, out); } -template Out, DerivedDimensionExpr... Ms> +template Out, typename... Ms> constexpr Out dimension_symbol_impl(Out out, const type_list&, const dimension_symbol_formatting& fmt, bool negative_power) { return (..., (out = dimension_symbol_impl(out, Ms{}, fmt, negative_power))); } -template Out, DerivedDimensionExpr... Nums, DerivedDimensionExpr... Dens> +template Out, typename... Nums, typename... Dens> constexpr Out dimension_symbol_impl(Out out, const type_list& nums, const type_list& dens, const dimension_symbol_formatting& fmt) { diff --git a/src/core/include/mp-units/framework/dimension_concepts.h b/src/core/include/mp-units/framework/dimension_concepts.h index 18bec37aa4..6e3c653b69 100644 --- a/src/core/include/mp-units/framework/dimension_concepts.h +++ b/src/core/include/mp-units/framework/dimension_concepts.h @@ -57,23 +57,6 @@ namespace detail { template concept BaseDimension = Dimension && is_derived_from_specialization_of_v; -template -struct is_dimension_one : std::false_type {}; - -template -concept IsPowerOfDim = - is_specialization_of_power && (BaseDimension || is_dimension_one::value); - -template -constexpr bool is_per_of_dims = false; - -template -constexpr bool is_per_of_dims> = - (... && (BaseDimension || is_dimension_one::value || IsPowerOfDim)); - -template -concept DerivedDimensionExpr = BaseDimension || is_dimension_one::value || IsPowerOfDim || is_per_of_dims; - } // namespace detail /** diff --git a/src/core/include/mp-units/framework/magnitude.h b/src/core/include/mp-units/framework/magnitude.h index 5873da1eab..ff2981d81e 100644 --- a/src/core/include/mp-units/framework/magnitude.h +++ b/src/core/include/mp-units/framework/magnitude.h @@ -428,22 +428,22 @@ constexpr Out magnitude_symbol_impl(Out out, const unit_symbol_formatting& fmt) template struct magnitude : detail::magnitude_base> { template - [[nodiscard]] friend consteval Magnitude auto operator*(magnitude m1, M m2) + [[nodiscard]] friend consteval Magnitude auto operator*(magnitude lhs, M rhs) { if constexpr (sizeof...(Ms) == 0) - return m2; + return rhs; else if constexpr (is_same_v>) - return m1; + return lhs; else - return _multiply_impl(m1, m2); + return _multiply_impl(lhs, rhs); } - [[nodiscard]] friend consteval auto operator/(magnitude l, Magnitude auto r) { return l * _pow<-1>(r); } + [[nodiscard]] friend consteval auto operator/(magnitude lhs, Magnitude auto rhs) { return lhs * _pow<-1>(rhs); } - template - [[nodiscard]] friend consteval bool operator==(magnitude, M2) + template + [[nodiscard]] friend consteval bool operator==(magnitude, Rhs) { - return is_same_v; + return is_same_v; } private: diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 67ea73ff67..3c4dc0c9ba 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -63,9 +63,11 @@ template concept IsFloatingPoint = treat_as_floating_point; template -concept ValuePreservingTo = requires(FromRep&& from, ToRep to) { - { to = std::forward(from) } -> std::same_as; -} && (IsFloatingPoint || (!IsFloatingPoint && (integral_conversion_factor(FromUnit, ToUnit)))); +concept ValuePreservingTo = + requires(FromRep&& from, ToRep to) { + { to = std::forward(from) } -> std::same_as; + } && (IsFloatingPoint || + (!IsFloatingPoint> && (integral_conversion_factor(FromUnit, ToUnit)))); template concept QuantityConvertibleTo = diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index a3efa56870..e2fbefc019 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -520,38 +520,24 @@ struct is_dimensionless : std::true_type {}; */ namespace detail { -template -concept QuantitySpecWithNoSpecifiers = detail::NamedQuantitySpec || detail::DerivedQuantitySpec; - template [[nodiscard]] consteval QuantitySpec auto get_kind_tree_root(Q q); } // namespace detail -#if MP_UNITS_API_NO_CRTP template - requires detail::QuantitySpecWithNoSpecifiers && detail::SameQuantitySpec + requires(!detail::QuantityKindSpec) && detail::SameQuantitySpec +#if MP_UNITS_API_NO_CRTP struct kind_of_ final : Q::_base_type_ { - using _base_type_ = kind_of_; - static constexpr auto _quantity_spec_ = Q{}; -}; #else - -#if MP_UNITS_COMP_CLANG -template - requires detail::QuantitySpecWithNoSpecifiers && detail::SameQuantitySpec -#else -template - requires detail::SameQuantitySpec -#endif struct kind_of_ final : quantity_spec, Q{}>::_base_type_ { +#endif using _base_type_ = kind_of_; static constexpr auto _quantity_spec_ = Q{}; }; -#endif -MP_UNITS_EXPORT template - requires detail::SameQuantitySpec +MP_UNITS_EXPORT template + requires requires { typename kind_of_; } constexpr kind_of_ kind_of; namespace detail {