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