diff --git a/SeQuant/core/space.hpp b/SeQuant/core/space.hpp index 0fd3d69cf..cc928c65e 100644 --- a/SeQuant/core/space.hpp +++ b/SeQuant/core/space.hpp @@ -18,6 +18,14 @@ namespace sequant { +namespace bitset { +using type = int32_t; +constexpr type reserved = 0x80000000; +constexpr type null = 0x00000000; +} // namespace bitset + +using bitset_t = bitset::type; + class QuantumNumbersAttr; // used to constrain TypeAttr ctor class Index; // friend of TypeAttr @@ -29,8 +37,6 @@ class Index; // friend of TypeAttr /// (intersection, union, etc.) it is encoded as a fixed-width (32) bitset. class TypeAttr { public: - using bitset_t = int32_t; - /// default ctor creates a null TypeAttr constexpr TypeAttr() noexcept = default; @@ -43,7 +49,7 @@ class TypeAttr { /// @param bitset bitset representation of this Type /// @pre `(bitset & make_reserved().bitset) == null.bitset` explicit constexpr TypeAttr(bitset_t bitset) noexcept : bitset(bitset) { - assert((this->bitset & reserved.bitset) == null.bitset); + assert((this->bitset & bitset::reserved) == bitset::null); } /// construct TypeAddr from things that can be cast to bitset_t, but exclude @@ -144,8 +150,6 @@ inline const TypeAttr TypeAttr::reserved = TypeAttr::make_reserved(); /// denotes other quantum numbers (particle type, spin, etc.) class QuantumNumbersAttr { public: - using bitset_t = int32_t; - /// default ctor creates a null QuantumNumbersAttr /// @post `static_cast(*this) == false` constexpr QuantumNumbersAttr() noexcept = default; @@ -160,7 +164,7 @@ class QuantumNumbersAttr { /// @pre `(bitset & make_reserved().bitset()) == null.bitset()` explicit constexpr QuantumNumbersAttr(bitset_t bitset) noexcept : bitset(bitset) { - assert((this->bitset & reserved.bitset) == null.bitset); + assert((this->bitset & bitset::reserved) == bitset::null); } template ); +static_assert(!std::is_convertible_v); // QuantumNumbersAttr::bitset_t cannot be constructed from Spin -static_assert(!std::is_constructible_v); +static_assert(!std::is_constructible_v); // but Spin can be cast to QuantumNumbersAttr::bitset_t -static_assert(meta::is_statically_castable_v); +static_assert(meta::is_statically_castable_v); // Spin cannot be cast to nonsense ... static_assert( !meta::is_statically_castable_v); inline Spin operator~(Spin s) { - return static_cast(~(static_cast(s))); + return static_cast(~(static_cast(s))); } inline Spin operator|(Spin s1, Spin s2) { - return static_cast(static_cast(s1) | - static_cast(s2)); + return static_cast(static_cast(s1) | + static_cast(s2)); } inline Spin operator&(Spin s1, Spin s2) { - return static_cast(static_cast(s1) & - static_cast(s2)); + return static_cast(static_cast(s1) & + static_cast(s2)); } /// converts QuantumNumbersAttr to Spin