refactor: Repetitive inline constexpr removed as no longer needed

Not needed anymore as stated in cplusplus/draft#4601
This commit is contained in:
Mateusz Pusz committed 2024-09-05 08:43:36 +02:00
1 parent 2a4e1e3d95
commit 2e840cfdb4
95 files changed
+1765 -1772

No files matched your search

+1 -1
View File
@@ -122,7 +122,7 @@ public:
MP_UNITS_EXPORT_END
template<typename T>
inline constexpr bool is_integer =
constexpr bool is_integer =
std::is_integral_v<T> && !std::is_same_v<T, bool> && !std::is_same_v<T, char> && !std::is_same_v<T, wchar_t>;
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
+1 -1
View File
@@ -104,7 +104,7 @@ namespace std {
struct from_range_t {
explicit from_range_t() = default;
};
inline constexpr from_range_t from_range{};
constexpr from_range_t from_range{};
} // namespace std
+13 -13
View File
@@ -40,32 +40,32 @@ namespace mp_units::detail {
template<std::intmax_t Value>
requires(0 <= Value) && (Value < 10)
inline constexpr basic_fixed_string superscript_number = u8"";
constexpr basic_fixed_string superscript_number = u8"";
template<>
inline constexpr basic_fixed_string superscript_number<0> = u8"\u2070";
constexpr basic_fixed_string superscript_number<0> = u8"\u2070";
template<>
inline constexpr basic_fixed_string superscript_number<1> = u8"\u00b9";
constexpr basic_fixed_string superscript_number<1> = u8"\u00b9";
template<>
inline constexpr basic_fixed_string superscript_number<2> = u8"\u00b2";
constexpr basic_fixed_string superscript_number<2> = u8"\u00b2";
template<>
inline constexpr basic_fixed_string superscript_number<3> = u8"\u00b3";
constexpr basic_fixed_string superscript_number<3> = u8"\u00b3";
template<>
inline constexpr basic_fixed_string superscript_number<4> = u8"\u2074";
constexpr basic_fixed_string superscript_number<4> = u8"\u2074";
template<>
inline constexpr basic_fixed_string superscript_number<5> = u8"\u2075";
constexpr basic_fixed_string superscript_number<5> = u8"\u2075";
template<>
inline constexpr basic_fixed_string superscript_number<6> = u8"\u2076";
constexpr basic_fixed_string superscript_number<6> = u8"\u2076";
template<>
inline constexpr basic_fixed_string superscript_number<7> = u8"\u2077";
constexpr basic_fixed_string superscript_number<7> = u8"\u2077";
template<>
inline constexpr basic_fixed_string superscript_number<8> = u8"\u2078";
constexpr basic_fixed_string superscript_number<8> = u8"\u2078";
template<>
inline constexpr basic_fixed_string superscript_number<9> = u8"\u2079";
constexpr basic_fixed_string superscript_number<9> = u8"\u2079";
inline constexpr symbol_text superscript_minus(u8"\u207b", "-");
constexpr symbol_text superscript_minus(u8"\u207b", "-");
inline constexpr symbol_text superscript_prefix(u8"", "^");
constexpr symbol_text superscript_prefix(u8"", "^");
template<std::intmax_t Value>
[[nodiscard]] consteval auto superscript_helper()
+3 -3
View File
@@ -40,10 +40,10 @@ MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
namespace mp_units::detail {
template<typename T>
inline constexpr bool is_type_list = false;
constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
constexpr bool is_type_list<T<Types...>> = true;
template<typename T>
concept TypeList = is_type_list<T>;
@@ -56,7 +56,7 @@ template<template<typename...> typename List, typename... Types>
struct type_list_size_impl<List<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> {};
template<TypeList List>
inline constexpr std::size_t type_list_size = type_list_size_impl<List>::value;
constexpr std::size_t type_list_size = type_list_size_impl<List>::value;
// map
template<typename T, template<typename...> typename To>
+4 -4
View File
@@ -28,14 +28,14 @@
#if MP_UNITS_API_NO_CRTP
#define QUANTITY_SPEC(name, ...) \
inline constexpr struct name final : ::mp_units::quantity_spec<__VA_ARGS__> { \
#define QUANTITY_SPEC(name, ...) \
constexpr struct name final : ::mp_units::quantity_spec<__VA_ARGS__> { \
} name
#else
#define QUANTITY_SPEC(name, ...) \
inline constexpr struct name final : ::mp_units::quantity_spec<name, __VA_ARGS__> { \
#define QUANTITY_SPEC(name, ...) \
constexpr struct name final : ::mp_units::quantity_spec<name, __VA_ARGS__> { \
} name
#endif
+7 -8
View File
@@ -60,26 +60,26 @@ using conditional = MP_UNITS_TYPENAME detail::conditional_impl<B>::template type
// is_same
template<class T, class U>
inline constexpr bool is_same_v = false;
constexpr bool is_same_v = false;
template<class T>
inline constexpr bool is_same_v<T, T> = true;
constexpr bool is_same_v<T, T> = true;
template<class T, class U>
using is_same = std::bool_constant<is_same_v<T, U>>;
// is_specialization_of
template<typename T, template<typename...> typename Type>
inline constexpr bool is_specialization_of = false;
constexpr bool is_specialization_of = false;
template<typename... Params, template<typename...> typename Type>
inline constexpr bool is_specialization_of<Type<Params...>, Type> = true;
constexpr bool is_specialization_of<Type<Params...>, Type> = true;
template<typename T, template<auto...> typename Type>
inline constexpr bool is_specialization_of_v = false;
constexpr bool is_specialization_of_v = false;
template<auto... Params, template<auto...> typename Type>
inline constexpr bool is_specialization_of_v<Type<Params...>, Type> = true;
constexpr bool is_specialization_of_v<Type<Params...>, Type> = true;
MP_UNITS_EXPORT_END
@@ -92,8 +92,7 @@ void to_base_specialization_of(const volatile Type<Params...>*);
} // namespace detail
template<typename T, template<typename...> typename Type>
inline constexpr bool is_derived_from_specialization_of =
requires(T* t) { detail::to_base_specialization_of<Type>(t); };
constexpr bool is_derived_from_specialization_of = requires(T* t) { detail::to_base_specialization_of<Type>(t); };
namespace detail {
@@ -61,10 +61,10 @@ struct absolute_ {
MP_UNITS_EXPORT_BEGIN
template<Reference auto R>
inline constexpr delta_<MP_UNITS_REMOVE_CONST(decltype(R))> delta{};
constexpr delta_<MP_UNITS_REMOVE_CONST(decltype(R))> delta{};
template<Reference auto R>
inline constexpr absolute_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};
constexpr absolute_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};
MP_UNITS_EXPORT_END
@@ -50,11 +50,11 @@ MP_UNITS_EXPORT_BEGIN
* @tparam Rep a representation type for which a type trait is defined
*/
template<typename Rep>
inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
template<typename Rep>
requires requires { typename wrapped_type_t<Rep>; }
inline constexpr bool treat_as_floating_point<Rep> = treat_as_floating_point<wrapped_type_t<Rep>>;
constexpr bool treat_as_floating_point<Rep> = treat_as_floating_point<wrapped_type_t<Rep>>;
/**
* @brief Specifies a type to have a scalar character
@@ -62,7 +62,7 @@ inline constexpr bool treat_as_floating_point<Rep> = treat_as_floating_point<wra
* A scalar is a physical quantity that has magnitude but no direction.
*/
template<typename Rep>
inline constexpr bool is_scalar = std::is_floating_point_v<Rep> || (std::is_integral_v<Rep> && !is_same_v<Rep, bool>);
constexpr bool is_scalar = std::is_floating_point_v<Rep> || (std::is_integral_v<Rep> && !is_same_v<Rep, bool>);
/**
* @brief Specifies a type to have a vector character
@@ -76,11 +76,11 @@ inline constexpr bool is_scalar = std::is_floating_point_v<Rep> || (std::is_inte
* @code{.cpp}
* template<class T>
* requires mp_units::is_scalar<T>
* inline constexpr bool mp_units::is_vector<T> = true;
* constexpr bool mp_units::is_vector<T> = true;
* @endcode
*/
template<typename Rep>
inline constexpr bool is_vector = false;
constexpr bool is_vector = false;
/**
* @brief Specifies a type to have a tensor character
@@ -91,7 +91,7 @@ inline constexpr bool is_vector = false;
* Similarly to `is_vector` a partial specialization is needed in such cases.
*/
template<typename Rep>
inline constexpr bool is_tensor = false;
constexpr bool is_tensor = false;
/**
* @brief A type trait that defines zero, one, min, and max for a representation type
@@ -115,9 +115,9 @@ struct dimension_interface {
* For example:
*
* @code{.cpp}
* inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
* inline constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
* inline constexpr struct dim_mass final : base_dimension<"M"> {} dim_mass;
* constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
* constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
* constexpr struct dim_mass final : base_dimension<"M"> {} dim_mass;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -184,9 +184,7 @@ struct derived_dimension final : detail::dimension_interface, detail::derived_di
* dimensions are zero. It is a dimension of a quantity of dimension one also known as
* "dimensionless".
*/
MP_UNITS_EXPORT inline constexpr struct dimension_one final :
detail::dimension_interface,
detail::derived_dimension_impl<> {
MP_UNITS_EXPORT constexpr struct dimension_one final : detail::dimension_interface, detail::derived_dimension_impl<> {
} dimension_one;
namespace detail {
@@ -53,7 +53,7 @@ template<symbol_text Symbol>
void to_base_specialization_of_base_dimension(const volatile base_dimension<Symbol>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_base_dimension =
constexpr bool is_derived_from_specialization_of_base_dimension =
requires(T* t) { to_base_specialization_of_base_dimension(t); };
/**
@@ -68,16 +68,16 @@ template<typename T>
struct is_dimension_one : std::false_type {};
template<typename T>
inline constexpr bool is_power_of_dim = requires {
constexpr bool is_power_of_dim = requires {
requires is_specialization_of_power<T> &&
(BaseDimension<typename T::factor> || is_dimension_one<typename T::factor>::value);
};
template<typename T>
inline constexpr bool is_per_of_dims = false;
constexpr bool is_per_of_dims = false;
template<typename... Ts>
inline constexpr bool is_per_of_dims<per<Ts...>> =
constexpr bool is_per_of_dims<per<Ts...>> =
(... && (BaseDimension<Ts> || is_dimension_one<Ts>::value || is_power_of_dim<Ts>));
template<typename T>
@@ -57,37 +57,37 @@ struct per {};
namespace detail {
template<typename T>
inline constexpr bool is_specialization_of_per = false;
constexpr bool is_specialization_of_per = false;
template<typename... Ts>
inline constexpr bool is_specialization_of_per<per<Ts...>> = true;
constexpr bool is_specialization_of_per<per<Ts...>> = true;
template<int Num, int... Den>
inline constexpr bool valid_ratio = true;
constexpr bool valid_ratio = true;
template<int... Den>
inline constexpr bool valid_ratio<0, Den...> = false;
constexpr bool valid_ratio<0, Den...> = false;
template<int Num>
inline constexpr bool valid_ratio<Num, 0> = false;
constexpr bool valid_ratio<Num, 0> = false;
template<>
inline constexpr bool valid_ratio<0, 0> = false;
constexpr bool valid_ratio<0, 0> = false;
template<int Num, int... Den>
inline constexpr bool positive_ratio = gt_zero<Num>;
constexpr bool positive_ratio = gt_zero<Num>;
template<int Num, int Den>
inline constexpr bool positive_ratio<Num, Den> = gt_zero<Num * Den>;
constexpr bool positive_ratio<Num, Den> = gt_zero<Num * Den>;
template<int Num, int... Den>
inline constexpr bool ratio_one = false;
constexpr bool ratio_one = false;
template<>
inline constexpr bool ratio_one<1> = true;
constexpr bool ratio_one<1> = true;
template<int N>
inline constexpr bool ratio_one<N, N> = true;
constexpr bool ratio_one<N, N> = true;
} // namespace detail
@@ -127,10 +127,10 @@ using expr_type = MP_UNITS_TYPENAME detail::expr_type_impl<T>::type;
namespace detail {
template<typename T>
inline constexpr bool is_specialization_of_power = false;
constexpr bool is_specialization_of_power = false;
template<typename F, int... Ints>
inline constexpr bool is_specialization_of_power<power<F, Ints...>> = true;
constexpr bool is_specialization_of_power<power<F, Ints...>> = true;
template<typename T, ratio R>
consteval auto power_or_T_impl()
@@ -509,10 +509,10 @@ concept expr_type_projectable = (requires { typename Proj<T>; } ||
(is_specialization_of_power<T> && requires { typename Proj<typename T::factor>; }));
template<typename T, template<typename> typename Proj>
inline constexpr bool expr_projectable_impl = false;
constexpr bool expr_projectable_impl = false;
template<typename... Ts, template<typename> typename Proj>
inline constexpr bool expr_projectable_impl<type_list<Ts...>, Proj> = (... && expr_type_projectable<Ts, Proj>);
constexpr bool expr_projectable_impl<type_list<Ts...>, Proj> = (... && expr_type_projectable<Ts, Proj>);
template<typename T, template<typename> typename Proj>
concept expr_projectable = requires {
+20 -21
View File
@@ -59,10 +59,10 @@ using factorizer = wheel_factorizer<4>;
namespace detail {
template<typename T>
inline constexpr bool is_magnitude = false;
constexpr bool is_magnitude = false;
template<typename T>
inline constexpr bool is_specialization_of_magnitude = false;
constexpr bool is_specialization_of_magnitude = false;
} // namespace detail
@@ -87,7 +87,7 @@ concept Magnitude = detail::is_magnitude<T>;
// void to_base_specialization_of_constant(const volatile constant<V>*);
// template<typename T>
// inline constexpr bool is_derived_from_specialization_of_constant =
// constexpr bool is_derived_from_specialization_of_constant =
// requires(T * t) { to_base_specialization_of_constant(t); };
// } // namespace detail
@@ -142,7 +142,7 @@ concept Magnitude = detail::is_magnitude<T>;
namespace detail {
template<typename T>
inline constexpr bool is_named_magnitude = Magnitude<T> && !detail::is_specialization_of_magnitude<T>;
constexpr bool is_named_magnitude = Magnitude<T> && !detail::is_specialization_of_magnitude<T>;
}
@@ -178,10 +178,10 @@ struct power_v {
namespace detail {
template<typename T>
inline constexpr bool is_specialization_of_power_v = false;
constexpr bool is_specialization_of_power_v = false;
template<auto V, int... Ints>
inline constexpr bool is_specialization_of_power_v<power_v<V, Ints...>> = true;
constexpr bool is_specialization_of_power_v<power_v<V, Ints...>> = true;
} // namespace detail
@@ -572,13 +572,13 @@ namespace detail {
// }
// template<MagnitudeSpec auto... Elements>
// inline constexpr bool all_elements_valid = (is_valid_element(Elements) && ...);
// constexpr bool all_elements_valid = (is_valid_element(Elements) && ...);
// template<MagnitudeSpec auto... Elements>
// inline constexpr bool all_elements_in_order = strictly_increasing(get_base_value(Elements)...);
// constexpr bool all_elements_in_order = strictly_increasing(get_base_value(Elements)...);
// template<MagnitudeSpec auto... Elements>
// inline constexpr bool is_element_pack_valid = all_elements_valid<Elements...> && all_elements_in_order<Elements...>;
// constexpr bool is_element_pack_valid = all_elements_valid<Elements...> && all_elements_in_order<Elements...>;
[[nodiscard]] consteval bool is_rational(MagnitudeSpec auto element)
{
@@ -707,15 +707,14 @@ template<auto... Ms>
void to_base_specialization_of_magnitude(const volatile magnitude<Ms...>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_magnitude =
requires(T* t) { to_base_specialization_of_magnitude(t); };
constexpr bool is_derived_from_specialization_of_magnitude = requires(T* t) { to_base_specialization_of_magnitude(t); };
template<typename T>
requires is_derived_from_specialization_of_magnitude<T>
inline constexpr bool is_magnitude<T> = true;
constexpr bool is_magnitude<T> = true;
template<auto... Ms>
inline constexpr bool is_specialization_of_magnitude<magnitude<Ms...>> = true;
constexpr bool is_specialization_of_magnitude<magnitude<Ms...>> = true;
} // namespace detail
@@ -726,12 +725,12 @@ MP_UNITS_EXPORT_BEGIN
*/
#if MP_UNITS_COMP_CLANG
inline constexpr struct mag_pi : magnitude<mag_value{std::numbers::pi_v<long double>}> {
constexpr struct mag_pi : magnitude<mag_value{std::numbers::pi_v<long double>}> {
} mag_pi;
#else
inline constexpr struct mag_pi : magnitude<std::numbers::pi_v<long double>> {
constexpr struct mag_pi : magnitude<std::numbers::pi_v<long double>> {
} mag_pi;
#endif
@@ -882,7 +881,7 @@ using common_magnitude_type = decltype(common_magnitude_type_impl(M));
//
// WARNING: The program behaviour will be undefined if you provide a wrong answer, so check your math!
MP_UNITS_EXPORT template<std::intmax_t N>
inline constexpr std::optional<std::intmax_t> known_first_factor = std::nullopt;
constexpr std::optional<std::intmax_t> known_first_factor = std::nullopt;
namespace detail {
@@ -915,7 +914,7 @@ struct prime_factorization<1> {
};
template<std::intmax_t N>
inline constexpr auto prime_factorization_v = prime_factorization<N>::value;
constexpr auto prime_factorization_v = prime_factorization<N>::value;
} // namespace detail
@@ -927,18 +926,18 @@ inline constexpr auto prime_factorization_v = prime_factorization<N>::value;
*/
MP_UNITS_EXPORT template<std::intmax_t V>
requires detail::gt_zero<V>
inline constexpr Magnitude auto mag = detail::prime_factorization_v<V>;
constexpr Magnitude auto mag = detail::prime_factorization_v<V>;
MP_UNITS_EXPORT template<std::intmax_t N, std::intmax_t D>
requires detail::gt_zero<N>
inline constexpr Magnitude auto mag_ratio = detail::prime_factorization_v<N> / detail::prime_factorization_v<D>;
constexpr Magnitude auto mag_ratio = detail::prime_factorization_v<N> / detail::prime_factorization_v<D>;
/**
* @brief Create a Magnitude which is some rational number raised to a rational power.
*/
MP_UNITS_EXPORT template<std::intmax_t Base, std::intmax_t Pow>
requires detail::gt_zero<Base>
inline constexpr Magnitude auto mag_power = pow<Pow>(mag<Base>);
constexpr Magnitude auto mag_power = pow<Pow>(mag<Base>);
namespace detail {
@@ -960,7 +959,7 @@ template<typename T, auto... Ms>
return integer_part((detail::abs(power_of_2) < detail::abs(power_of_5)) ? power_of_2 : power_of_5);
}
inline constexpr symbol_text base_multiplier(u8"× 10", "x 10");
constexpr symbol_text base_multiplier(u8"× 10", "x 10");
template<Magnitude auto M>
[[nodiscard]] consteval auto magnitude_text()
@@ -40,8 +40,7 @@ template<auto R, typename Rep>
void to_base_specialization_of_quantity(const volatile quantity<R, Rep>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_quantity =
requires(T* t) { to_base_specialization_of_quantity(t); };
constexpr bool is_derived_from_specialization_of_quantity = requires(T* t) { to_base_specialization_of_quantity(t); };
} // namespace detail
@@ -43,7 +43,7 @@ namespace mp_units {
namespace detail {
template<PointOrigin PO>
inline constexpr bool is_specialization_of_zeroth_point_origin = false;
constexpr bool is_specialization_of_zeroth_point_origin = false;
template<PointOrigin PO>
[[nodiscard]] consteval bool is_zeroth_point_origin(PO)
@@ -130,12 +130,12 @@ template<QuantitySpec auto QS>
struct zeroth_point_origin_ final : absolute_point_origin<QS> {};
MP_UNITS_EXPORT template<QuantitySpec auto QS>
inline constexpr zeroth_point_origin_<QS> zeroth_point_origin;
constexpr zeroth_point_origin_<QS> zeroth_point_origin;
namespace detail {
template<auto QS>
inline constexpr bool is_specialization_of_zeroth_point_origin<zeroth_point_origin_<QS>> = true;
constexpr bool is_specialization_of_zeroth_point_origin<zeroth_point_origin_<QS>> = true;
} // namespace detail
@@ -38,13 +38,13 @@ struct absolute_point_origin;
namespace detail {
template<typename T>
inline constexpr bool is_quantity_point = false;
constexpr bool is_quantity_point = false;
template<auto Q>
void to_base_specialization_of_absolute_point_origin(const volatile absolute_point_origin<Q>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_absolute_point_origin =
constexpr bool is_derived_from_specialization_of_absolute_point_origin =
requires(T* t) { to_base_specialization_of_absolute_point_origin(t); };
} // namespace detail
@@ -66,7 +66,7 @@ template<auto QP>
void to_base_specialization_of_relative_point_origin(const volatile relative_point_origin<QP>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_relative_point_origin =
constexpr bool is_derived_from_specialization_of_relative_point_origin =
requires(T* t) { to_base_specialization_of_relative_point_origin(t); };
struct point_origin_interface;
@@ -99,12 +99,12 @@ template<auto R, auto PO, typename Rep>
void to_base_specialization_of_quantity_point(const volatile quantity_point<R, PO, Rep>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_quantity_point =
constexpr bool is_derived_from_specialization_of_quantity_point =
requires(T* t) { to_base_specialization_of_quantity_point(t); };
template<typename T>
requires is_derived_from_specialization_of_quantity_point<T>
inline constexpr bool is_quantity_point<T> = true;
constexpr bool is_quantity_point<T> = true;
template<PointOrigin PO1, PointOrigin PO2>
[[nodiscard]] consteval bool same_absolute_point_origins(PO1 po1, PO2 po2)
@@ -189,7 +189,7 @@ struct quantity_spec_interface : quantity_spec_interface_base {
MP_UNITS_EXPORT_BEGIN
inline constexpr struct is_kind {
constexpr struct is_kind {
} is_kind;
/**
@@ -235,13 +235,13 @@ MP_UNITS_EXPORT_END
* For example:
*
* @code{.cpp}
* inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
* inline constexpr struct dim_mass final : base_dimension<"M"> {} dim_mass;
* inline constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
* constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
* constexpr struct dim_mass final : base_dimension<"M"> {} dim_mass;
* constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
*
* inline constexpr struct length final : quantity_spec<dim_length> {} length;
* inline constexpr struct mass final : quantity_spec<dim_mass> {} mass;
* inline constexpr struct time final : quantity_spec<dim_time> {} time;
* constexpr struct length final : quantity_spec<dim_length> {} length;
* constexpr struct mass final : quantity_spec<dim_mass> {} mass;
* constexpr struct time final : quantity_spec<dim_time> {} time;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -280,12 +280,12 @@ struct quantity_spec<Self, Dim, Args...> : detail::quantity_spec_interface<Self>
* For example:
*
* @code{.cpp}
* inline constexpr struct area final : quantity_spec<pow<2>(length)> {} area;
* inline constexpr struct volume final : quantity_spec<pow<3>(length)> {} volume;
* inline constexpr struct velocity final : quantity_spec<position_vector / duration> {} velocity;
* inline constexpr struct speed final : quantity_spec<length / time> {} speed;
* inline constexpr struct force final : quantity_spec<mass * acceleration, quantity_character::vector> {} force;
* inline constexpr struct power final : quantity_spec<force * velocity, quantity_character::scalar> {} power;
* constexpr struct area final : quantity_spec<pow<2>(length)> {} area;
* constexpr struct volume final : quantity_spec<pow<3>(length)> {} volume;
* constexpr struct velocity final : quantity_spec<position_vector / duration> {} velocity;
* constexpr struct speed final : quantity_spec<length / time> {} speed;
* constexpr struct force final : quantity_spec<mass * acceleration, quantity_character::vector> {} force;
* constexpr struct power final : quantity_spec<force * velocity, quantity_character::scalar> {} power;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -335,10 +335,10 @@ struct propagate_equation<Q, true> {
* For example:
*
* @code{.cpp}
* inline constexpr struct width final : quantity_spec<length> {} width;
* inline constexpr struct height final : quantity_spec<length> {} height;
* inline constexpr struct diameter final : quantity_spec<width> {} diameter;
* inline constexpr struct position_vector final : quantity_spec<length, quantity_character::vector> {} position_vector;
* constexpr struct width final : quantity_spec<length> {} width;
* constexpr struct height final : quantity_spec<length> {} height;
* constexpr struct diameter final : quantity_spec<width> {} diameter;
* constexpr struct position_vector final : quantity_spec<length, quantity_character::vector> {} position_vector;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -396,10 +396,10 @@ struct quantity_spec<Self, QS, Args...> : detail::propagate_equation<QS>, detail
* For example:
*
* @code{.cpp}
* inline constexpr struct angular_measure final : quantity_spec<dimensionless, arc_length / radius, is_kind> {} angular_measure;
* inline constexpr struct velocity final : quantity_spec<speed, position_vector / duration> {} velocity;
* inline constexpr struct weight final : quantity_spec<force, mass * acceleration_of_free_fall> {} weight;
* inline constexpr struct kinetic_energy final : quantity_spec<mechanical_energy, mass * pow<2>(speed)> {} kinetic_energy;
* constexpr struct angular_measure final : quantity_spec<dimensionless, arc_length / radius, is_kind> {} angular_measure;
* constexpr struct velocity final : quantity_spec<speed, position_vector / duration> {} velocity;
* constexpr struct weight final : quantity_spec<force, mass * acceleration_of_free_fall> {} weight;
* constexpr struct kinetic_energy final : quantity_spec<mechanical_energy, mass * pow<2>(speed)> {} kinetic_energy;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -556,7 +556,7 @@ struct kind_of_<Q> final : quantity_spec<kind_of_<Q>, Q{}>::_base_type_ {
MP_UNITS_EXPORT template<detail::QuantitySpecWithNoSpecifiers auto Q>
requires detail::SameQuantitySpec<detail::get_kind_tree_root(Q), Q>
inline constexpr kind_of_<MP_UNITS_REMOVE_CONST(decltype(Q))> kind_of;
constexpr kind_of_<MP_UNITS_REMOVE_CONST(decltype(Q))> kind_of;
namespace detail {
@@ -53,10 +53,10 @@ struct kind_of_;
namespace detail {
template<typename T>
inline constexpr bool is_specialization_of_kind_of = false;
constexpr bool is_specialization_of_kind_of = false;
template<typename Q>
inline constexpr bool is_specialization_of_kind_of<kind_of_<Q>> = true;
constexpr bool is_specialization_of_kind_of<kind_of_<Q>> = true;
template<typename T>
concept QuantityKindSpec = is_specialization_of_kind_of<T>;
@@ -70,7 +70,7 @@ void to_base_specialization_of_quantity_spec(const volatile quantity_spec<T, Arg
#endif
template<typename T>
inline constexpr bool is_derived_from_specialization_of_quantity_spec =
constexpr bool is_derived_from_specialization_of_quantity_spec =
requires(T* t) { to_base_specialization_of_quantity_spec(t); };
/**
@@ -86,16 +86,16 @@ template<typename T>
struct is_dimensionless : std::false_type {};
template<typename T>
inline constexpr bool is_power_of_quantity_spec = requires {
constexpr bool is_power_of_quantity_spec = requires {
requires is_specialization_of_power<T> &&
(NamedQuantitySpec<typename T::factor> || is_dimensionless<typename T::factor>::value);
};
template<typename T>
inline constexpr bool is_per_of_quantity_specs = false;
constexpr bool is_per_of_quantity_specs = false;
template<typename... Ts>
inline constexpr bool is_per_of_quantity_specs<per<Ts...>> =
constexpr bool is_per_of_quantity_specs<per<Ts...>> =
(... && (NamedQuantitySpec<Ts> || is_dimensionless<Ts>::value || is_power_of_quantity_spec<Ts>));
template<typename T>
@@ -45,15 +45,15 @@ namespace mp_units {
* @code{.cpp}
* // hypothetical natural system of units for c=1
*
* inline constexpr struct second final : named_unit<"s"> {} second;
* inline constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
* inline constexpr struct gram final : named_unit<"g"> {} gram;
* inline constexpr auto kilogram = si::kilo<gram>;
* constexpr struct second final : named_unit<"s"> {} second;
* constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
* constexpr struct gram final : named_unit<"g"> {} gram;
* constexpr auto kilogram = si::kilo<gram>;
*
* inline constexpr struct time : system_reference<isq::time, second> {} time;
* inline constexpr struct length : system_reference<isq::length, second> {} length;
* inline constexpr struct speed : system_reference<isq::speed, second / second> {} speed;
* inline constexpr struct force : system_reference<isq::force, kilogram / second> {} force;
* constexpr struct time : system_reference<isq::time, second> {} time;
* constexpr struct length : system_reference<isq::length, second> {} length;
* constexpr struct speed : system_reference<isq::speed, second / second> {} speed;
* constexpr struct force : system_reference<isq::force, kilogram / second> {} force;
* @endcode
*
* @tparam Q quantity for which a unit is being assigned
+21 -21
View File
@@ -64,7 +64,7 @@ template<Magnitude auto M, Unit U>
struct scaled_unit_impl;
template<typename T>
inline constexpr bool is_specialization_of_scaled_unit = false;
constexpr bool is_specialization_of_scaled_unit = false;
template<DerivedUnitExpr... Expr>
struct derived_unit_impl;
@@ -241,7 +241,7 @@ struct scaled_unit final : detail::scaled_unit_impl<M, U> {};
namespace detail {
template<auto M, Unit U>
inline constexpr bool is_specialization_of_scaled_unit<scaled_unit<M, U>> = true;
constexpr bool is_specialization_of_scaled_unit<scaled_unit<M, U>> = true;
} // namespace detail
@@ -256,12 +256,12 @@ inline constexpr bool is_specialization_of_scaled_unit<scaled_unit<M, U>> = true
* For example:
*
* @code{.cpp}
* inline constexpr struct second final : named_unit<"s", kind_of<time>> {} second;
* inline constexpr struct metre final : named_unit<"m", kind_of<length> {} metre;
* inline constexpr struct hertz final : named_unit<"Hz", inverse(second), kind_of<frequency>> {} hertz;
* inline constexpr struct newton final : named_unit<"N", kilogram * metre / square(second)> {} newton;
* inline constexpr struct degree_Celsius final : named_unit<{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {}
* degree_Celsius; inline constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
* constexpr struct second final : named_unit<"s", kind_of<time>> {} second;
* constexpr struct metre final : named_unit<"m", kind_of<length> {} metre;
* constexpr struct hertz final : named_unit<"Hz", inverse(second), kind_of<frequency>> {} hertz;
* constexpr struct newton final : named_unit<"N", kilogram * metre / square(second)> {} newton;
* constexpr struct degree_Celsius final : named_unit<{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {}
* degree_Celsius; constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
* @endcode
*
* @note A common convention in this library is to assign the same name for a type and an object of this type.
@@ -386,9 +386,9 @@ struct named_unit<Symbol, U, QS, PO> : decltype(U)::_base_type_ {
* struct kilo_ : prefixed_unit<"k", mag_power<10, 3>, U> {};
*
* template<PrefixableUnit auto U>
* inline constexpr kilo_<U> kilo;
* constexpr kilo_<U> kilo;
*
* inline constexpr auto kilogram = si::kilo<gram>;
* constexpr auto kilogram = si::kilo<gram>;
* @endcode
*
* @tparam Symbol a prefix text to prepend to a unit symbol
@@ -468,7 +468,7 @@ struct derived_unit final : detail::derived_unit_impl<Expr...> {};
* Unit of a dimensionless quantity.
*/
// clang-format off
MP_UNITS_EXPORT inline constexpr struct one final : detail::derived_unit_impl<> {} one;
MP_UNITS_EXPORT constexpr struct one final : detail::derived_unit_impl<> {} one;
// clang-format on
namespace detail {
@@ -534,10 +534,10 @@ template<Unit T, typename... Expr>
}
template<typename T>
inline constexpr bool is_specialization_of_derived_unit = false;
constexpr bool is_specialization_of_derived_unit = false;
template<typename... Expr>
inline constexpr bool is_specialization_of_derived_unit<derived_unit<Expr...>> = true;
constexpr bool is_specialization_of_derived_unit<derived_unit<Expr...>> = true;
} // namespace detail
@@ -611,10 +611,10 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Unit U>
// common dimensionless units
// clang-format off
inline constexpr struct percent final : named_unit<"%", mag_ratio<1, 100> * one> {} percent;
inline constexpr struct per_mille final : named_unit<symbol_text{u8"‰", "%o"}, mag_ratio<1, 1000> * one> {} per_mille;
inline constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1, 1'000'000> * one> {} parts_per_million;
inline constexpr auto ppm = parts_per_million;
constexpr struct percent final : named_unit<"%", mag_ratio<1, 100> * one> {} percent;
constexpr struct per_mille final : named_unit<symbol_text{u8"‰", "%o"}, mag_ratio<1, 1000> * one> {} per_mille;
constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1, 1'000'000> * one> {} parts_per_million;
constexpr auto ppm = parts_per_million;
// clang-format on
@@ -675,14 +675,14 @@ template<Unit U1, Unit U2>
* be provided.
*/
template<Unit auto U>
inline constexpr bool space_before_unit_symbol = true;
constexpr bool space_before_unit_symbol = true;
template<>
inline constexpr bool space_before_unit_symbol<one> = false;
constexpr bool space_before_unit_symbol<one> = false;
template<>
inline constexpr bool space_before_unit_symbol<percent> = false;
constexpr bool space_before_unit_symbol<percent> = false;
template<>
inline constexpr bool space_before_unit_symbol<per_mille> = false;
constexpr bool space_before_unit_symbol<per_mille> = false;
// get_unit_symbol
@@ -59,7 +59,7 @@ template<symbol_text Symbol, auto... Args>
void to_base_specialization_of_named_unit(const volatile named_unit<Symbol, Args...>*);
template<typename T>
inline constexpr bool is_derived_from_specialization_of_named_unit =
constexpr bool is_derived_from_specialization_of_named_unit =
requires(T* t) { to_base_specialization_of_named_unit(t); };
} // namespace detail
@@ -73,14 +73,13 @@ concept PrefixableUnit = Unit<T> && detail::is_derived_from_specialization_of_na
namespace detail {
template<typename T>
inline constexpr bool is_power_of_unit =
requires { requires is_specialization_of_power<T> && Unit<typename T::factor>; };
constexpr bool is_power_of_unit = requires { requires is_specialization_of_power<T> && Unit<typename T::factor>; };
template<typename T>
inline constexpr bool is_per_of_units = false;
constexpr bool is_per_of_units = false;
template<typename... Ts>
inline constexpr bool is_per_of_units<per<Ts...>> = (... && (Unit<Ts> || is_power_of_unit<Ts>));
constexpr bool is_per_of_units<per<Ts...>> = (... && (Unit<Ts> || is_power_of_unit<Ts>));
template<typename T>
concept DerivedUnitExpr = Unit<T> || detail::is_power_of_unit<T> || detail::is_per_of_units<T>;
@@ -184,7 +184,7 @@ template<Unit auto ToU, Representation ToRep, typename QP>
* Implicit conversions between quantities of different types are allowed only for "safe"
* (e.g. non-truncating) conversion. In truncating cases an explicit cast have to be used.
*
* inline constexpr struct A : absolute_point_origin<A, isq::distance> A;
* constexpr struct A : absolute_point_origin<A, isq::distance> A;
*
* using ToQ = quantity<mm, int>;
* auto qp = value_cast<ToQ>(quantity_point{1.23 * m});
@@ -210,8 +210,8 @@ template<Quantity ToQ, typename QP>
* Implicit conversions between quantities of different types are allowed only for "safe"
* (e.g. non-truncating) conversion. In truncating cases an explicit cast have to be used.
*
* inline constexpr struct A : absolute_point_origin<A, isq::distance> A;
* inline constexpr struct B : relative_point_origin<A + 1*m> B;
* constexpr struct A : absolute_point_origin<A, isq::distance> A;
* constexpr struct B : relative_point_origin<A + 1*m> B;
*
* using ToQP = quantity_point<mm, B, int>;
* auto qp = value_cast<ToQP>(quantity_point{1.23 * m});