- std::array< uint32_t, I > data;\r
-\r
- void _set()\r
- {\r
- }\r
-\r
- static constexpr bool _accepts()\r
- {\r
- return true;\r
- }\r
-\r
- template < typename T > static constexpr bool _accepts()\r
- {\r
- return std::is_enum< T >::value;\r
- }\r
-\r
- template < typename T, typename T2, typename ... ARGS > static constexpr bool _accepts()\r
- {\r
- return std::is_enum< T >::value && _accepts< T2, ARGS... >();\r
- }\r
-\r
- template < typename T, typename ... ARGS > void _set(T t, ARGS ... args)\r
- {\r
- (*this)[t] = true;\r
- _set(args...);\r
- }\r
-public:\r
- BitSets()\r
- {\r
- for( auto& u : data )\r
- {\r
- u = 0;\r
- }\r
- }\r
- BitSets(const BitSets&) = default;\r
- BitSets(BitSets&&) = default;\r
-\r
- template < typename T, typename ... ARGS, typename std::enable_if< _accepts< T, ARGS... >() >::type * = nullptr >BitSets( T t, ARGS ... args )\r
- {\r
- for( auto& u : data )\r
- u = 0;\r
- _set( t, args... );\r
- }\r
-\r
- explicit BitSets( std::array< uint32_t, I > d )\r
- {\r
- for( auto i = 0u; i < I; ++i )\r
- {\r
- data[i] = d[i];\r
- }\r
- }\r
-\r
- explicit BitSets( std::array< int32_t, I > d )\r
- {\r
- for( auto i = 0u; i < I; ++i )\r
- {\r
- data[i] = static_cast<uint32_t>( d[i] );\r
- }\r
- }\r
-\r
- BitSets& operator = (const BitSets&) = default;\r
- BitSets& operator = (BitSets&&) = default;\r
-\r
- struct reference\r
- {\r
- std::array< uint32_t, I >& data;\r
- size_t pos;\r
-\r
- reference& operator=( reference r )\r
- {\r
- (*this) = static_cast<bool>( r );\r
- return *this;\r
- }\r
-\r
- reference& operator=( bool v )\r
- {\r
- if( v )\r
- {\r
- data[pos / 32] |= 1 << (pos & 31);\r
- }\r
- else\r
- {\r
- data[pos / 32] &= ~(1 << (pos & 31));\r
- }\r
- return *this;\r
- }\r
-\r
- operator bool() const\r
- {\r
- auto i = static_cast<size_t>( pos );\r
- return (data[i / 32] & (1 << (i & 31))) != 0;\r
- }\r
- };\r
-\r
- reference operator[]( S index )\r
- {\r
- return { data, static_cast<size_t>( index ) };\r
- }\r
-\r
- bool operator[]( S index ) const\r
- {\r
- auto i = static_cast<size_t>( index );\r
- return ( data[i / 32] & ( 1 << (i & 31) ) ) != 0;\r
- }\r
-\r
- std::array< uint32_t, I > GetRawData() const\r
- {\r
- return data;\r
- }\r
-\r
- BitSets operator|( BitSets b ) const\r
- {\r
- BitSets r;\r
- for( auto i = 0u; i < I; ++i )\r
- {\r
- r.data[i] = data[i] | b.data[i];\r
- }\r
- return r;\r
- }\r
-\r
- BitSets operator^( BitSets b ) const\r
- {\r
- BitSets r;\r
- for( auto i = 0u; i < I; ++i )\r
- {\r
- r.data[i] = data[i] ^ b.data[i];\r
- }\r
- return r;\r
- }\r
-\r
- BitSets operator&( BitSets b ) const\r
- {\r
- BitSets r;\r
- for( auto i = 0u; i < I; ++i )\r
- {\r
- r.data[i] = data[i] & b.data[i];\r
- }\r
- return r;\r
- }\r