refactor: 💥 ! PrefixFamily support removed
It doesn't have much sense to restrict prefixes usage for most units and in many places we were wrong to do so already.
This commit is contained in:
1 parent
725d193122
commit
32b36fb670
66 files changed
+221
-268
No files matched your search
@@ -35,6 +35,13 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename>
|
||||
inline constexpr bool can_be_prefixed = false;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* @brief A common point for a hierarchy of units
|
||||
*
|
||||
@@ -69,39 +76,31 @@ struct same_unit_reference : is_same<typename U1::reference, typename U2::refere
|
||||
* @brief A named unit
|
||||
*
|
||||
* Defines a named (in most cases coherent) unit that is then passed to a dimension definition.
|
||||
* A named unit may be used by other units defined with the prefix of the same type, unless
|
||||
* no_prefix is provided for PF template parameter (in such a case it is impossible to define
|
||||
* a prefix unit based on this one).
|
||||
* A named unit may be composed with a prefix to create a prefixed_unit.
|
||||
*
|
||||
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
|
||||
* @tparam Symbol a short text representation of the unit
|
||||
* @tparam PF no_prefix or a type of prefix family
|
||||
*/
|
||||
template<typename Child, basic_symbol_text Symbol, PrefixFamily PF>
|
||||
template<typename Child, basic_symbol_text Symbol>
|
||||
struct named_unit : downcast_dispatch<Child, scaled_unit<ratio(1), Child>> {
|
||||
static constexpr auto symbol = Symbol;
|
||||
using prefix_family = PF;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A scaled unit
|
||||
* @brief A named scaled unit
|
||||
*
|
||||
* Defines a new named unit that is a scaled version of another unit. Such unit can be used by
|
||||
* other units defined with the prefix of the same type, unless no_prefix is provided for PF
|
||||
* template parameter (in such a case it is impossible to define a prefix unit based on this
|
||||
* one).
|
||||
* Defines a new named unit that is a scaled version of another unit.
|
||||
* A named unit may be composed with a prefix to create a prefixed_unit.
|
||||
*
|
||||
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
|
||||
* @tparam Symbol a short text representation of the unit
|
||||
* @tparam PF no_prefix or a type of prefix family
|
||||
* @tparam R a scale to apply to U
|
||||
* @tparam U a reference unit to scale
|
||||
*/
|
||||
template<typename Child, basic_symbol_text Symbol, PrefixFamily PF, ratio R, Unit U>
|
||||
template<typename Child, basic_symbol_text Symbol, ratio R, Unit U>
|
||||
requires UnitRatio<R>
|
||||
struct named_scaled_unit : downcast_dispatch<Child, scaled_unit<R * U::ratio, typename U::reference>> {
|
||||
static constexpr auto symbol = Symbol;
|
||||
using prefix_family = PF;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,10 +115,9 @@ struct named_scaled_unit : downcast_dispatch<Child, scaled_unit<R * U::ratio, ty
|
||||
* @tparam U reference unit
|
||||
*/
|
||||
template<typename Child, Prefix P, NamedUnit U>
|
||||
requires std::same_as<typename P::prefix_family, typename U::prefix_family>
|
||||
requires detail::can_be_prefixed<U>
|
||||
struct prefixed_unit : downcast_dispatch<Child, scaled_unit<P::ratio * U::ratio, typename U::reference>> {
|
||||
static constexpr auto symbol = P::symbol + U::symbol;
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -131,9 +129,7 @@ struct prefixed_unit : downcast_dispatch<Child, scaled_unit<P::ratio * U::ratio,
|
||||
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
|
||||
*/
|
||||
template<typename Child>
|
||||
struct derived_unit : downcast_dispatch<Child, scaled_unit<ratio(1), Child>> {
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
struct derived_unit : downcast_dispatch<Child, scaled_unit<ratio(1), Child>> {};
|
||||
|
||||
/**
|
||||
* @brief A unit with a deduced ratio and symbol
|
||||
@@ -152,7 +148,6 @@ template<typename Child, DerivedDimension Dim, NamedUnit U, NamedUnit... URest>
|
||||
requires detail::same_scaled_units<typename Dim::recipe, U, URest...>
|
||||
struct derived_deduced_unit : downcast_dispatch<Child, detail::derived_deduced_unit<Dim, U, URest...>> {
|
||||
static constexpr auto symbol = detail::derived_symbol_text<Dim, U, URest...>();
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -160,18 +155,14 @@ struct derived_deduced_unit : downcast_dispatch<Child, detail::derived_deduced_u
|
||||
*
|
||||
* Defines a named alias for another unit. It is useful to assign alternative names and symbols
|
||||
* to the already predefined units (i.e. "tonne" for "megagram").
|
||||
* An alias unit may be used by other units defined with the prefix of the same type, unless
|
||||
* no_prefix is provided for PF template parameter (in such a case it is impossible to define
|
||||
* a prefix unit based on this one).
|
||||
* A alias unit may be composed with a prefix to create a prefixed_alias_unit.
|
||||
*
|
||||
* @tparam U Unit for which an alias is defined
|
||||
* @tparam Symbol a short text representation of the unit
|
||||
* @tparam PF no_prefix or a type of prefix family
|
||||
*/
|
||||
template<Unit U, basic_symbol_text Symbol, PrefixFamily PF>
|
||||
template<Unit U, basic_symbol_text Symbol>
|
||||
struct alias_unit : U {
|
||||
static constexpr auto symbol = Symbol;
|
||||
using prefix_family = PF;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -188,16 +179,15 @@ struct alias_unit : U {
|
||||
// TODO gcc bug: 95015
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95015
|
||||
// template<Unit U, Prefix P, AliasUnit AU>
|
||||
// requires (!AliasUnit<U>) && std::same_as<typename P::prefix_family, typename AU::prefix_family>
|
||||
// requires (!AliasUnit<U>)
|
||||
template<Unit U, Prefix P, NamedUnit AU>
|
||||
requires std::same_as<typename P::prefix_family, typename AU::prefix_family>
|
||||
requires detail::can_be_prefixed<AU>
|
||||
struct prefixed_alias_unit : U {
|
||||
static constexpr auto symbol = P::symbol + AU::symbol;
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Unknown unit
|
||||
* @brief Unknown coherent unit
|
||||
*
|
||||
* Used as a coherent unit of an unknown dimension.
|
||||
*/
|
||||
@@ -205,17 +195,17 @@ struct unknown_coherent_unit : derived_unit<unknown_coherent_unit> {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename Child, basic_symbol_text Symbol, PrefixFamily PF>
|
||||
void is_named_impl(const volatile named_unit<Child, Symbol, PF>*);
|
||||
template<typename Child, basic_symbol_text Symbol>
|
||||
void is_named_impl(const volatile named_unit<Child, Symbol>*);
|
||||
|
||||
template<typename Child, basic_symbol_text Symbol, PrefixFamily PF, ratio R, Unit U>
|
||||
void is_named_impl(const volatile named_scaled_unit<Child, Symbol, PF, R, U>*);
|
||||
template<typename Child, basic_symbol_text Symbol, ratio R, typename U>
|
||||
void is_named_impl(const volatile named_scaled_unit<Child, Symbol, R, U>*);
|
||||
|
||||
template<typename Child, typename P, typename U>
|
||||
void is_named_impl(const volatile prefixed_unit<Child, P, U>*);
|
||||
|
||||
template<Unit U, basic_symbol_text Symbol, PrefixFamily PF>
|
||||
void is_named_impl(const volatile alias_unit<U, Symbol, PF>*);
|
||||
template<typename U, basic_symbol_text Symbol>
|
||||
void is_named_impl(const volatile alias_unit<U, Symbol>*);
|
||||
|
||||
template<typename U, typename P, typename AU>
|
||||
void is_named_impl(const volatile prefixed_alias_unit<U, P, AU>*);
|
||||
@@ -223,6 +213,18 @@ void is_named_impl(const volatile prefixed_alias_unit<U, P, AU>*);
|
||||
template<Unit U>
|
||||
inline constexpr bool is_named<U> = requires(U * u) { is_named_impl(u); };
|
||||
|
||||
template<typename Child, basic_symbol_text Symbol>
|
||||
void can_be_prefixed_impl(const volatile named_unit<Child, Symbol>*);
|
||||
|
||||
template<typename Child, basic_symbol_text Symbol, ratio R, typename U>
|
||||
void can_be_prefixed_impl(const volatile named_scaled_unit<Child, Symbol, R, U>*);
|
||||
|
||||
template<typename U, basic_symbol_text Symbol>
|
||||
void can_be_prefixed_impl(const volatile alias_unit<U, Symbol>*);
|
||||
|
||||
template<Unit U>
|
||||
inline constexpr bool can_be_prefixed<U> = requires(U * u) { can_be_prefixed_impl(u); };
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace units
|
||||
Reference in new issue
Block a user