Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- bitset ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_BITSET |
| 12 | #define _LIBCPP_BITSET |
| 13 | |
| 14 | /* |
| 15 | bitset synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | namespace std { |
| 21 | |
| 22 | template <size_t N> |
| 23 | class bitset |
| 24 | { |
| 25 | public: |
| 26 | // bit reference: |
| 27 | class reference |
| 28 | { |
| 29 | friend class bitset; |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 30 | reference() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | public: |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 32 | ~reference() noexcept; |
| 33 | reference& operator=(bool x) noexcept; // for b[i] = x; |
| 34 | reference& operator=(const reference&) noexcept; // for b[i] = b[j]; |
| 35 | bool operator~() const noexcept; // flips the bit |
| 36 | operator bool() const noexcept; // for x = b[i]; |
| 37 | reference& flip() noexcept; // for b[i].flip(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | // 23.3.5.1 constructors: |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 41 | constexpr bitset() noexcept; |
| 42 | constexpr bitset(unsigned long long val) noexcept; |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 43 | template <class charT> |
| 44 | explicit bitset(const charT* str, |
| 45 | typename basic_string<charT>::size_type n = basic_string<charT>::npos, |
| 46 | charT zero = charT('0'), charT one = charT('1')); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | template<class charT, class traits, class Allocator> |
| 48 | explicit bitset(const basic_string<charT,traits,Allocator>& str, |
| 49 | typename basic_string<charT,traits,Allocator>::size_type pos = 0, |
| 50 | typename basic_string<charT,traits,Allocator>::size_type n = |
| 51 | basic_string<charT,traits,Allocator>::npos, |
| 52 | charT zero = charT('0'), charT one = charT('1')); |
| 53 | |
| 54 | // 23.3.5.2 bitset operations: |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 55 | bitset& operator&=(const bitset& rhs) noexcept; |
| 56 | bitset& operator|=(const bitset& rhs) noexcept; |
| 57 | bitset& operator^=(const bitset& rhs) noexcept; |
| 58 | bitset& operator<<=(size_t pos) noexcept; |
| 59 | bitset& operator>>=(size_t pos) noexcept; |
| 60 | bitset& set() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | bitset& set(size_t pos, bool val = true); |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 62 | bitset& reset() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | bitset& reset(size_t pos); |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 64 | bitset operator~() const noexcept; |
| 65 | bitset& flip() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | bitset& flip(size_t pos); |
| 67 | |
| 68 | // element access: |
| 69 | constexpr bool operator[](size_t pos) const; // for b[i]; |
| 70 | reference operator[](size_t pos); // for b[i]; |
| 71 | unsigned long to_ulong() const; |
| 72 | unsigned long long to_ullong() const; |
| 73 | template <class charT, class traits, class Allocator> |
| 74 | basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; |
| 75 | template <class charT, class traits> |
| 76 | basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; |
| 77 | template <class charT> |
| 78 | basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; |
| 79 | basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 80 | size_t count() const noexcept; |
| 81 | constexpr size_t size() const noexcept; |
| 82 | bool operator==(const bitset& rhs) const noexcept; |
| 83 | bool operator!=(const bitset& rhs) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | bool test(size_t pos) const; |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 85 | bool all() const noexcept; |
| 86 | bool any() const noexcept; |
| 87 | bool none() const noexcept; |
| 88 | bitset operator<<(size_t pos) const noexcept; |
| 89 | bitset operator>>(size_t pos) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | // 23.3.5.3 bitset operators: |
| 93 | template <size_t N> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 94 | bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | |
| 96 | template <size_t N> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 97 | bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | |
| 99 | template <size_t N> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 100 | bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 101 | |
| 102 | template <class charT, class traits, size_t N> |
| 103 | basic_istream<charT, traits>& |
| 104 | operator>>(basic_istream<charT, traits>& is, bitset<N>& x); |
| 105 | |
| 106 | template <class charT, class traits, size_t N> |
| 107 | basic_ostream<charT, traits>& |
| 108 | operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); |
| 109 | |
| 110 | template <size_t N> struct hash<std::bitset<N>>; |
| 111 | |
| 112 | } // std |
| 113 | |
| 114 | */ |
| 115 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 116 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 117 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 118 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | |
| 120 | #include <__config> |
| 121 | #include <__bit_reference> |
| 122 | #include <cstddef> |
| 123 | #include <climits> |
| 124 | #include <string> |
| 125 | #include <stdexcept> |
| 126 | #include <iosfwd> |
| 127 | #include <__functional_base> |
| 128 | #if defined(_LIBCPP_NO_EXCEPTIONS) |
| 129 | #include <cassert> |
| 130 | #endif |
| 131 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 132 | #include <__undef_min_max> |
| 133 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 135 | |
| 136 | template <size_t _N_words, size_t _Size> |
Howard Hinnant | f03c3b4 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 137 | class __bitset; |
| 138 | |
| 139 | template <size_t _N_words, size_t _Size> |
| 140 | struct __has_storage_type<__bitset<_N_words, _Size> > |
| 141 | { |
| 142 | static const bool value = true; |
| 143 | }; |
| 144 | |
| 145 | template <size_t _N_words, size_t _Size> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | class __bitset |
| 147 | { |
| 148 | public: |
| 149 | typedef ptrdiff_t difference_type; |
| 150 | typedef size_t size_type; |
Howard Hinnant | f867f63 | 2012-05-07 16:50:38 +0000 | [diff] [blame] | 151 | typedef size_type __storage_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | protected: |
| 153 | typedef __bitset __self; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | typedef __storage_type* __storage_pointer; |
| 155 | typedef const __storage_type* __const_storage_pointer; |
| 156 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 157 | |
| 158 | friend class __bit_reference<__bitset>; |
| 159 | friend class __bit_const_reference<__bitset>; |
| 160 | friend class __bit_iterator<__bitset, false>; |
| 161 | friend class __bit_iterator<__bitset, true>; |
Howard Hinnant | 4ae952a | 2012-08-17 17:10:18 +0000 | [diff] [blame] | 162 | friend struct __bit_array<__bitset>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 163 | |
| 164 | __storage_type __first_[_N_words]; |
| 165 | |
| 166 | typedef __bit_reference<__bitset> reference; |
| 167 | typedef __bit_const_reference<__bitset> const_reference; |
| 168 | typedef __bit_iterator<__bitset, false> iterator; |
| 169 | typedef __bit_iterator<__bitset, true> const_iterator; |
| 170 | |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 171 | _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
| 172 | explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 174 | _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 176 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 178 | _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 180 | _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} |
| 182 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 183 | void operator&=(const __bitset& __v) _NOEXCEPT; |
| 184 | void operator|=(const __bitset& __v) _NOEXCEPT; |
| 185 | void operator^=(const __bitset& __v) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 187 | void flip() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const |
| 189 | {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} |
| 190 | _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const |
| 191 | {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} |
| 192 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 193 | bool all() const _NOEXCEPT; |
| 194 | bool any() const _NOEXCEPT; |
| 195 | size_t __hash_code() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 196 | private: |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 197 | #ifdef _LIBCPP_HAS_NO_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 198 | void __init(unsigned long long __v, false_type) _NOEXCEPT; |
| 199 | void __init(unsigned long long __v, true_type) _NOEXCEPT; |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 200 | #endif // _LIBCPP_HAS_NO_CONSTEXPR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | unsigned long to_ulong(false_type) const; |
| 202 | unsigned long to_ulong(true_type) const; |
| 203 | unsigned long long to_ullong(false_type) const; |
| 204 | unsigned long long to_ullong(true_type) const; |
| 205 | unsigned long long to_ullong(true_type, false_type) const; |
| 206 | unsigned long long to_ullong(true_type, true_type) const; |
| 207 | }; |
| 208 | |
| 209 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 210 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 211 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 212 | __bitset<_N_words, _Size>::__bitset() _NOEXCEPT |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 213 | #ifndef _LIBCPP_HAS_NO_CONSTEXPR |
| 214 | : __first_{0} |
| 215 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | { |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 217 | #ifdef _LIBCPP_HAS_NO_CONSTEXPR |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 218 | _VSTD::fill_n(__first_, _N_words, __storage_type(0)); |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 219 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 222 | #ifdef _LIBCPP_HAS_NO_CONSTEXPR |
| 223 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | template <size_t _N_words, size_t _Size> |
| 225 | void |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 226 | __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | { |
| 228 | __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; |
| 229 | for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) |
| 230 | __t[__i] = static_cast<__storage_type>(__v); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 231 | _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); |
| 232 | _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | __storage_type(0)); |
| 234 | } |
| 235 | |
| 236 | template <size_t _N_words, size_t _Size> |
| 237 | inline _LIBCPP_INLINE_VISIBILITY |
| 238 | void |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 239 | __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | { |
| 241 | __first_[0] = __v; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 242 | _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 245 | #endif // _LIBCPP_HAS_NO_CONSTEXPR |
| 246 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 248 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 249 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 250 | __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 251 | #ifndef _LIBCPP_HAS_NO_CONSTEXPR |
Nico Weber | 0211e86 | 2014-06-04 15:46:56 +0000 | [diff] [blame] | 252 | #if __SIZEOF_SIZE_T__ == 8 |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 253 | : __first_{__v} |
Nico Weber | 0211e86 | 2014-06-04 15:46:56 +0000 | [diff] [blame] | 254 | #elif __SIZEOF_SIZE_T__ == 4 |
Howard Hinnant | 11a31d0 | 2013-03-06 17:30:26 +0000 | [diff] [blame] | 255 | : __first_{__v, __v >> __bits_per_word} |
Howard Hinnant | 3101474 | 2013-03-06 18:16:12 +0000 | [diff] [blame] | 256 | #else |
Howard Hinnant | 11a31d0 | 2013-03-06 17:30:26 +0000 | [diff] [blame] | 257 | #error This constructor has not been ported to this platform |
| 258 | #endif |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 259 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | { |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 261 | #ifdef _LIBCPP_HAS_NO_CONSTEXPR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 262 | __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 263 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 267 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 269 | __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | { |
| 271 | for (size_type __i = 0; __i < _N_words; ++__i) |
| 272 | __first_[__i] &= __v.__first_[__i]; |
| 273 | } |
| 274 | |
| 275 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 276 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 277 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 278 | __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | { |
| 280 | for (size_type __i = 0; __i < _N_words; ++__i) |
| 281 | __first_[__i] |= __v.__first_[__i]; |
| 282 | } |
| 283 | |
| 284 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 285 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 286 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 287 | __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 288 | { |
| 289 | for (size_type __i = 0; __i < _N_words; ++__i) |
| 290 | __first_[__i] ^= __v.__first_[__i]; |
| 291 | } |
| 292 | |
| 293 | template <size_t _N_words, size_t _Size> |
| 294 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 295 | __bitset<_N_words, _Size>::flip() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | { |
| 297 | // do middle whole words |
| 298 | size_type __n = _Size; |
| 299 | __storage_pointer __p = __first_; |
| 300 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 301 | *__p = ~*__p; |
| 302 | // do last partial word |
| 303 | if (__n > 0) |
| 304 | { |
| 305 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 306 | __storage_type __b = *__p & __m; |
| 307 | *__p &= ~__m; |
| 308 | *__p |= ~__b & __m; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | template <size_t _N_words, size_t _Size> |
| 313 | unsigned long |
| 314 | __bitset<_N_words, _Size>::to_ulong(false_type) const |
| 315 | { |
| 316 | const_iterator __e = __make_iter(_Size); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 317 | const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 318 | if (__i != __e) |
| 319 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 320 | throw overflow_error("bitset to_ulong overflow error"); |
| 321 | #else |
| 322 | assert(!"bitset to_ulong overflow error"); |
| 323 | #endif |
| 324 | return __first_[0]; |
| 325 | } |
| 326 | |
| 327 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 328 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 | unsigned long |
| 330 | __bitset<_N_words, _Size>::to_ulong(true_type) const |
| 331 | { |
| 332 | return __first_[0]; |
| 333 | } |
| 334 | |
| 335 | template <size_t _N_words, size_t _Size> |
| 336 | unsigned long long |
| 337 | __bitset<_N_words, _Size>::to_ullong(false_type) const |
| 338 | { |
| 339 | const_iterator __e = __make_iter(_Size); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 340 | const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 341 | if (__i != __e) |
| 342 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 343 | throw overflow_error("bitset to_ullong overflow error"); |
| 344 | #else |
| 345 | assert(!"bitset to_ullong overflow error"); |
| 346 | #endif |
| 347 | return to_ullong(true_type()); |
| 348 | } |
| 349 | |
| 350 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 351 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | unsigned long long |
| 353 | __bitset<_N_words, _Size>::to_ullong(true_type) const |
| 354 | { |
| 355 | return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); |
| 356 | } |
| 357 | |
| 358 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 359 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | unsigned long long |
| 361 | __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const |
| 362 | { |
| 363 | return __first_[0]; |
| 364 | } |
| 365 | |
| 366 | template <size_t _N_words, size_t _Size> |
| 367 | unsigned long long |
| 368 | __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const |
| 369 | { |
| 370 | unsigned long long __r = __first_[0]; |
| 371 | for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) |
| 372 | __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); |
| 373 | return __r; |
| 374 | } |
| 375 | |
| 376 | template <size_t _N_words, size_t _Size> |
| 377 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 378 | __bitset<_N_words, _Size>::all() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | { |
| 380 | // do middle whole words |
| 381 | size_type __n = _Size; |
| 382 | __const_storage_pointer __p = __first_; |
| 383 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 384 | if (~*__p) |
| 385 | return false; |
| 386 | // do last partial word |
| 387 | if (__n > 0) |
| 388 | { |
| 389 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 390 | if (~*__p & __m) |
| 391 | return false; |
| 392 | } |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | template <size_t _N_words, size_t _Size> |
| 397 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 398 | __bitset<_N_words, _Size>::any() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | { |
| 400 | // do middle whole words |
| 401 | size_type __n = _Size; |
| 402 | __const_storage_pointer __p = __first_; |
| 403 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 404 | if (*__p) |
| 405 | return true; |
| 406 | // do last partial word |
| 407 | if (__n > 0) |
| 408 | { |
| 409 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 410 | if (*__p & __m) |
| 411 | return true; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | template <size_t _N_words, size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 417 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | size_t |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 419 | __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | { |
| 421 | size_t __h = 0; |
| 422 | for (size_type __i = 0; __i < _N_words; ++__i) |
| 423 | __h ^= __first_[__i]; |
| 424 | return __h; |
| 425 | } |
| 426 | |
| 427 | template <size_t _Size> |
| 428 | class __bitset<1, _Size> |
| 429 | { |
| 430 | public: |
| 431 | typedef ptrdiff_t difference_type; |
| 432 | typedef size_t size_type; |
Howard Hinnant | f867f63 | 2012-05-07 16:50:38 +0000 | [diff] [blame] | 433 | typedef size_type __storage_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | protected: |
| 435 | typedef __bitset __self; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | typedef __storage_type* __storage_pointer; |
| 437 | typedef const __storage_type* __const_storage_pointer; |
| 438 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 439 | |
| 440 | friend class __bit_reference<__bitset>; |
| 441 | friend class __bit_const_reference<__bitset>; |
| 442 | friend class __bit_iterator<__bitset, false>; |
| 443 | friend class __bit_iterator<__bitset, true>; |
Howard Hinnant | 4ae952a | 2012-08-17 17:10:18 +0000 | [diff] [blame] | 444 | friend struct __bit_array<__bitset>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | __storage_type __first_; |
| 447 | |
| 448 | typedef __bit_reference<__bitset> reference; |
| 449 | typedef __bit_const_reference<__bitset> const_reference; |
| 450 | typedef __bit_iterator<__bitset, false> iterator; |
| 451 | typedef __bit_iterator<__bitset, true> const_iterator; |
| 452 | |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 453 | _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
| 454 | explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 456 | _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | {return reference(&__first_, __storage_type(1) << __pos);} |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 458 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | {return const_reference(&__first_, __storage_type(1) << __pos);} |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 460 | _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 462 | _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} |
| 464 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 465 | void operator&=(const __bitset& __v) _NOEXCEPT; |
| 466 | void operator|=(const __bitset& __v) _NOEXCEPT; |
| 467 | void operator^=(const __bitset& __v) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 469 | void flip() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | |
| 471 | unsigned long to_ulong() const; |
| 472 | unsigned long long to_ullong() const; |
| 473 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 474 | bool all() const _NOEXCEPT; |
| 475 | bool any() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 477 | size_t __hash_code() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | }; |
| 479 | |
| 480 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 481 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 482 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 483 | __bitset<1, _Size>::__bitset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 | : __first_(0) |
| 485 | { |
| 486 | } |
| 487 | |
| 488 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 489 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 490 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 491 | __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | : __first_(static_cast<__storage_type>(__v)) |
| 493 | { |
| 494 | } |
| 495 | |
| 496 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 497 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 499 | __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | { |
| 501 | __first_ &= __v.__first_; |
| 502 | } |
| 503 | |
| 504 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 505 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 507 | __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | { |
| 509 | __first_ |= __v.__first_; |
| 510 | } |
| 511 | |
| 512 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 513 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 515 | __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | { |
| 517 | __first_ ^= __v.__first_; |
| 518 | } |
| 519 | |
| 520 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 521 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | void |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 523 | __bitset<1, _Size>::flip() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | { |
| 525 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
| 526 | __first_ = ~__first_; |
| 527 | __first_ &= __m; |
| 528 | } |
| 529 | |
| 530 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 531 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | unsigned long |
| 533 | __bitset<1, _Size>::to_ulong() const |
| 534 | { |
| 535 | return __first_; |
| 536 | } |
| 537 | |
| 538 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 539 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 540 | unsigned long long |
| 541 | __bitset<1, _Size>::to_ullong() const |
| 542 | { |
| 543 | return __first_; |
| 544 | } |
| 545 | |
| 546 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 547 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 549 | __bitset<1, _Size>::all() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | { |
| 551 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
| 552 | return !(~__first_ & __m); |
| 553 | } |
| 554 | |
| 555 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 556 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 558 | __bitset<1, _Size>::any() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 559 | { |
| 560 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
| 561 | return __first_ & __m; |
| 562 | } |
| 563 | |
| 564 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 565 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | size_t |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 567 | __bitset<1, _Size>::__hash_code() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | { |
| 569 | return __first_; |
| 570 | } |
| 571 | |
| 572 | template <> |
| 573 | class __bitset<0, 0> |
| 574 | { |
| 575 | public: |
| 576 | typedef ptrdiff_t difference_type; |
| 577 | typedef size_t size_type; |
Howard Hinnant | f867f63 | 2012-05-07 16:50:38 +0000 | [diff] [blame] | 578 | typedef size_type __storage_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 579 | protected: |
| 580 | typedef __bitset __self; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | typedef __storage_type* __storage_pointer; |
| 582 | typedef const __storage_type* __const_storage_pointer; |
| 583 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 584 | |
| 585 | friend class __bit_reference<__bitset>; |
| 586 | friend class __bit_const_reference<__bitset>; |
| 587 | friend class __bit_iterator<__bitset, false>; |
| 588 | friend class __bit_iterator<__bitset, true>; |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 589 | friend struct __bit_array<__bitset>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | |
| 591 | typedef __bit_reference<__bitset> reference; |
| 592 | typedef __bit_const_reference<__bitset> const_reference; |
| 593 | typedef __bit_iterator<__bitset, false> iterator; |
| 594 | typedef __bit_iterator<__bitset, true> const_iterator; |
| 595 | |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 596 | _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
| 597 | explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 599 | _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | {return reference(0, 1);} |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 601 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | {return const_reference(0, 1);} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 603 | _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | {return iterator(0, 0);} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 605 | _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | {return const_iterator(0, 0);} |
| 607 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 608 | _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} |
| 609 | _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} |
| 610 | _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 612 | _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | |
| 614 | _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} |
| 615 | _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} |
| 616 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} |
| 618 | _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 620 | _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | }; |
| 622 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 623 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 624 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 625 | __bitset<0, 0>::__bitset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | { |
| 627 | } |
| 628 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 629 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 630 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 631 | __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | { |
| 633 | } |
| 634 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 635 | template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 636 | template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | |
| 638 | template <size_t _Size> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 639 | class _LIBCPP_TYPE_VIS_ONLY bitset |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 640 | : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> |
| 641 | { |
Howard Hinnant | 11a31d0 | 2013-03-06 17:30:26 +0000 | [diff] [blame] | 642 | public: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; |
| 644 | typedef __bitset<__n_words, _Size> base; |
| 645 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 646 | public: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | typedef typename base::reference reference; |
| 648 | typedef typename base::const_reference const_reference; |
| 649 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 650 | // 23.3.5.1 constructors: |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 651 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} |
| 652 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 653 | bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 654 | template<class _CharT> |
| 655 | explicit bitset(const _CharT* __str, |
| 656 | typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, |
| 657 | _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 658 | template<class _CharT, class _Traits, class _Allocator> |
| 659 | explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, |
| 660 | typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, |
| 661 | typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | (basic_string<_CharT,_Traits,_Allocator>::npos), |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 663 | _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 665 | // 23.3.5.2 bitset operations: |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 666 | bitset& operator&=(const bitset& __rhs) _NOEXCEPT; |
| 667 | bitset& operator|=(const bitset& __rhs) _NOEXCEPT; |
| 668 | bitset& operator^=(const bitset& __rhs) _NOEXCEPT; |
| 669 | bitset& operator<<=(size_t __pos) _NOEXCEPT; |
| 670 | bitset& operator>>=(size_t __pos) _NOEXCEPT; |
| 671 | bitset& set() _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 672 | bitset& set(size_t __pos, bool __val = true); |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 673 | bitset& reset() _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 674 | bitset& reset(size_t __pos); |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 675 | bitset operator~() const _NOEXCEPT; |
| 676 | bitset& flip() _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 677 | bitset& flip(size_t __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 678 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 679 | // element access: |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 680 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 681 | const_reference operator[](size_t __p) const {return base::__make_ref(__p);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 682 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 683 | unsigned long to_ulong() const; |
| 684 | unsigned long long to_ullong() const; |
| 685 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 686 | basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 687 | _CharT __one = _CharT('1')) const; |
| 688 | template <class _CharT, class _Traits> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 689 | basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 690 | _CharT __one = _CharT('1')) const; |
| 691 | template <class _CharT> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 693 | _CharT __one = _CharT('1')) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 694 | basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 695 | char __one = '1') const; |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 696 | size_t count() const _NOEXCEPT; |
Howard Hinnant | 90d8723 | 2012-07-07 17:04:52 +0000 | [diff] [blame] | 697 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 698 | bool operator==(const bitset& __rhs) const _NOEXCEPT; |
| 699 | bool operator!=(const bitset& __rhs) const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 700 | bool test(size_t __pos) const; |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 701 | bool all() const _NOEXCEPT; |
| 702 | bool any() const _NOEXCEPT; |
| 703 | _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} |
| 704 | bitset operator<<(size_t __pos) const _NOEXCEPT; |
| 705 | bitset operator>>(size_t __pos) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 706 | |
| 707 | private: |
| 708 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 709 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 710 | size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | |
| 712 | friend struct hash<bitset>; |
| 713 | }; |
| 714 | |
| 715 | template <size_t _Size> |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 716 | template<class _CharT> |
| 717 | bitset<_Size>::bitset(const _CharT* __str, |
| 718 | typename basic_string<_CharT>::size_type __n, |
| 719 | _CharT __zero, _CharT __one) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 721 | size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | for (size_t __i = 0; __i < __rlen; ++__i) |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 723 | if (__str[__i] != __zero && __str[__i] != __one) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 724 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 725 | throw invalid_argument("bitset string ctor has invalid argument"); |
| 726 | #else |
| 727 | assert(!"bitset string ctor has invalid argument"); |
| 728 | #endif |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 729 | size_t _Mp = _VSTD::min(__rlen, _Size); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 730 | size_t __i = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 731 | for (; __i < _Mp; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 733 | _CharT __c = __str[_Mp - 1 - __i]; |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 734 | if (__c == __zero) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 735 | (*this)[__i] = false; |
Howard Hinnant | 34d6b19 | 2010-11-17 21:53:14 +0000 | [diff] [blame] | 736 | else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 737 | (*this)[__i] = true; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 739 | _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | template <size_t _Size> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 743 | template<class _CharT, class _Traits, class _Allocator> |
| 744 | bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, |
| 745 | typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, |
| 747 | _CharT __zero, _CharT __one) |
| 748 | { |
| 749 | if (__pos > __str.size()) |
| 750 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 751 | throw out_of_range("bitset string pos out of range"); |
| 752 | #else |
| 753 | assert(!"bitset string pos out of range"); |
| 754 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 755 | size_t __rlen = _VSTD::min(__n, __str.size() - __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | for (size_t __i = __pos; __i < __pos + __rlen; ++__i) |
| 757 | if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) |
| 758 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 759 | throw invalid_argument("bitset string ctor has invalid argument"); |
| 760 | #else |
| 761 | assert(!"bitset string ctor has invalid argument"); |
| 762 | #endif |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 763 | size_t _Mp = _VSTD::min(__rlen, _Size); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | size_t __i = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 765 | for (; __i < _Mp; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 767 | _CharT __c = __str[__pos + _Mp - 1 - __i]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | if (_Traits::eq(__c, __zero)) |
| 769 | (*this)[__i] = false; |
| 770 | else |
| 771 | (*this)[__i] = true; |
| 772 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 773 | _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 777 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 779 | bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 780 | { |
| 781 | base::operator&=(__rhs); |
| 782 | return *this; |
| 783 | } |
| 784 | |
| 785 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 786 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 787 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 788 | bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 789 | { |
| 790 | base::operator|=(__rhs); |
| 791 | return *this; |
| 792 | } |
| 793 | |
| 794 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 795 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 797 | bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | { |
| 799 | base::operator^=(__rhs); |
| 800 | return *this; |
| 801 | } |
| 802 | |
| 803 | template <size_t _Size> |
| 804 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 805 | bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 806 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 807 | __pos = _VSTD::min(__pos, _Size); |
| 808 | _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); |
| 809 | _VSTD::fill_n(base::__make_iter(0), __pos, false); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | return *this; |
| 811 | } |
| 812 | |
| 813 | template <size_t _Size> |
| 814 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 815 | bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 817 | __pos = _VSTD::min(__pos, _Size); |
| 818 | _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); |
| 819 | _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 820 | return *this; |
| 821 | } |
| 822 | |
| 823 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 824 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 825 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 826 | bitset<_Size>::set() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 827 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 828 | _VSTD::fill_n(base::__make_iter(0), _Size, true); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | return *this; |
| 830 | } |
| 831 | |
| 832 | template <size_t _Size> |
| 833 | bitset<_Size>& |
| 834 | bitset<_Size>::set(size_t __pos, bool __val) |
| 835 | { |
| 836 | if (__pos >= _Size) |
| 837 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 838 | throw out_of_range("bitset set argument out of range"); |
| 839 | #else |
| 840 | assert(!"bitset set argument out of range"); |
| 841 | #endif |
| 842 | (*this)[__pos] = __val; |
| 843 | return *this; |
| 844 | } |
| 845 | |
| 846 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 847 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 848 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 849 | bitset<_Size>::reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 851 | _VSTD::fill_n(base::__make_iter(0), _Size, false); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | return *this; |
| 853 | } |
| 854 | |
| 855 | template <size_t _Size> |
| 856 | bitset<_Size>& |
| 857 | bitset<_Size>::reset(size_t __pos) |
| 858 | { |
| 859 | if (__pos >= _Size) |
| 860 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 861 | throw out_of_range("bitset reset argument out of range"); |
| 862 | #else |
| 863 | assert(!"bitset reset argument out of range"); |
| 864 | #endif |
| 865 | (*this)[__pos] = false; |
| 866 | return *this; |
| 867 | } |
| 868 | |
| 869 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 870 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 872 | bitset<_Size>::operator~() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 873 | { |
| 874 | bitset __x(*this); |
| 875 | __x.flip(); |
| 876 | return __x; |
| 877 | } |
| 878 | |
| 879 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 880 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 881 | bitset<_Size>& |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 882 | bitset<_Size>::flip() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 883 | { |
| 884 | base::flip(); |
| 885 | return *this; |
| 886 | } |
| 887 | |
| 888 | template <size_t _Size> |
| 889 | bitset<_Size>& |
| 890 | bitset<_Size>::flip(size_t __pos) |
| 891 | { |
| 892 | if (__pos >= _Size) |
| 893 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 894 | throw out_of_range("bitset flip argument out of range"); |
| 895 | #else |
| 896 | assert(!"bitset flip argument out of range"); |
| 897 | #endif |
| 898 | reference r = base::__make_ref(__pos); |
| 899 | r = ~r; |
| 900 | return *this; |
| 901 | } |
| 902 | |
| 903 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 904 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | unsigned long |
| 906 | bitset<_Size>::to_ulong() const |
| 907 | { |
| 908 | return base::to_ulong(); |
| 909 | } |
| 910 | |
| 911 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 912 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | unsigned long long |
| 914 | bitset<_Size>::to_ullong() const |
| 915 | { |
| 916 | return base::to_ullong(); |
| 917 | } |
| 918 | |
| 919 | template <size_t _Size> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 920 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | basic_string<_CharT, _Traits, _Allocator> |
| 922 | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const |
| 923 | { |
| 924 | basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); |
| 925 | for (size_t __i = 0; __i < _Size; ++__i) |
| 926 | { |
| 927 | if ((*this)[__i]) |
| 928 | __r[_Size - 1 - __i] = __one; |
| 929 | } |
| 930 | return __r; |
| 931 | } |
| 932 | |
| 933 | template <size_t _Size> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 934 | template <class _CharT, class _Traits> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 935 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 936 | basic_string<_CharT, _Traits, allocator<_CharT> > |
| 937 | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const |
| 938 | { |
| 939 | return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); |
| 940 | } |
| 941 | |
| 942 | template <size_t _Size> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 943 | template <class _CharT> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 944 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 945 | basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > |
| 946 | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const |
| 947 | { |
| 948 | return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); |
| 949 | } |
| 950 | |
| 951 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 952 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 953 | basic_string<char, char_traits<char>, allocator<char> > |
| 954 | bitset<_Size>::to_string(char __zero, char __one) const |
| 955 | { |
| 956 | return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); |
| 957 | } |
| 958 | |
| 959 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 960 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 961 | size_t |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 962 | bitset<_Size>::count() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 963 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 964 | return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 968 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 969 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 970 | bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 972 | return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 976 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 978 | bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 979 | { |
| 980 | return !(*this == __rhs); |
| 981 | } |
| 982 | |
| 983 | template <size_t _Size> |
| 984 | bool |
| 985 | bitset<_Size>::test(size_t __pos) const |
| 986 | { |
| 987 | if (__pos >= _Size) |
| 988 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 989 | throw out_of_range("bitset test argument out of range"); |
| 990 | #else |
| 991 | assert(!"bitset test argument out of range"); |
| 992 | #endif |
| 993 | return (*this)[__pos]; |
| 994 | } |
| 995 | |
| 996 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 997 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 999 | bitset<_Size>::all() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1000 | { |
| 1001 | return base::all(); |
| 1002 | } |
| 1003 | |
| 1004 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 1005 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | bool |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1007 | bitset<_Size>::any() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | { |
| 1009 | return base::any(); |
| 1010 | } |
| 1011 | |
| 1012 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 1013 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1015 | bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | { |
| 1017 | bitset __r = *this; |
| 1018 | __r <<= __pos; |
| 1019 | return __r; |
| 1020 | } |
| 1021 | |
| 1022 | template <size_t _Size> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 1023 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1025 | bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1026 | { |
| 1027 | bitset __r = *this; |
| 1028 | __r >>= __pos; |
| 1029 | return __r; |
| 1030 | } |
| 1031 | |
| 1032 | template <size_t _Size> |
| 1033 | inline _LIBCPP_INLINE_VISIBILITY |
| 1034 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1035 | operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1036 | { |
| 1037 | bitset<_Size> __r = __x; |
| 1038 | __r &= __y; |
| 1039 | return __r; |
| 1040 | } |
| 1041 | |
| 1042 | template <size_t _Size> |
| 1043 | inline _LIBCPP_INLINE_VISIBILITY |
| 1044 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1045 | operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1046 | { |
| 1047 | bitset<_Size> __r = __x; |
| 1048 | __r |= __y; |
| 1049 | return __r; |
| 1050 | } |
| 1051 | |
| 1052 | template <size_t _Size> |
| 1053 | inline _LIBCPP_INLINE_VISIBILITY |
| 1054 | bitset<_Size> |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1055 | operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | { |
| 1057 | bitset<_Size> __r = __x; |
| 1058 | __r ^= __y; |
| 1059 | return __r; |
| 1060 | } |
| 1061 | |
| 1062 | template <size_t _Size> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1063 | struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | : public unary_function<bitset<_Size>, size_t> |
| 1065 | { |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 1066 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 10f25d2 | 2011-05-27 20:52:28 +0000 | [diff] [blame] | 1067 | size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1068 | {return __bs.__hash_code();} |
| 1069 | }; |
| 1070 | |
Howard Hinnant | 464aa5c | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 1071 | template <class _CharT, class _Traits, size_t _Size> |
| 1072 | basic_istream<_CharT, _Traits>& |
| 1073 | operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); |
| 1074 | |
| 1075 | template <class _CharT, class _Traits, size_t _Size> |
| 1076 | basic_ostream<_CharT, _Traits>& |
| 1077 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); |
| 1078 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | _LIBCPP_END_NAMESPACE_STD |
| 1080 | |
| 1081 | #endif // _LIBCPP_BITSET |