diff --git a/include/xo/unit/basis_unit.hpp b/include/xo/unit/basis_unit.hpp index 2c7bb8b4..57f440b0 100644 --- a/include/xo/unit/basis_unit.hpp +++ b/include/xo/unit/basis_unit.hpp @@ -37,6 +37,20 @@ namespace xo { scalefactor_ratio_type scalefactor_; }; + inline constexpr bool + operator==(const basis_unit & x, const basis_unit & y) + { + return ((x.native_dim_ == y.native_dim_) + && (x.scalefactor_ == y.scalefactor_)); + } + + inline constexpr bool + operator!=(const basis_unit & x, const basis_unit & y) + { + return ((x.native_dim_ != y.native_dim_) + || (x.scalefactor_ != y.scalefactor_)); + } + namespace bu { // ----- mass ----- @@ -144,134 +158,7 @@ namespace xo { (scalefactor.to_str(), native_unit2_v[static_cast(basis_dim)].abbrev_str()))); } - -#ifdef NOT_USING - template - struct scaled_native_unit2_abbrev { - /* e.g. unit of '1000 grams' will have abbrev '1000g' in absence - * of a specialization for scaled_native_unit_abbrev - */ - static constexpr const basis_unit2_abbrev_type value - = (basis_unit2_abbrev_type::from_flatstring - (flatstring_concat - (xo::ratio::ratio(InnerScaleNum, - InnerScaleDen) - .to_str(), - native_unit2_v[static_cast(BasisDim)].abbrev_str()))); - - // = bu_fallback_abbrev(BasisDim, - // xo::ratio::ratio(InnerScaleNum, InnerScaleDen)); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("ng"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("ug"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("mg"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("kg"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("t"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("kt"); - }; - - // ----- units for dim::distance ----- - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("nm"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("um"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("mm"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("km"); - }; - - // ----- units for dim::time ----- - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("ns"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("us"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("ms"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("min"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("hr"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("dy"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("yr250"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("yr360"); - }; - - template <> - struct scaled_native_unit2_abbrev { - static constexpr const basis_unit2_abbrev_type value = basis_unit2_abbrev_type::from_chars("yr365"); - }; - - // ----- native unit abbrev api ----- - - template - constexpr auto scaled_native_unit2_abbrev_v = scaled_native_unit2_abbrev::value; -#endif } - - } /*namespace qty*/ } /*namespace xo*/ diff --git a/include/xo/unit/bpu.hpp b/include/xo/unit/bpu.hpp index 3e394356..2e167734 100644 --- a/include/xo/unit/bpu.hpp +++ b/include/xo/unit/bpu.hpp @@ -118,6 +118,22 @@ namespace xo { return bpu::unit_power(bu); } + template + inline constexpr bool + operator==(const bpu & x, const bpu & y) { + return ((x.native_dim_ == y.native_dim_) + && (x.scalefactor_ == y.scalefactor_) + && (x.power_ == y.power_)); + } + + template + inline constexpr bool + operator!=(const bpu & x, const bpu & y) { + return ((x.native_dim_ != y.native_dim_) + || (x.scalefactor_ != y.scalefactor_) + || (x.power_ != y.power_)); + } + } /*namespace qty*/ } /*namespace xo*/ diff --git a/include/xo/unit/natural_unit.hpp b/include/xo/unit/natural_unit.hpp index 1eba006e..96272fff 100644 --- a/include/xo/unit/natural_unit.hpp +++ b/include/xo/unit/natural_unit.hpp @@ -130,6 +130,25 @@ namespace xo { bpu bpu_v_[n_dim]; }; + template + constexpr bool + operator==(const natural_unit & x, const natural_unit & y) { + if (x.n_bpu() != y.n_bpu()) + return false; + + for (std::size_t i = 0, n = x.n_bpu(); i + constexpr bool + operator!=(const natural_unit & x, const natural_unit & y) { + return !(x == y); + } + namespace detail { /** * Given bpu ~ (b.u)^p: