diff --git a/include/xo/unit/natural_unit.hpp b/include/xo/unit/natural_unit.hpp index b1616454..96453408 100644 --- a/include/xo/unit/natural_unit.hpp +++ b/include/xo/unit/natural_unit.hpp @@ -16,6 +16,34 @@ namespace xo { template class natural_unit; + namespace detail { + template + constexpr void + push_bpu_array(natural_unit * p_target, Ts... args); + + template + constexpr void + push_bpu_array(natural_unit * p_target) {} + + template + constexpr void + push_bpu_array(natural_unit * p_target, T0 && bpu0, Ts... args) { + p_target->push_back(bpu0); + push_bpu_array(p_target, args...); + } + } + + template + struct bpu_array_maker { + template + static constexpr natural_unit + make_bpu_array(Ts... args) { + natural_unit bpu_array; + detail::push_bpu_array(&bpu_array, args...); + return bpu_array; + } + }; + /** @class natural_unit * @brief an array representing the cartesian product of distinct basis-power-units * @@ -35,6 +63,10 @@ namespace xo { public: constexpr natural_unit() : n_bpu_{0} {} + static constexpr natural_unit from_bu(basis_unit bu) { + return bpu_array_maker::make_bpu_array(make_unit_power(bu)); + } + constexpr std::size_t n_bpu() const { return n_bpu_; } constexpr bool is_dimensionless() const { return n_bpu_ == 0; } @@ -96,34 +128,6 @@ namespace xo { bpu bpu_v_[n_dim]; }; - namespace detail { - template - constexpr void - push_bpu_array(natural_unit * p_target, Ts... args); - - template - constexpr void - push_bpu_array(natural_unit * p_target) {} - - template - constexpr void - push_bpu_array(natural_unit * p_target, T0 && bpu0, Ts... args) { - p_target->push_back(bpu0); - push_bpu_array(p_target, args...); - } - } - - template - struct bpu_array_maker { - template - static constexpr natural_unit - make_bpu_array(Ts... args) { - natural_unit bpu_array; - detail::push_bpu_array(&bpu_array, args...); - return bpu_array; - } - }; - namespace detail { /** * Given bpu ~ (b.u)^p: