From 1a2023a9a24786a0492d5217865a8122ddb19731 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 7 May 2024 13:37:44 -0400 Subject: [PATCH] xo-unit: + .is_natural() method in natural_unit, scaled_unit --- include/xo/unit/natural_unit.hpp | 3 +++ include/xo/unit/quantity.hpp | 1 + include/xo/unit/scaled_unit.hpp | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/xo/unit/natural_unit.hpp b/include/xo/unit/natural_unit.hpp index 7dfe3447..bebf62c7 100644 --- a/include/xo/unit/natural_unit.hpp +++ b/include/xo/unit/natural_unit.hpp @@ -70,6 +70,9 @@ namespace xo { return detail::nu_maker::make_nu(bpu(bu, power)); } + /** always true. @see scaled_unit::is_natural **/ + constexpr bool is_natural() const { return true; } + constexpr std::size_t n_bpu() const { return n_bpu_; } constexpr bool is_dimensionless() const { return n_bpu_ == 0; } diff --git a/include/xo/unit/quantity.hpp b/include/xo/unit/quantity.hpp index 9b368263..a186b48b 100644 --- a/include/xo/unit/quantity.hpp +++ b/include/xo/unit/quantity.hpp @@ -32,6 +32,7 @@ namespace xo { template < auto NaturalUnit, typename Repr = double> + requires (NaturalUnit.is_natural()) class quantity { public: /** @defgroup quantity-type-traits quantity type traits **/ diff --git a/include/xo/unit/scaled_unit.hpp b/include/xo/unit/scaled_unit.hpp index ac6fd60a..ecdc1719 100644 --- a/include/xo/unit/scaled_unit.hpp +++ b/include/xo/unit/scaled_unit.hpp @@ -29,7 +29,10 @@ namespace xo { 1.0 / outer_scale_sq_); } - /** @brief true iff scaled unit can be faithfully represented by a @ref natural_unit **/ + /** @brief true iff scaled unit can be faithfully represented by a @ref natural_unit + * + * @see natural_unit::is_natural + **/ constexpr bool is_natural() const { return (outer_scale_factor_ == OuterScale(1) && (outer_scale_sq_ == 1.0)); }