blob: cd6c289b4c480b7b090c6a5b2b23eb4d09435eb6 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- bitset ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_BITSET
12#define _LIBCPP_BITSET
13
14/*
15 bitset synopsis
16
17namespace std
18{
19
20namespace std {
21
22template <size_t N>
23class bitset
24{
25public:
26 // bit reference:
27 class reference
28 {
29 friend class bitset;
Howard Hinnant10f25d22011-05-27 20:52:28 +000030 reference() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 public:
Howard Hinnant10f25d22011-05-27 20:52:28 +000032 ~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 Hinnantbc8d3f92010-05-11 19:42:16 +000038 };
39
40 // 23.3.5.1 constructors:
Howard Hinnant10f25d22011-05-27 20:52:28 +000041 constexpr bitset() noexcept;
42 constexpr bitset(unsigned long long val) noexcept;
Howard Hinnant34d6b192010-11-17 21:53:14 +000043 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 Hinnantbc8d3f92010-05-11 19:42:16 +000047 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 Hinnant10f25d22011-05-27 20:52:28 +000055 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 Hinnantbc8d3f92010-05-11 19:42:16 +000061 bitset& set(size_t pos, bool val = true);
Howard Hinnant10f25d22011-05-27 20:52:28 +000062 bitset& reset() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063 bitset& reset(size_t pos);
Howard Hinnant10f25d22011-05-27 20:52:28 +000064 bitset operator~() const noexcept;
65 bitset& flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066 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 Hinnant10f25d22011-05-27 20:52:28 +000080 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 Hinnantbc8d3f92010-05-11 19:42:16 +000084 bool test(size_t pos) const;
Howard Hinnant10f25d22011-05-27 20:52:28 +000085 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 Hinnantbc8d3f92010-05-11 19:42:16 +000090};
91
92// 23.3.5.3 bitset operators:
93template <size_t N>
Howard Hinnant10f25d22011-05-27 20:52:28 +000094bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095
96template <size_t N>
Howard Hinnant10f25d22011-05-27 20:52:28 +000097bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
99template <size_t N>
Howard Hinnant10f25d22011-05-27 20:52:28 +0000100bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101
102template <class charT, class traits, size_t N>
103basic_istream<charT, traits>&
104operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
105
106template <class charT, class traits, size_t N>
107basic_ostream<charT, traits>&
108operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
109
110template <size_t N> struct hash<std::bitset<N>>;
111
112} // std
113
114*/
115
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116#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 Hinnantbc8d3f92010-05-11 19:42:16 +0000124
Eric Fiselier018a3d52017-05-31 22:07:49 +0000125#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 Hinnant66c6f972011-11-29 16:45:27 +0000132
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133_LIBCPP_BEGIN_NAMESPACE_STD
134
135template <size_t _N_words, size_t _Size>
Howard Hinnantf03c3b42011-07-02 20:33:23 +0000136class __bitset;
137
138template <size_t _N_words, size_t _Size>
139struct __has_storage_type<__bitset<_N_words, _Size> >
140{
141 static const bool value = true;
142};
143
144template <size_t _N_words, size_t _Size>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145class __bitset
146{
147public:
148 typedef ptrdiff_t difference_type;
149 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000150 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151protected:
152 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153 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 Hinnant4ae952a2012-08-17 17:10:18 +0000161 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162
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 Stepanova3b25f82015-11-07 01:22:13 +0000170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000171 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000173 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000174
Howard Hinnant10f25d22011-05-27 20:52:28 +0000175 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000179 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000181 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
183
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000185 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000187 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000189 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190
Howard Hinnant10f25d22011-05-27 20:52:28 +0000191 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192 _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 Hinnant10f25d22011-05-27 20:52:28 +0000197 bool all() const _NOEXCEPT;
198 bool any() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000200 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201private:
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000202#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant10f25d22011-05-27 20:52:28 +0000203 void __init(unsigned long long __v, false_type) _NOEXCEPT;
Evgeniy Stepanov28c02db2015-12-09 22:32:36 +0000204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000205 void __init(unsigned long long __v, true_type) _NOEXCEPT;
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000206#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 unsigned long to_ulong(false_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209 unsigned long to_ulong(true_type) const;
210 unsigned long long to_ullong(false_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212 unsigned long long to_ullong(true_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214 unsigned long long to_ullong(true_type, false_type) const;
215 unsigned long long to_ullong(true_type, true_type) const;
216};
217
218template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000219inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000220_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000221__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000222#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant90d87232012-07-07 17:04:52 +0000223 : __first_{0}
224#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225{
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000226#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant0949eed2011-06-30 21:18:19 +0000227 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
Howard Hinnant90d87232012-07-07 17:04:52 +0000228#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000229}
230
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000231#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant90d87232012-07-07 17:04:52 +0000232
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233template <size_t _N_words, size_t _Size>
234void
Howard Hinnantec3773c2011-12-01 20:21:04 +0000235__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236{
237 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
Marshall Clow06f2e002017-11-27 22:27:22 +0000238 size_t __sz = _Size;
239 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
240 if ( __sz < __bits_per_word)
241 __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
242 else
243 __t[__i] = static_cast<__storage_type>(__v);
244
Howard Hinnant0949eed2011-06-30 21:18:19 +0000245 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
246 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247 __storage_type(0));
248}
249
250template <size_t _N_words, size_t _Size>
251inline _LIBCPP_INLINE_VISIBILITY
252void
Howard Hinnantec3773c2011-12-01 20:21:04 +0000253__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254{
255 __first_[0] = __v;
Marshall Clow06f2e002017-11-27 22:27:22 +0000256 if (_Size < __bits_per_word)
257 __first_[0] &= ( 1ULL << _Size ) - 1;
258
Howard Hinnant0949eed2011-06-30 21:18:19 +0000259 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260}
261
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000262#endif // _LIBCPP_CXX03_LANG
Howard Hinnant90d87232012-07-07 17:04:52 +0000263
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000265inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000266_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000267__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000268#ifndef _LIBCPP_CXX03_LANG
Nico Weber0211e862014-06-04 15:46:56 +0000269#if __SIZEOF_SIZE_T__ == 8
Howard Hinnant90d87232012-07-07 17:04:52 +0000270 : __first_{__v}
Nico Weber0211e862014-06-04 15:46:56 +0000271#elif __SIZEOF_SIZE_T__ == 4
Marshall Clow06f2e002017-11-27 22:27:22 +0000272 : __first_{static_cast<__storage_type>(__v),
273 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
274 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
Howard Hinnant31014742013-03-06 18:16:12 +0000275#else
Howard Hinnant11a31d02013-03-06 17:30:26 +0000276#error This constructor has not been ported to this platform
277#endif
Howard Hinnant90d87232012-07-07 17:04:52 +0000278#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279{
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000280#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
Howard Hinnant90d87232012-07-07 17:04:52 +0000282#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283}
284
285template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000286inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000288__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289{
290 for (size_type __i = 0; __i < _N_words; ++__i)
291 __first_[__i] &= __v.__first_[__i];
292}
293
294template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000295inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000297__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298{
299 for (size_type __i = 0; __i < _N_words; ++__i)
300 __first_[__i] |= __v.__first_[__i];
301}
302
303template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000304inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000306__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307{
308 for (size_type __i = 0; __i < _N_words; ++__i)
309 __first_[__i] ^= __v.__first_[__i];
310}
311
312template <size_t _N_words, size_t _Size>
313void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000314__bitset<_N_words, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315{
316 // do middle whole words
317 size_type __n = _Size;
318 __storage_pointer __p = __first_;
319 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
320 *__p = ~*__p;
321 // do last partial word
322 if (__n > 0)
323 {
324 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
325 __storage_type __b = *__p & __m;
326 *__p &= ~__m;
327 *__p |= ~__b & __m;
328 }
329}
330
331template <size_t _N_words, size_t _Size>
332unsigned long
333__bitset<_N_words, _Size>::to_ulong(false_type) const
334{
335 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000336 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337 if (__i != __e)
Marshall Clow14c09a22016-08-25 15:09:01 +0000338 __throw_overflow_error("bitset to_ulong overflow error");
339
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340 return __first_[0];
341}
342
343template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000344inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345unsigned long
346__bitset<_N_words, _Size>::to_ulong(true_type) const
347{
348 return __first_[0];
349}
350
351template <size_t _N_words, size_t _Size>
352unsigned long long
353__bitset<_N_words, _Size>::to_ullong(false_type) const
354{
355 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000356 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357 if (__i != __e)
Marshall Clow14c09a22016-08-25 15:09:01 +0000358 __throw_overflow_error("bitset to_ullong overflow error");
359
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360 return to_ullong(true_type());
361}
362
363template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000364inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365unsigned long long
366__bitset<_N_words, _Size>::to_ullong(true_type) const
367{
368 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
369}
370
371template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000372inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373unsigned long long
374__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
375{
376 return __first_[0];
377}
378
379template <size_t _N_words, size_t _Size>
380unsigned long long
381__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
382{
383 unsigned long long __r = __first_[0];
384 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
385 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
386 return __r;
387}
388
389template <size_t _N_words, size_t _Size>
390bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000391__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392{
393 // do middle whole words
394 size_type __n = _Size;
395 __const_storage_pointer __p = __first_;
396 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
397 if (~*__p)
398 return false;
399 // do last partial word
400 if (__n > 0)
401 {
402 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
403 if (~*__p & __m)
404 return false;
405 }
406 return true;
407}
408
409template <size_t _N_words, size_t _Size>
410bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000411__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412{
413 // do middle whole words
414 size_type __n = _Size;
415 __const_storage_pointer __p = __first_;
416 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
417 if (*__p)
418 return true;
419 // do last partial word
420 if (__n > 0)
421 {
422 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
423 if (*__p & __m)
424 return true;
425 }
426 return false;
427}
428
429template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000430inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000432__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433{
434 size_t __h = 0;
435 for (size_type __i = 0; __i < _N_words; ++__i)
436 __h ^= __first_[__i];
437 return __h;
438}
439
440template <size_t _Size>
441class __bitset<1, _Size>
442{
443public:
444 typedef ptrdiff_t difference_type;
445 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000446 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447protected:
448 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 typedef __storage_type* __storage_pointer;
450 typedef const __storage_type* __const_storage_pointer;
451 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
452
453 friend class __bit_reference<__bitset>;
454 friend class __bit_const_reference<__bitset>;
455 friend class __bit_iterator<__bitset, false>;
456 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +0000457 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458
459 __storage_type __first_;
460
461 typedef __bit_reference<__bitset> reference;
462 typedef __bit_const_reference<__bitset> const_reference;
463 typedef __bit_iterator<__bitset, false> iterator;
464 typedef __bit_iterator<__bitset, true> const_iterator;
465
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000467 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000469 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470
Howard Hinnant10f25d22011-05-27 20:52:28 +0000471 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000475 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000477 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
479
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000481 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000483 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000485 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000488 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 unsigned long long to_ullong() const;
494
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000496 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000498 bool any() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000501 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502};
503
504template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000505inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000506_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000507__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508 : __first_(0)
509{
510}
511
512template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000513inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000514_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000515__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Marshall Clow21edec72017-11-27 19:03:30 +0000516 : __first_(
517 _Size == __bits_per_word ? static_cast<__storage_type>(__v)
518 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
519 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520{
521}
522
523template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000524inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000526__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527{
528 __first_ &= __v.__first_;
529}
530
531template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000532inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000534__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535{
536 __first_ |= __v.__first_;
537}
538
539template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000540inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000542__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543{
544 __first_ ^= __v.__first_;
545}
546
547template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000548inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000550__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551{
552 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
553 __first_ = ~__first_;
554 __first_ &= __m;
555}
556
557template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000558inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559unsigned long
560__bitset<1, _Size>::to_ulong() const
561{
562 return __first_;
563}
564
565template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000566inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567unsigned long long
568__bitset<1, _Size>::to_ullong() const
569{
570 return __first_;
571}
572
573template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000574inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000576__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577{
578 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
579 return !(~__first_ & __m);
580}
581
582template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000583inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000585__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586{
587 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
588 return __first_ & __m;
589}
590
591template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000592inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000594__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595{
596 return __first_;
597}
598
599template <>
600class __bitset<0, 0>
601{
602public:
603 typedef ptrdiff_t difference_type;
604 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000605 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606protected:
607 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 typedef __storage_type* __storage_pointer;
609 typedef const __storage_type* __const_storage_pointer;
610 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
611
612 friend class __bit_reference<__bitset>;
613 friend class __bit_const_reference<__bitset>;
614 friend class __bit_iterator<__bitset, false>;
615 friend class __bit_iterator<__bitset, true>;
Howard Hinnantec3773c2011-12-01 20:21:04 +0000616 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617
618 typedef __bit_reference<__bitset> reference;
619 typedef __bit_const_reference<__bitset> const_reference;
620 typedef __bit_iterator<__bitset, false> iterator;
621 typedef __bit_iterator<__bitset, true> const_iterator;
622
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000624 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000626 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627
Howard Hinnant10f25d22011-05-27 20:52:28 +0000628 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629 {return reference(0, 1);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 {return const_reference(0, 1);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000632 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 {return iterator(0, 0);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000634 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 {return const_iterator(0, 0);}
636
Howard Hinnant10f25d22011-05-27 20:52:28 +0000637 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
638 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
639 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640
Howard Hinnant10f25d22011-05-27 20:52:28 +0000641 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642
643 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
644 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
645
Howard Hinnant10f25d22011-05-27 20:52:28 +0000646 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
647 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648
Howard Hinnant10f25d22011-05-27 20:52:28 +0000649 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650};
651
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000652inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000653_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000654__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655{
656}
657
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000658inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000659_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000660__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661{
662}
663
Eric Fiselierc3589a82017-01-04 23:56:00 +0000664template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
Eric Fiselier566bcb42016-04-21 22:54:21 +0000665template <size_t _Size> struct hash<bitset<_Size> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666
667template <size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000668class _LIBCPP_TEMPLATE_VIS bitset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
670{
Howard Hinnant11a31d02013-03-06 17:30:26 +0000671public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
673 typedef __bitset<__n_words, _Size> base;
674
Howard Hinnant324bb032010-08-22 00:02:43 +0000675public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 typedef typename base::reference reference;
677 typedef typename base::const_reference const_reference;
678
Howard Hinnant324bb032010-08-22 00:02:43 +0000679 // 23.3.5.1 constructors:
Howard Hinnant90d87232012-07-07 17:04:52 +0000680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
682 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Howard Hinnant34d6b192010-11-17 21:53:14 +0000683 template<class _CharT>
684 explicit bitset(const _CharT* __str,
685 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
686 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant324bb032010-08-22 00:02:43 +0000687 template<class _CharT, class _Traits, class _Allocator>
688 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
689 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
690 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant324bb032010-08-22 00:02:43 +0000692 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693
Howard Hinnant324bb032010-08-22 00:02:43 +0000694 // 23.3.5.2 bitset operations:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000696 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000698 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000700 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
701 bitset& operator<<=(size_t __pos) _NOEXCEPT;
702 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000704 bitset& set() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000705 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000707 bitset& reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000708 bitset& reset(size_t __pos);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000710 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000712 bitset& flip() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000713 bitset& flip(size_t __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714
Howard Hinnant324bb032010-08-22 00:02:43 +0000715 // element access:
Howard Hinnant90d87232012-07-07 17:04:52 +0000716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
717 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000720 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000722 unsigned long long to_ullong() const;
723 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000725 _CharT __one = _CharT('1')) const;
726 template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000729 _CharT __one = _CharT('1')) const;
730 template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000733 _CharT __one = _CharT('1')) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant324bb032010-08-22 00:02:43 +0000736 char __one = '1') const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000738 size_t count() const _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000741 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000743 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000744 bool test(size_t __pos) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000746 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000748 bool any() const _NOEXCEPT;
749 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000751 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000753 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754
755private:
756
Howard Hinnant422a53f2010-09-21 21:28:23 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000758 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759
760 friend struct hash<bitset>;
761};
762
763template <size_t _Size>
Howard Hinnant34d6b192010-11-17 21:53:14 +0000764template<class _CharT>
765bitset<_Size>::bitset(const _CharT* __str,
766 typename basic_string<_CharT>::size_type __n,
767 _CharT __zero, _CharT __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000769 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant34d6b192010-11-17 21:53:14 +0000771 if (__str[__i] != __zero && __str[__i] != __one)
Marshall Clow14c09a22016-08-25 15:09:01 +0000772 __throw_invalid_argument("bitset string ctor has invalid argument");
773
Howard Hinnant99968442011-11-29 18:15:50 +0000774 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000776 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 {
Howard Hinnant99968442011-11-29 18:15:50 +0000778 _CharT __c = __str[_Mp - 1 - __i];
Howard Hinnant34d6b192010-11-17 21:53:14 +0000779 if (__c == __zero)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 (*this)[__i] = false;
Howard Hinnant34d6b192010-11-17 21:53:14 +0000781 else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 (*this)[__i] = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000784 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000785}
786
787template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000788template<class _CharT, class _Traits, class _Allocator>
789bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
790 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
792 _CharT __zero, _CharT __one)
793{
794 if (__pos > __str.size())
Marshall Clow14c09a22016-08-25 15:09:01 +0000795 __throw_out_of_range("bitset string pos out of range");
796
Howard Hinnant0949eed2011-06-30 21:18:19 +0000797 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
799 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
Marshall Clow14c09a22016-08-25 15:09:01 +0000800 __throw_invalid_argument("bitset string ctor has invalid argument");
801
Howard Hinnant99968442011-11-29 18:15:50 +0000802 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000804 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 {
Howard Hinnant99968442011-11-29 18:15:50 +0000806 _CharT __c = __str[__pos + _Mp - 1 - __i];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 if (_Traits::eq(__c, __zero))
808 (*this)[__i] = false;
809 else
810 (*this)[__i] = true;
811 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000812 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813}
814
815template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000816inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000818bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819{
820 base::operator&=(__rhs);
821 return *this;
822}
823
824template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000825inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000827bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828{
829 base::operator|=(__rhs);
830 return *this;
831}
832
833template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000834inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000836bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837{
838 base::operator^=(__rhs);
839 return *this;
840}
841
842template <size_t _Size>
843bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000844bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000846 __pos = _VSTD::min(__pos, _Size);
847 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
848 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 return *this;
850}
851
852template <size_t _Size>
853bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000854bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000856 __pos = _VSTD::min(__pos, _Size);
857 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
858 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 return *this;
860}
861
862template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000863inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000865bitset<_Size>::set() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000867 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 return *this;
869}
870
871template <size_t _Size>
872bitset<_Size>&
873bitset<_Size>::set(size_t __pos, bool __val)
874{
875 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000876 __throw_out_of_range("bitset set argument out of range");
877
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 (*this)[__pos] = __val;
879 return *this;
880}
881
882template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000883inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000885bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000887 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 return *this;
889}
890
891template <size_t _Size>
892bitset<_Size>&
893bitset<_Size>::reset(size_t __pos)
894{
895 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000896 __throw_out_of_range("bitset reset argument out of range");
897
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898 (*this)[__pos] = false;
899 return *this;
900}
901
902template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000903inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +0000905bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906{
907 bitset __x(*this);
908 __x.flip();
909 return __x;
910}
911
912template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000913inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000915bitset<_Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916{
917 base::flip();
918 return *this;
919}
920
921template <size_t _Size>
922bitset<_Size>&
923bitset<_Size>::flip(size_t __pos)
924{
925 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000926 __throw_out_of_range("bitset flip argument out of range");
927
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 reference r = base::__make_ref(__pos);
929 r = ~r;
930 return *this;
931}
932
933template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000934inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935unsigned long
936bitset<_Size>::to_ulong() const
937{
938 return base::to_ulong();
939}
940
941template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000942inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943unsigned long long
944bitset<_Size>::to_ullong() const
945{
946 return base::to_ullong();
947}
948
949template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000950template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951basic_string<_CharT, _Traits, _Allocator>
952bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
953{
954 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
955 for (size_t __i = 0; __i < _Size; ++__i)
956 {
957 if ((*this)[__i])
958 __r[_Size - 1 - __i] = __one;
959 }
960 return __r;
961}
962
963template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000964template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000965inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966basic_string<_CharT, _Traits, allocator<_CharT> >
967bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
968{
969 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
970}
971
972template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000973template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000974inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
976bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
977{
978 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
979}
980
981template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000982inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983basic_string<char, char_traits<char>, allocator<char> >
984bitset<_Size>::to_string(char __zero, char __one) const
985{
986 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
987}
988
989template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000990inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000992bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000994 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995}
996
997template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000998inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001000bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001001{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001002 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003}
1004
1005template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001006inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001008bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001009{
1010 return !(*this == __rhs);
1011}
1012
1013template <size_t _Size>
1014bool
1015bitset<_Size>::test(size_t __pos) const
1016{
1017 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +00001018 __throw_out_of_range("bitset test argument out of range");
1019
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 return (*this)[__pos];
1021}
1022
1023template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001024inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001026bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027{
1028 return base::all();
1029}
1030
1031template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001032inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001034bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035{
1036 return base::any();
1037}
1038
1039template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001040inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001042bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043{
1044 bitset __r = *this;
1045 __r <<= __pos;
1046 return __r;
1047}
1048
1049template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001050inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001052bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053{
1054 bitset __r = *this;
1055 __r >>= __pos;
1056 return __r;
1057}
1058
1059template <size_t _Size>
1060inline _LIBCPP_INLINE_VISIBILITY
1061bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001062operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063{
1064 bitset<_Size> __r = __x;
1065 __r &= __y;
1066 return __r;
1067}
1068
1069template <size_t _Size>
1070inline _LIBCPP_INLINE_VISIBILITY
1071bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001072operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073{
1074 bitset<_Size> __r = __x;
1075 __r |= __y;
1076 return __r;
1077}
1078
1079template <size_t _Size>
1080inline _LIBCPP_INLINE_VISIBILITY
1081bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001082operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
1084 bitset<_Size> __r = __x;
1085 __r ^= __y;
1086 return __r;
1087}
1088
1089template <size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001090struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 : public unary_function<bitset<_Size>, size_t>
1092{
Howard Hinnant422a53f2010-09-21 21:28:23 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +00001094 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 {return __bs.__hash_code();}
1096};
1097
Howard Hinnant464aa5c2011-07-18 15:51:59 +00001098template <class _CharT, class _Traits, size_t _Size>
1099basic_istream<_CharT, _Traits>&
1100operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1101
1102template <class _CharT, class _Traits, size_t _Size>
1103basic_ostream<_CharT, _Traits>&
1104operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1105
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106_LIBCPP_END_NAMESPACE_STD
1107
Eric Fiselier018a3d52017-05-31 22:07:49 +00001108_LIBCPP_POP_MACROS
1109
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110#endif // _LIBCPP_BITSET