From b4c3ba4dda9409887d04a100524d1dac899b9914 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 5 Apr 2024 01:37:06 -0400 Subject: [PATCH] xo-unit: + numeric_concept + unit_concept --- include/xo/unit/numeric_concept.hpp | 38 +++++++++++++++++++++ include/xo/unit/quantity_concept.hpp | 3 +- include/xo/unit/unit_concept.hpp | 49 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 include/xo/unit/numeric_concept.hpp create mode 100644 include/xo/unit/unit_concept.hpp diff --git a/include/xo/unit/numeric_concept.hpp b/include/xo/unit/numeric_concept.hpp new file mode 100644 index 00000000..720099a3 --- /dev/null +++ b/include/xo/unit/numeric_concept.hpp @@ -0,0 +1,38 @@ +/* @file numeric_concept.hpp */ + +#pragma once + +#include + +namespace xo { + namespace unit { + /** @concept numeric_concept + * @brief Concept for values that participate in arithmetic operations (+,-,*,/) and comparisons + * + * Intended to include at least: + * - built-in integral and floating-point types + * - boost::rational + * - std::complex + * - xo::unit::quantity + * + * This implies we don't require T to be totally ordered, + * and don't require (<,<=,>=,>) operators. + * + * Intend numeric_concept to apply to types suitable for + * xo::unit::quantity::repr_type. + **/ + template + concept numeric_concept = requires(T x, U y) + { + { -x }; + { x - y }; + { x + y }; + { x * y }; + { x / y }; + { x == y }; + { x != y }; + }; + } /*namespace unit*/ +} /*namespace xo*/ + +/* end numeric_concept.hpp */ diff --git a/include/xo/unit/quantity_concept.hpp b/include/xo/unit/quantity_concept.hpp index 09d33446..1235a277 100644 --- a/include/xo/unit/quantity_concept.hpp +++ b/include/xo/unit/quantity_concept.hpp @@ -2,7 +2,8 @@ #pragma once -#include +#include "unit_concept.hpp" +#include "numeric_concept.hpp" namespace xo { namespace unit { diff --git a/include/xo/unit/unit_concept.hpp b/include/xo/unit/unit_concept.hpp new file mode 100644 index 00000000..8c5fe59c --- /dev/null +++ b/include/xo/unit/unit_concept.hpp @@ -0,0 +1,49 @@ +/* @file unit_concept.hpp */ + +#pragma once + +#include "dimension_concept.hpp" + +namespace xo { + namespace unit { + /** @brief concept for a Unit type, suitable for use with the quantity template + * + * Example: + * @code + * using namespace xo::unit; + * static_assert(unit_concept); + * @endcode + **/ + template + concept unit_concept = requires(Unit unit) + { + typename Unit::scalefactor_type; + typename Unit::dim_type; + typename Unit::canon_type; + } + && (ratio_concept + && bpu_list_concept + && bpu_list_concept); + + + /** @brief concept for a Unit type, that contains exactly one basis dimension + * + * Example: + * @code + * using namespace xo::unit + * static_assert(basis_unit_concept); + * @endcode + **/ + template + concept basis_unit_concept = requires(Unit unit) + { + typename Unit::dim_type; + typename Unit::dim_type::rest_type; + } + && (std::same_as) + && (unit_concept); + } /*namespace unit*/ +} /*namespace xo*/ + + +/* end unit_concept.hpp */