blob: e26e674dd33f648b71ab3797905960ee20907ac0 [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)];
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 Hinnant0949eed2011-06-30 21:18:19 +0000240 _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 Hinnantbc8d3f92010-05-11 19:42:16 +0000242 __storage_type(0));
243}
244
245template <size_t _N_words, size_t _Size>
246inline _LIBCPP_INLINE_VISIBILITY
247void
Howard Hinnantec3773c2011-12-01 20:21:04 +0000248__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249{
250 __first_[0] = __v;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000251 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252}
253
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000254#endif // _LIBCPP_CXX03_LANG
Howard Hinnant90d87232012-07-07 17:04:52 +0000255
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000257inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000258_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000259__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000260#ifndef _LIBCPP_CXX03_LANG
Nico Weber0211e862014-06-04 15:46:56 +0000261#if __SIZEOF_SIZE_T__ == 8
Howard Hinnant90d87232012-07-07 17:04:52 +0000262 : __first_{__v}
Nico Weber0211e862014-06-04 15:46:56 +0000263#elif __SIZEOF_SIZE_T__ == 4
Dimitry Andric5f8cb582016-09-02 21:02:11 +0000264 : __first_{static_cast<__storage_type>(__v), static_cast<__storage_type>(__v >> __bits_per_word)}
Howard Hinnant31014742013-03-06 18:16:12 +0000265#else
Howard Hinnant11a31d02013-03-06 17:30:26 +0000266#error This constructor has not been ported to this platform
267#endif
Howard Hinnant90d87232012-07-07 17:04:52 +0000268#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269{
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000270#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
Howard Hinnant90d87232012-07-07 17:04:52 +0000272#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273}
274
275template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000276inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000278__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279{
280 for (size_type __i = 0; __i < _N_words; ++__i)
281 __first_[__i] &= __v.__first_[__i];
282}
283
284template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000285inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000287__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288{
289 for (size_type __i = 0; __i < _N_words; ++__i)
290 __first_[__i] |= __v.__first_[__i];
291}
292
293template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000294inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000296__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297{
298 for (size_type __i = 0; __i < _N_words; ++__i)
299 __first_[__i] ^= __v.__first_[__i];
300}
301
302template <size_t _N_words, size_t _Size>
303void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000304__bitset<_N_words, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305{
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
321template <size_t _N_words, size_t _Size>
322unsigned long
323__bitset<_N_words, _Size>::to_ulong(false_type) const
324{
325 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000326 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 if (__i != __e)
Marshall Clow14c09a22016-08-25 15:09:01 +0000328 __throw_overflow_error("bitset to_ulong overflow error");
329
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330 return __first_[0];
331}
332
333template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000334inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335unsigned long
336__bitset<_N_words, _Size>::to_ulong(true_type) const
337{
338 return __first_[0];
339}
340
341template <size_t _N_words, size_t _Size>
342unsigned long long
343__bitset<_N_words, _Size>::to_ullong(false_type) const
344{
345 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000346 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347 if (__i != __e)
Marshall Clow14c09a22016-08-25 15:09:01 +0000348 __throw_overflow_error("bitset to_ullong overflow error");
349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350 return to_ullong(true_type());
351}
352
353template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000354inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355unsigned 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
361template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000362inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363unsigned long long
364__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
365{
366 return __first_[0];
367}
368
369template <size_t _N_words, size_t _Size>
370unsigned 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
379template <size_t _N_words, size_t _Size>
380bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000381__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382{
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
399template <size_t _N_words, size_t _Size>
400bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000401__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402{
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
419template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000420inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000422__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423{
424 size_t __h = 0;
425 for (size_type __i = 0; __i < _N_words; ++__i)
426 __h ^= __first_[__i];
427 return __h;
428}
429
430template <size_t _Size>
431class __bitset<1, _Size>
432{
433public:
434 typedef ptrdiff_t difference_type;
435 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000436 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437protected:
438 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 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 Hinnant4ae952a2012-08-17 17:10:18 +0000447 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448
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 Stepanova3b25f82015-11-07 01:22:13 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000457 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000459 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460
Howard Hinnant10f25d22011-05-27 20:52:28 +0000461 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000463 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000465 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000467 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
469
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000471 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000473 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000475 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000478 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483 unsigned long long to_ullong() const;
484
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000486 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000488 bool any() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000491 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492};
493
494template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000495inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000496_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000497__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 : __first_(0)
499{
500}
501
502template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000503inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000504_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000505__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Marshall Clow21edec72017-11-27 19:03:30 +0000506 : __first_(
507 _Size == __bits_per_word ? static_cast<__storage_type>(__v)
508 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
509 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510{
511}
512
513template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000514inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000516__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517{
518 __first_ &= __v.__first_;
519}
520
521template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000522inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000524__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525{
526 __first_ |= __v.__first_;
527}
528
529template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000530inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000532__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533{
534 __first_ ^= __v.__first_;
535}
536
537template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000538inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000540__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541{
542 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
543 __first_ = ~__first_;
544 __first_ &= __m;
545}
546
547template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000548inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549unsigned long
550__bitset<1, _Size>::to_ulong() const
551{
552 return __first_;
553}
554
555template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000556inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557unsigned long long
558__bitset<1, _Size>::to_ullong() const
559{
560 return __first_;
561}
562
563template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000564inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000566__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567{
568 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
569 return !(~__first_ & __m);
570}
571
572template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000573inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000575__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576{
577 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
578 return __first_ & __m;
579}
580
581template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000582inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000584__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585{
586 return __first_;
587}
588
589template <>
590class __bitset<0, 0>
591{
592public:
593 typedef ptrdiff_t difference_type;
594 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000595 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596protected:
597 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598 typedef __storage_type* __storage_pointer;
599 typedef const __storage_type* __const_storage_pointer;
600 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
601
602 friend class __bit_reference<__bitset>;
603 friend class __bit_const_reference<__bitset>;
604 friend class __bit_iterator<__bitset, false>;
605 friend class __bit_iterator<__bitset, true>;
Howard Hinnantec3773c2011-12-01 20:21:04 +0000606 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607
608 typedef __bit_reference<__bitset> reference;
609 typedef __bit_const_reference<__bitset> const_reference;
610 typedef __bit_iterator<__bitset, false> iterator;
611 typedef __bit_iterator<__bitset, true> const_iterator;
612
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000614 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000616 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617
Howard Hinnant10f25d22011-05-27 20:52:28 +0000618 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 {return reference(0, 1);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000620 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621 {return const_reference(0, 1);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000622 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 {return iterator(0, 0);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000624 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 {return const_iterator(0, 0);}
626
Howard Hinnant10f25d22011-05-27 20:52:28 +0000627 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
628 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
629 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630
Howard Hinnant10f25d22011-05-27 20:52:28 +0000631 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632
633 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
634 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
635
Howard Hinnant10f25d22011-05-27 20:52:28 +0000636 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
637 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638
Howard Hinnant10f25d22011-05-27 20:52:28 +0000639 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640};
641
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000642inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000643_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000644__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645{
646}
647
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000648inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000649_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000650__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651{
652}
653
Eric Fiselierc3589a82017-01-04 23:56:00 +0000654template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
Eric Fiselier566bcb42016-04-21 22:54:21 +0000655template <size_t _Size> struct hash<bitset<_Size> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656
657template <size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000658class _LIBCPP_TEMPLATE_VIS bitset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
660{
Howard Hinnant11a31d02013-03-06 17:30:26 +0000661public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
663 typedef __bitset<__n_words, _Size> base;
664
Howard Hinnant324bb032010-08-22 00:02:43 +0000665public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 typedef typename base::reference reference;
667 typedef typename base::const_reference const_reference;
668
Howard Hinnant324bb032010-08-22 00:02:43 +0000669 // 23.3.5.1 constructors:
Howard Hinnant90d87232012-07-07 17:04:52 +0000670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
671 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
672 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Howard Hinnant34d6b192010-11-17 21:53:14 +0000673 template<class _CharT>
674 explicit bitset(const _CharT* __str,
675 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
676 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant324bb032010-08-22 00:02:43 +0000677 template<class _CharT, class _Traits, class _Allocator>
678 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
679 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
680 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant324bb032010-08-22 00:02:43 +0000682 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683
Howard Hinnant324bb032010-08-22 00:02:43 +0000684 // 23.3.5.2 bitset operations:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000686 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000688 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000690 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
691 bitset& operator<<=(size_t __pos) _NOEXCEPT;
692 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000694 bitset& set() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000695 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000697 bitset& reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000698 bitset& reset(size_t __pos);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000700 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000702 bitset& flip() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000703 bitset& flip(size_t __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704
Howard Hinnant324bb032010-08-22 00:02:43 +0000705 // element access:
Howard Hinnant90d87232012-07-07 17:04:52 +0000706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
707 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000710 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000712 unsigned long long to_ullong() const;
713 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000715 _CharT __one = _CharT('1')) const;
716 template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000719 _CharT __one = _CharT('1')) const;
720 template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000723 _CharT __one = _CharT('1')) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant324bb032010-08-22 00:02:43 +0000726 char __one = '1') const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000728 size_t count() const _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000729 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000731 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000733 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000734 bool test(size_t __pos) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000736 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000738 bool any() const _NOEXCEPT;
739 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000741 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000743 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744
745private:
746
Howard Hinnant422a53f2010-09-21 21:28:23 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000748 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749
750 friend struct hash<bitset>;
751};
752
753template <size_t _Size>
Howard Hinnant34d6b192010-11-17 21:53:14 +0000754template<class _CharT>
755bitset<_Size>::bitset(const _CharT* __str,
756 typename basic_string<_CharT>::size_type __n,
757 _CharT __zero, _CharT __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000759 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant34d6b192010-11-17 21:53:14 +0000761 if (__str[__i] != __zero && __str[__i] != __one)
Marshall Clow14c09a22016-08-25 15:09:01 +0000762 __throw_invalid_argument("bitset string ctor has invalid argument");
763
Howard Hinnant99968442011-11-29 18:15:50 +0000764 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000766 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 {
Howard Hinnant99968442011-11-29 18:15:50 +0000768 _CharT __c = __str[_Mp - 1 - __i];
Howard Hinnant34d6b192010-11-17 21:53:14 +0000769 if (__c == __zero)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 (*this)[__i] = false;
Howard Hinnant34d6b192010-11-17 21:53:14 +0000771 else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 (*this)[__i] = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000774 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775}
776
777template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000778template<class _CharT, class _Traits, class _Allocator>
779bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
780 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
782 _CharT __zero, _CharT __one)
783{
784 if (__pos > __str.size())
Marshall Clow14c09a22016-08-25 15:09:01 +0000785 __throw_out_of_range("bitset string pos out of range");
786
Howard Hinnant0949eed2011-06-30 21:18:19 +0000787 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
789 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
Marshall Clow14c09a22016-08-25 15:09:01 +0000790 __throw_invalid_argument("bitset string ctor has invalid argument");
791
Howard Hinnant99968442011-11-29 18:15:50 +0000792 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000794 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 {
Howard Hinnant99968442011-11-29 18:15:50 +0000796 _CharT __c = __str[__pos + _Mp - 1 - __i];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797 if (_Traits::eq(__c, __zero))
798 (*this)[__i] = false;
799 else
800 (*this)[__i] = true;
801 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000802 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803}
804
805template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000806inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000808bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809{
810 base::operator&=(__rhs);
811 return *this;
812}
813
814template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000815inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000817bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818{
819 base::operator|=(__rhs);
820 return *this;
821}
822
823template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000824inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000826bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827{
828 base::operator^=(__rhs);
829 return *this;
830}
831
832template <size_t _Size>
833bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000834bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000836 __pos = _VSTD::min(__pos, _Size);
837 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
838 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 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(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
848 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 return *this;
850}
851
852template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000853inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000855bitset<_Size>::set() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000857 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 return *this;
859}
860
861template <size_t _Size>
862bitset<_Size>&
863bitset<_Size>::set(size_t __pos, bool __val)
864{
865 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000866 __throw_out_of_range("bitset set argument out of range");
867
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 (*this)[__pos] = __val;
869 return *this;
870}
871
872template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000873inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000875bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000877 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 return *this;
879}
880
881template <size_t _Size>
882bitset<_Size>&
883bitset<_Size>::reset(size_t __pos)
884{
885 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000886 __throw_out_of_range("bitset reset argument out of range");
887
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 (*this)[__pos] = false;
889 return *this;
890}
891
892template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000893inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +0000895bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896{
897 bitset __x(*this);
898 __x.flip();
899 return __x;
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>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906{
907 base::flip();
908 return *this;
909}
910
911template <size_t _Size>
912bitset<_Size>&
913bitset<_Size>::flip(size_t __pos)
914{
915 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000916 __throw_out_of_range("bitset flip argument out of range");
917
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 reference r = base::__make_ref(__pos);
919 r = ~r;
920 return *this;
921}
922
923template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000924inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925unsigned long
926bitset<_Size>::to_ulong() const
927{
928 return base::to_ulong();
929}
930
931template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000932inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933unsigned long long
934bitset<_Size>::to_ullong() const
935{
936 return base::to_ullong();
937}
938
939template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000940template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941basic_string<_CharT, _Traits, _Allocator>
942bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
943{
944 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
945 for (size_t __i = 0; __i < _Size; ++__i)
946 {
947 if ((*this)[__i])
948 __r[_Size - 1 - __i] = __one;
949 }
950 return __r;
951}
952
953template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000954template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000955inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956basic_string<_CharT, _Traits, allocator<_CharT> >
957bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
958{
959 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
960}
961
962template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000963template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000964inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
966bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
967{
968 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
969}
970
971template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000972inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973basic_string<char, char_traits<char>, allocator<char> >
974bitset<_Size>::to_string(char __zero, char __one) const
975{
976 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
977}
978
979template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000980inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000982bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000984 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985}
986
987template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000988inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000990bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000992 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993}
994
995template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000996inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000998bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999{
1000 return !(*this == __rhs);
1001}
1002
1003template <size_t _Size>
1004bool
1005bitset<_Size>::test(size_t __pos) const
1006{
1007 if (__pos >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +00001008 __throw_out_of_range("bitset test argument out of range");
1009
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 return (*this)[__pos];
1011}
1012
1013template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001014inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001016bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017{
1018 return base::all();
1019}
1020
1021template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001022inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001024bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025{
1026 return base::any();
1027}
1028
1029template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001030inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001032bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033{
1034 bitset __r = *this;
1035 __r <<= __pos;
1036 return __r;
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>
1050inline _LIBCPP_INLINE_VISIBILITY
1051bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001052operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053{
1054 bitset<_Size> __r = __x;
1055 __r &= __y;
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>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001080struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 : public unary_function<bitset<_Size>, size_t>
1082{
Howard Hinnant422a53f2010-09-21 21:28:23 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +00001084 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 {return __bs.__hash_code();}
1086};
1087
Howard Hinnant464aa5c2011-07-18 15:51:59 +00001088template <class _CharT, class _Traits, size_t _Size>
1089basic_istream<_CharT, _Traits>&
1090operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1091
1092template <class _CharT, class _Traits, size_t _Size>
1093basic_ostream<_CharT, _Traits>&
1094operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1095
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096_LIBCPP_END_NAMESPACE_STD
1097
Eric Fiselier018a3d52017-05-31 22:07:49 +00001098_LIBCPP_POP_MACROS
1099
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100#endif // _LIBCPP_BITSET