mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
fix: prefixed_alias_unit
constraints fixed
This commit is contained in:
@@ -45,6 +45,11 @@ Concepts
|
||||
A concept matching all unit types that have an atomic text symbol that can be used to aggregate it with
|
||||
other named units to form a final symbol of a derived unit.
|
||||
|
||||
.. concept:: template<typename T> AliasUnit
|
||||
|
||||
A concept matching all alias unit types in the library. Satisfied by all unit types derived
|
||||
from the instantiation of :class:`alias_unit`.
|
||||
|
||||
.. concept:: template<typename U, typename D> UnitOf
|
||||
|
||||
A concept matching only units of a specified dimension. Satisfied by all unit types that
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <units/bits/external/type_traits.h>
|
||||
#include <units/customization_points.h>
|
||||
#include <units/magnitude.h>
|
||||
#include <units/symbol_text.h>
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
#include <cstdint>
|
||||
@@ -86,6 +87,20 @@ inline constexpr bool is_named = false;
|
||||
template<typename T>
|
||||
concept NamedUnit = Unit<T> && detail::is_named<T>;
|
||||
|
||||
template<Unit U, basic_symbol_text Symbol>
|
||||
struct alias_unit;
|
||||
|
||||
// TODO: Remove when P1985 accepted
|
||||
namespace detail {
|
||||
|
||||
template<Unit U, basic_symbol_text Symbol>
|
||||
void to_base_alias_unit(const volatile alias_unit<U, Symbol>*);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
concept AliasUnit = requires(T* t) { detail::to_base_alias_unit(t); };
|
||||
|
||||
// BaseDimension
|
||||
template<basic_fixed_string Symbol, NamedUnit U>
|
||||
struct base_dimension;
|
||||
|
@@ -58,8 +58,10 @@ inline constexpr bool can_be_prefixed = false;
|
||||
*
|
||||
* @tparam M a Magnitude representing the (relative) size of this unit
|
||||
* @tparam U a unit to use as a reference for this dimension
|
||||
*
|
||||
* @note U cannot be constrained with Unit as for some specializations (i.e. named_unit)
|
||||
* it gets the incomplete child's type with the CRTP idiom.
|
||||
*/
|
||||
// TODO Replace `typename` with `Unit`
|
||||
template<Magnitude auto M, typename U>
|
||||
struct scaled_unit : downcast_base<scaled_unit<M, U>> {
|
||||
static constexpr UNITS_MSVC_WORKAROUND(Magnitude) auto mag = M;
|
||||
@@ -175,12 +177,8 @@ struct alias_unit : U {
|
||||
* @tparam P prefix to be appied to the reference unit
|
||||
* @tparam AU reference alias unit
|
||||
*/
|
||||
// TODO gcc bug: 95015
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95015
|
||||
// template<Unit U, Prefix P, AliasUnit AU>
|
||||
// requires (!AliasUnit<U>)
|
||||
template<Unit U, Prefix P, NamedUnit AU>
|
||||
requires detail::can_be_prefixed<AU>
|
||||
template<Unit U, Prefix P, AliasUnit AU>
|
||||
requires(!AliasUnit<U>)
|
||||
struct prefixed_alias_unit : U {
|
||||
static constexpr auto symbol = P::symbol + AU::symbol;
|
||||
};
|
||||
|
Reference in New Issue
Block a user