feat: PrefixableUnit concept introduced

This commit is contained in:
Mateusz Pusz
2022-10-19 13:15:02 +02:00
parent f156bc4c71
commit ec1dace1f9
3 changed files with 53 additions and 51 deletions

View File

@@ -34,16 +34,16 @@ inline constexpr struct activity : system_reference<activity_dim, si::becquerel>
// check for invalid prefixes
template<Unit auto V1>
concept can_not_be_prefixed = !requires { typename si::milli_<V1>; };
template<template<auto U> typename prefix, Unit auto V1>
concept can_not_be_prefixed = !requires { typename prefix<V1>; };
static_assert(can_not_be_prefixed<si::degree_Celsius>);
static_assert(can_not_be_prefixed<si::minute>);
static_assert(can_not_be_prefixed<si::hour>);
static_assert(can_not_be_prefixed<si::day>);
static_assert(can_not_be_prefixed<si::kilogram>);
static_assert(can_not_be_prefixed<si::hectare>);
static_assert(can_not_be_prefixed<si::metre / si::second>);
static_assert(can_not_be_prefixed<si::milli_, si::degree_Celsius>);
static_assert(can_not_be_prefixed<si::milli_, si::minute>);
static_assert(can_not_be_prefixed<si::milli_, si::hour>);
static_assert(can_not_be_prefixed<si::milli_, si::day>);
static_assert(can_not_be_prefixed<si::milli_, si::kilogram>);
static_assert(can_not_be_prefixed<si::milli_, si::hectare>);
static_assert(can_not_be_prefixed<si::milli_, si::metre / si::second>);
// Named quantity/dimension and unit
static_assert(

View File

@@ -92,6 +92,9 @@ concept NamedUnit = Unit<T> && requires(T* t) { detail::to_base_specialization_o
template<Unit auto V>
inline constexpr bool unit_can_be_prefixed = NamedUnit<std::remove_const_t<decltype(V)>>;
template<typename T>
concept PrefixableUnit = NamedUnit<T> && unit_can_be_prefixed<T{}>;
/**
* @brief A prefixed unit
*
@@ -103,8 +106,7 @@ inline constexpr bool unit_can_be_prefixed = NamedUnit<std::remove_const_t<declt
* @tparam P prefix to be appied to the coherent_unit unit
* @tparam U coherent_unit unit
*/
template<basic_symbol_text Symbol, Magnitude auto M, NamedUnit auto U>
requires unit_can_be_prefixed<U>
template<basic_symbol_text Symbol, Magnitude auto M, PrefixableUnit auto U>
struct prefixed_unit : std::remove_const_t<decltype(M * U)> {
static constexpr auto symbol = Symbol + U.symbol;
};

View File

@@ -26,86 +26,86 @@
namespace units::si {
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct yocto_ : prefixed_unit<"y", mag_power<10, -24>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct zepto_ : prefixed_unit<"z", mag_power<10, -21>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct atto_ : prefixed_unit<"a", mag_power<10, -18>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct femto_ : prefixed_unit<"f", mag_power<10, -15>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct pico_ : prefixed_unit<"p", mag_power<10, -12>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct nano_ : prefixed_unit<"n", mag_power<10, -9>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct micro_ : prefixed_unit<basic_symbol_text{"\u00b5", "u"}, mag_power<10, -6>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct milli_ : prefixed_unit<"m", mag_power<10, -3>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct centi_ : prefixed_unit<"c", mag_power<10, -2>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct deci_ : prefixed_unit<"d", mag_power<10, -1>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct deca_ : prefixed_unit<"da", mag_power<10, 1>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct hecto_ : prefixed_unit<"h", mag_power<10, 2>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct kilo_ : prefixed_unit<"k", mag_power<10, 3>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct mega_ : prefixed_unit<"M", mag_power<10, 6>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct giga_ : prefixed_unit<"G", mag_power<10, 9>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct tera_ : prefixed_unit<"T", mag_power<10, 12>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct peta_ : prefixed_unit<"P", mag_power<10, 15>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct exa_ : prefixed_unit<"E", mag_power<10, 18>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct zetta_ : prefixed_unit<"Z", mag_power<10, 21>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
struct yotta_ : prefixed_unit<"Y", mag_power<10, 24>, U> {};
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr yocto_<U> yocto;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr zepto_<U> zepto;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr atto_<U> atto;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr femto_<U> femto;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr pico_<U> pico;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr nano_<U> nano;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr micro_<U> micro;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr milli_<U> milli;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr centi_<U> centi;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr deci_<U> deci;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr deca_<U> deca;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr hecto_<U> hecto;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr kilo_<U> kilo;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr mega_<U> mega;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr giga_<U> giga;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr tera_<U> tera;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr peta_<U> peta;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr exa_<U> exa;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr zetta_<U> zetta;
template<NamedUnit auto U>
template<PrefixableUnit auto U>
inline constexpr yotta_<U> yotta;
} // namespace units::si