#ifndef ALGOIM_BOOLUARRAY_HPP #define ALGOIM_BOOLUARRAY_HPP // algoim::booluarray #include #include "uvector.hpp" namespace algoim { namespace booluarray_detail { constexpr int pow(int base, int exp) { return exp == 0 ? 1 : base * pow(base, exp - 1); } template constexpr int furl(const uvector& i) // 为什么这里可以是constexpr,uvector不是变量吗? { int ind = i(0); for (int j = 1; j < N; ++j) ind = ind * E + i(j); return ind; } } // namespace booluarray_detail // booluarray implements a simple N-dimensional array of booleans, with // compile-time extent E across all dimensions; it is essentially a basic // specialisation of uarray template class booluarray { constexpr static int size = booluarray_detail::pow(E, N); public: std::bitset bits; booluarray() {} booluarray(bool val) { if (val) bits.set(); // 全部置为1 } bool operator()(const uvector& i) const { return bits[booluarray_detail::furl(i)]; } auto operator()(const uvector& i) { return bits[booluarray_detail::furl(i)]; } // returns true iff the entire array is false bool none() const { return bits.none(); } }; } // namespace algoim #endif