From 34214f571ddae67f7592eaf6a6f830a06433dd72 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 5 Apr 2024 01:38:36 -0400 Subject: [PATCH] xo-unit: + di_replace_basis_scale --- include/xo/unit/dimension_impl.hpp | 44 +++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/include/xo/unit/dimension_impl.hpp b/include/xo/unit/dimension_impl.hpp index d51c655c..d241f9ec 100644 --- a/include/xo/unit/dimension_impl.hpp +++ b/include/xo/unit/dimension_impl.hpp @@ -180,7 +180,7 @@ namespace xo { using dim_type = typename Dim::rest_type; }; - // ----- bpu_list ----- + // ----- bpu_node ----- /** Represents the cartesian product of a list of 'native basis power units'; * represents something with dimensions @@ -234,6 +234,48 @@ namespace xo { static constexpr std::uint32_t n_dimension = 1; }; + // ----- di_replace_basis_scale ----- + + /** + * @brief Replace BpuList member with matching BasisDim, preserving everything except (inner) scalefactor + **/ + template + struct di_replace_basis_scale; + + template + struct di_replace_basis_scale_aux; + + /** specialization for non-empty BpuList **/ + template + struct di_replace_basis_scale { + using type = di_replace_basis_scale_aux::type; + }; + + /** specialization for empty BpuList -- error not found **/ + template + struct di_replace_basis_scale {}; + + /** specialization for matching front **/ + template + struct di_replace_basis_scale_aux { + using _replace_bpu_type = bpu; + + static_assert(native_bpu_concept<_replace_bpu_type>); + + /* NewBpu replaces Front */ + using type = bpu_node<_replace_bpu_type, Rest>; + }; + + template + struct di_replace_basis_scale_aux { + /* keep Front, replace NewBpu in rest */ + using type = bpu_node::type>; + }; + // ----- bpu_cartesian_product ----- /** Require: