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