Merge branch 'master' of github.com:mpusz/units

This commit is contained in:
Mateusz Pusz
2023-06-19 14:02:39 +02:00
6 changed files with 30 additions and 26 deletions

View File

@ -350,8 +350,8 @@ private:
f.specs.unit.separator = mp_units::unit_symbol_separator::space;
else {
if (f.specs.unit.encoding == mp_units::text_encoding::ascii)
throw UNITS_STD_FMT::format_error("dot unit separator allowed only for Unicode encoding");
f.specs.unit.separator = mp_units::unit_symbol_separator::dot;
throw UNITS_STD_FMT::format_error("half_high_dot unit separator allowed only for Unicode encoding");
f.specs.unit.separator = mp_units::unit_symbol_separator::half_high_dot;
}
}

View File

@ -66,11 +66,12 @@ concept CastableNumber = CommonTypeWith<T, std::intmax_t> && ScalableNumber<std:
// TODO Fix it according to sudo_cast implementation
template<typename T>
concept Scalable = CastableNumber<T> ||
(requires { typename T::value_type; } && CastableNumber<typename T::value_type> &&
ScalableNumber<T, std::common_type_t<typename T::value_type, std::intmax_t>>) ||
(requires { typename T::element_type; } && CastableNumber<typename T::element_type> &&
ScalableNumber<T, std::common_type_t<typename T::element_type, std::intmax_t>>);
concept Scalable =
CastableNumber<T> ||
(requires { typename T::value_type; } && CastableNumber<typename T::value_type> &&
ScalableNumber<T, std::common_type_t<typename T::value_type, std::intmax_t>>) ||
(requires { typename T::element_type; } && CastableNumber<std::remove_reference_t<typename T::element_type>> &&
ScalableNumber<T, std::common_type_t<std::remove_reference_t<typename T::element_type>, std::intmax_t>>);
} // namespace detail

View File

