mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
fix: some fixes revealed during clang compilation
This commit is contained in:
@@ -48,7 +48,7 @@ void si_example()
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
constexpr auto GeV = si::giga<si::electronvolt>;
|
||||
constexpr QuantityOf<isq::speed> auto c = 1. * si::si2019::speed_of_light_in_vacuum;
|
||||
constexpr auto c2 = pow<2>(c);
|
||||
auto c2 = pow<2>(c);
|
||||
|
||||
const auto p1 = isq::momentum(4. * GeV / c);
|
||||
const QuantityOf<isq::mass> auto m1 = 3. * GeV / c2;
|
||||
|
@@ -46,11 +46,12 @@ namespace mp_units {
|
||||
* @tparam ToQS a quantity specification to use for a target quantity
|
||||
*/
|
||||
template<QuantitySpec auto ToQS, typename Q>
|
||||
requires Quantity<std::remove_cvref_t<Q>> && (castable(Q::quantity_spec, ToQS))
|
||||
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
|
||||
requires Quantity<std::remove_cvref_t<Q>> && (castable(q.quantity_spec, ToQS))
|
||||
{
|
||||
if constexpr (detail::QuantityKindSpec<std::remove_const_t<decltype(ToQS)>> &&
|
||||
AssociatedUnit<std::remove_const_t<decltype(q.unit)>>)
|
||||
AssociatedUnit<std::remove_const_t<decltype(Q::unit)>>)
|
||||
return make_quantity<q.unit>(std::forward<Q>(q).value());
|
||||
else
|
||||
return make_quantity<reference<ToQS, q.unit>{}>(std::forward<Q>(q).value());
|
||||
|
@@ -62,7 +62,6 @@ inline constexpr bool is_derived_from_specialization_of_quantity_spec =
|
||||
|
||||
#ifdef __cpp_explicit_this_parameter
|
||||
template<BaseDimension auto Dim, auto... Args>
|
||||
template<auto... Args>
|
||||
void to_base_specialization_of_base_quantity_spec(const volatile quantity_spec<Dim, Args...>*);
|
||||
#else
|
||||
template<typename Self, BaseDimension auto Dim, auto... Args>
|
||||
|
@@ -448,7 +448,7 @@ template<Unit Lhs, Unit Rhs>
|
||||
return detail::expr_divide<derived_unit, struct one, detail::type_list_of_unit_less>(lhs, rhs);
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval Unit auto operator/(int value, Unit auto u)
|
||||
[[nodiscard]] MP_UNITS_CONSTEVAL Unit auto operator/(int value, Unit auto u)
|
||||
{
|
||||
gsl_Expects(value == 1);
|
||||
return detail::expr_invert<derived_unit, struct one>(u);
|
||||
@@ -720,7 +720,7 @@ constexpr Out unit_symbol_impl(Out out, const scaled_unit<M, U>& u, unit_symbol_
|
||||
constexpr auto mag_txt = magnitude_text<M>();
|
||||
out = copy<CharT>(mag_txt, fmt.encoding, out);
|
||||
|
||||
if constexpr (has_unit_symbol(u.reference_unit)) {
|
||||
if constexpr (has_unit_symbol(scaled_unit<M, U>::reference_unit)) {
|
||||
*out++ = ' ';
|
||||
return unit_symbol_impl<CharT>(out, u.reference_unit, fmt, negative_power);
|
||||
} else {
|
||||
|
@@ -48,9 +48,11 @@ constexpr auto pow_res = pow<2>(amplitude_spectral_density[si::volt / sqrt(si::h
|
||||
static_assert(implicitly_convertible(power_spectral_density, get_quantity_spec(pow_res)));
|
||||
static_assert(square(si::volt) / si::hertz == get_unit(pow_res));
|
||||
|
||||
#if __cpp_lib_constexpr_cmath || MP_UNITS_COMP_GCC
|
||||
static_assert(sqrt(16 * power_spectral_density[square(si::volt) / si::hertz]) ==
|
||||
4 * amplitude_spectral_density[si::volt / sqrt(si::hertz)]);
|
||||
static_assert(16 * power_spectral_density[square(si::volt) / si::hertz] ==
|
||||
pow<2>(4 * amplitude_spectral_density[si::volt / sqrt(si::hertz)]));
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
@@ -63,7 +63,7 @@ static_assert(1 * isq::length[nmi] == 1852 * isq::length[si::metre]);
|
||||
static_assert(1 * isq::speed[kn] == isq::length(1 * nmi) / isq::time(1 * si::hour));
|
||||
|
||||
// Force
|
||||
static_assert(1 * isq::force[pdl] == isq::mass(1 * lb) * isq::length(1 * ft) / pow<2>(isq::time(1 * si::second)));
|
||||
static_assert(1 * isq::force[pdl] == isq::mass(1 * lb) * isq::length(1 * ft) / (isq::time(1 * si::second) * isq::time(1 * si::second)));
|
||||
static_assert(1 * isq::force[lbf] == isq::mass(1 * lb) * (1 * si::standard_gravity));
|
||||
static_assert(1 * isq::force[kip] == 1000 * isq::force[lbf]);
|
||||
|
||||
|
@@ -26,6 +26,8 @@
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <optional>
|
||||
|
||||
#if __cpp_lib_constexpr_cmath || MP_UNITS_COMP_GCC
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace mp_units;
|
||||
@@ -80,7 +82,6 @@ static_assert(compare(pow<1, 4>(4. * isq::area[square(km)]), sqrt(2.) * pow<1, 4
|
||||
static_assert(compare(pow<1, 4>(4. * isq::area[square(ft)]), sqrt(2.) * pow<1, 4>(isq::area)[sqrt(ft)],
|
||||
std::sqrt(2.) * sqrt(isq::length[ft])));
|
||||
|
||||
// #if __cpp_lib_constexpr_cmath
|
||||
// floor
|
||||
// integral types
|
||||
static_assert(compare(floor<si::second>(1 * s), 1 * s));
|
||||
@@ -200,6 +201,6 @@ static_assert(compare(round<si::second>(-1499. * isq::time[ms]), -1. * isq::time
|
||||
static_assert(compare(round<si::second>(-1500. * isq::time[ms]), -2. * isq::time[s]));
|
||||
static_assert(compare(round<si::second>(-1999. * isq::time[ms]), -2. * isq::time[s]));
|
||||
|
||||
// #endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
@@ -33,7 +33,7 @@ using namespace mp_units;
|
||||
using namespace mp_units::natural::unit_symbols;
|
||||
|
||||
static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV]) == 1 * natural::speed[one]);
|
||||
static_assert(1 * natural::length[1 / GeV] / pow<2>(1 * natural::time[1 / GeV]) == 1 * natural::acceleration[GeV]);
|
||||
static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV] * (1 * natural::time[1 / GeV])) == 1 * natural::acceleration[GeV]);
|
||||
static_assert(1 * natural::mass[GeV] * (1 * natural::velocity[one]) == 1 * natural::momentum[GeV]);
|
||||
static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) == 1 * natural::force[GeV2]);
|
||||
static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) * (1 * natural::length[1 / GeV]) ==
|
||||
|
@@ -693,7 +693,7 @@ static_assert(invalid_arithmetic(5 * activity[Bq], 10 / (2 * isq::time[s]), 5 *
|
||||
static_assert(1 * si::si2019::speed_of_light_in_vacuum + 10 * isq::speed[m / s] == 299'792'468 * isq::speed[m / s]);
|
||||
|
||||
// Implicit conversions allowed between quantities of `convertible` references
|
||||
constexpr quantity<isq::speed[km / h]> speed = 120 * isq::length[km] / (2 * isq::time[h]);
|
||||
[[maybe_unused]] constexpr quantity<isq::speed[km / h]> speed = 120 * isq::length[km] / (2 * isq::time[h]);
|
||||
|
||||
// dimensionless
|
||||
static_assert((3 * one *= 2 * one) == 6 * one);
|
||||
|
@@ -56,8 +56,8 @@ static_assert(1 * Rm == 1'000'000'000'000'000'000 * Gm);
|
||||
static_assert(1 * Qm == 1'000'000'000'000'000'000 * Tm);
|
||||
|
||||
// check for invalid prefixes
|
||||
template<template<auto U> typename prefix, Unit auto V1>
|
||||
concept can_not_be_prefixed = !requires { typename prefix<V1>; };
|
||||
template<template<auto U> typename prefix, auto V1>
|
||||
concept can_not_be_prefixed = Unit<std::remove_const_t<decltype(V1)>> && !requires { typename prefix<V1>; };
|
||||
|
||||
static_assert(can_not_be_prefixed<si::milli_, si::degree_Celsius>);
|
||||
static_assert(can_not_be_prefixed<si::milli_, si::minute>);
|
||||
|
Reference in New Issue
Block a user