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