@ -42,12 +42,14 @@ template<typename Rep>
inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
template<typename Rep>
requires requires { typename Rep::value_type; }
inline constexpr bool treat_as_floating_point<Rep> = treat_as_floating_point<typename Rep::value_type>;
template<typename Rep>
requires requires { typename Rep::element_type; }
inline constexpr bool treat_as_floating_point<Rep> = treat_as_floating_point<typename Rep::element_type>;
requires requires { typename Rep::value_type; } || requires { typename Rep::element_type; }
inline constexpr bool treat_as_floating_point<Rep> = requires {
typename Rep::value_type;
requires treat_as_floating_point<typename Rep::value_type>;
} || requires {
typename Rep::element_type;
requires treat_as_floating_point<std::remove_reference_t<typename Rep::element_type>>;
};
/**
* @brief Specifies a type to have a scalar character

View File

@ -648,8 +648,8 @@ enum class unit_symbol_solidus {
};
enum class unit_symbol_separator {
space, // kg m²/s²
dot, // kg⋅m²/s² (valid only for unicode encoding)
space, // kg m²/s²
half_high_dot, // kg⋅m²/s² (valid only for unicode encoding)
default_separator = space
};
@ -681,9 +681,10 @@ constexpr Out copy(const basic_symbol_text<UnicodeCharT, N, M>& txt, text_encodi
template<typename CharT, std::output_iterator<CharT> Out>
constexpr Out print_separator(Out out, unit_symbol_formatting fmt)
{
if (fmt.separator == unit_symbol_separator::dot) {
if (fmt.separator == unit_symbol_separator::half_high_dot) {
if (fmt.encoding != text_encoding::unicode)
throw std::invalid_argument("'unit_symbol_separator::dot' can be only used with 'text_encoding::unicode'");
throw std::invalid_argument(
"'unit_symbol_separator::half_high_dot' can be only used with 'text_encoding::unicode'");
copy(std::string_view(""), out);
} else {
*out++ = ' ';

View File

@ -455,11 +455,11 @@ TEST_CASE("more then one modifier of the same kind should throw", "[text][fmt][e
}
}
TEST_CASE("dot separator requested for ASCII encoding should throw", "[text][fmt][exception]")
TEST_CASE("half_high_dot separator requested for ASCII encoding should throw", "[text][fmt][exception]")
{
REQUIRE_THROWS_MATCHES(UNITS_STD_FMT::vformat("{:%dAaq}", UNITS_STD_FMT::make_format_args(1 * isq::length[m])),
UNITS_STD_FMT::format_error,
Catch::Matchers::Message("dot unit separator allowed only for Unicode encoding"));
Catch::Matchers::Message("half_high_dot unit separator allowed only for Unicode encoding"));
}
TEST_CASE("%q and %Q can be put anywhere in a format string", "[text][fmt]")

View File

@ -121,7 +121,7 @@ static_assert(unit_symbol(square(metre), {.encoding = ascii}) == "m^2");
static_assert(unit_symbol(cubic(metre)) == "");
static_assert(unit_symbol(cubic(metre), {.encoding = ascii}) == "m^3");
static_assert(unit_symbol(kilo<metre> * metre) == "km m");
static_assert(unit_symbol(kilo<metre> * metre, {.separator = dot}) == "km⋅m");
static_assert(unit_symbol(kilo<metre> * metre, {.separator = half_high_dot}) == "km⋅m");
static_assert(unit_symbol(metre / metre) == "");
static_assert(unit_symbol(kilo<metre> / metre) == "km/m");
static_assert(unit_symbol(kilo<metre> / metre, {.solidus = never}) == "km m⁻¹");
@ -130,30 +130,30 @@ static_assert(unit_symbol(metre / second) == "m/s");
static_assert(unit_symbol(metre / second, {.solidus = always}) == "m/s");
static_assert(unit_symbol(metre / second, {.solidus = never}) == "m s⁻¹");
static_assert(unit_symbol(metre / second, {.encoding = ascii, .solidus = never}) == "m s^-1");
static_assert(unit_symbol(metre / second, {.solidus = never, .separator = dot}) == "m⋅s⁻¹");
static_assert(unit_symbol(metre / second, {.solidus = never, .separator = half_high_dot}) == "m⋅s⁻¹");
static_assert(unit_symbol(metre / square(second)) == "m/s²");
static_assert(unit_symbol(metre / square(second), {.encoding = ascii}) == "m/s^2");
static_assert(unit_symbol(metre / square(second), {.solidus = always}) == "m/s²");
static_assert(unit_symbol(metre / square(second), {.encoding = ascii, .solidus = always}) == "m/s^2");
static_assert(unit_symbol(metre / square(second), {.solidus = never}) == "m s⁻²");
static_assert(unit_symbol(metre / square(second), {.encoding = ascii, .solidus = never}) == "m s^-2");
static_assert(unit_symbol(metre / square(second), {.solidus = never, .separator = dot}) == "m⋅s⁻²");
static_assert(unit_symbol(metre / square(second), {.solidus = never, .separator = half_high_dot}) == "m⋅s⁻²");
static_assert(unit_symbol(kilogram * metre / square(second)) == "kg m/s²");
static_assert(unit_symbol(kilogram * metre / square(second), {.separator = dot}) == "kg⋅m/s²");
static_assert(unit_symbol(kilogram * metre / square(second), {.separator = half_high_dot}) == "kg⋅m/s²");
static_assert(unit_symbol(kilogram * metre / square(second), {.encoding = ascii}) == "kg m/s^2");
static_assert(unit_symbol(kilogram * metre / square(second), {.solidus = always}) == "kg m/s²");
static_assert(unit_symbol(kilogram * metre / square(second), {.encoding = ascii, .solidus = always}) == "kg m/s^2");
static_assert(unit_symbol(kilogram * metre / square(second), {.solidus = never}) == "kg m s⁻²");
static_assert(unit_symbol(kilogram * metre / square(second), {.encoding = ascii, .solidus = never}) == "kg m s^-2");
static_assert(unit_symbol(kilogram * metre / square(second), {.solidus = never, .separator = dot}) == "kg⋅m⋅s⁻²");
static_assert(unit_symbol(kilogram * metre / square(second), {.solidus = never, .separator = half_high_dot}) == "kg⋅m⋅s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second)) == "kg m⁻¹ s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second), {.separator = dot}) == "kg⋅m⁻¹⋅s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second), {.separator = half_high_dot}) == "kg⋅m⁻¹⋅s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second), {.encoding = ascii}) == "kg m^-1 s^-2");
static_assert(unit_symbol(kilogram / metre / square(second), {.solidus = always}) == "kg/(m s²)");
static_assert(unit_symbol(kilogram / metre / square(second), {.encoding = ascii, .solidus = always}) == "kg/(m s^2)");
static_assert(unit_symbol(kilogram / metre / square(second), {.solidus = never}) == "kg m⁻¹ s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second), {.encoding = ascii, .solidus = never}) == "kg m^-1 s^-2");
static_assert(unit_symbol(kilogram / metre / square(second), {.solidus = never, .separator = dot}) == "kg⋅m⁻¹⋅s⁻²");
static_assert(unit_symbol(kilogram / metre / square(second), {.solidus = never, .separator = half_high_dot}) == "kg⋅m⁻¹⋅s⁻²");
static_assert(unit_symbol(pow<123>(metre)) == "m¹²³");
static_assert(unit_symbol(pow<1, 2>(metre)) == "m^(1/2)");
static_assert(unit_symbol(pow<3, 5>(metre)) == "m^(3/5)");