From c582801d842c058e87a2cca537707508c6a4e33e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 1 Dec 2024 14:08:05 +0100 Subject: [PATCH] feat: `ScalableWith` isolated from `Scalar` and added as a constraint to `Complex` and `Vector` --- .../mp-units/framework/representation_concepts.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp-units/framework/representation_concepts.h b/src/core/include/mp-units/framework/representation_concepts.h index 9bcb0431..6d5f81e1 100644 --- a/src/core/include/mp-units/framework/representation_concepts.h +++ b/src/core/include/mp-units/framework/representation_concepts.h @@ -74,14 +74,19 @@ namespace detail { template concept WeaklyRegular = std::copyable && std::equality_comparable; +template +concept ScalableWith = WeaklyRegular && requires(T v, S s) { + { v* s / s } -> std::common_with; + { s* v / s } -> std::common_with; + { v / s* s } -> std::common_with; +}; + template -concept Scalar = (!disable_scalar) && WeaklyRegular && requires(T a, T b, T c) { +concept Scalar = (!disable_scalar) && WeaklyRegular && requires(T a, T b) { { -a } -> std::common_with; { a + b } -> std::common_with; { a - b } -> std::common_with; - { a* b / c } -> std::common_with; - { a / b* c } -> std::common_with; -}; +} && ScalableWith; namespace real_impl { @@ -177,6 +182,7 @@ concept Complex = (!disable_complex) && WeaklyRegular && requires(T a, T b ::mp_units::real(a); ::mp_units::imag(a); ::mp_units::modulus(a); + requires ScalableWith; requires std::constructible_from; }; @@ -234,6 +240,7 @@ concept Vector = (!disable_vector) && WeaklyRegular && requires(T a, T b) { a + b } -> std::common_with; { a - b } -> std::common_with; ::mp_units::magnitude(a); + requires ScalableWith; // TODO should we also check for the below (e.g., when `size() > 1` or `2`) // { zero_vector() } -> Vector; // { unit_vector(a) } -> Vector;