blob: b7d95a811f38e571455e5c508ad9b4e0a99e7370 [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 Hinnant08e17472011-10-17 20:05:10 +0000116#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000118#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000119
120#include <__config>
121#include <__bit_reference>
122#include <cstddef>
123#include <climits>
124#include <string>
125#include <stdexcept>
126#include <iosfwd>
127#include <__functional_base>
128#if defined(_LIBCPP_NO_EXCEPTIONS)
129 #include <cassert>
130#endif
131
Howard Hinnant66c6f972011-11-29 16:45:27 +0000132#include <__undef_min_max>
133
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134_LIBCPP_BEGIN_NAMESPACE_STD
135
136template <size_t _N_words, size_t _Size>
Howard Hinnantf03c3b42011-07-02 20:33:23 +0000137class __bitset;
138
139template <size_t _N_words, size_t _Size>
140struct __has_storage_type<__bitset<_N_words, _Size> >
141{
142 static const bool value = true;
143};
144
145template <size_t _N_words, size_t _Size>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146class __bitset
147{
148public:
149 typedef ptrdiff_t difference_type;
150 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000151 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152protected:
153 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154 typedef __storage_type* __storage_pointer;
155 typedef const __storage_type* __const_storage_pointer;
156 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
157
158 friend class __bit_reference<__bitset>;
159 friend class __bit_const_reference<__bitset>;
160 friend class __bit_iterator<__bitset, false>;
161 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +0000162 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163
164 __storage_type __first_[_N_words];
165
166 typedef __bit_reference<__bitset> reference;
167 typedef __bit_const_reference<__bitset> const_reference;
168 typedef __bit_iterator<__bitset, false> iterator;
169 typedef __bit_iterator<__bitset, true> const_iterator;
170
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000172 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000174 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175
Howard Hinnant10f25d22011-05-27 20:52:28 +0000176 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000178 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000180 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000182 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
184
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000186 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000188 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000190 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191
Howard Hinnant10f25d22011-05-27 20:52:28 +0000192 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
194 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
195 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
196 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
197
Howard Hinnant10f25d22011-05-27 20:52:28 +0000198 bool all() const _NOEXCEPT;
199 bool any() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000201 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202private:
Howard Hinnant90d87232012-07-07 17:04:52 +0000203#ifdef _LIBCPP_HAS_NO_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000204 void __init(unsigned long long __v, false_type) _NOEXCEPT;
205 void __init(unsigned long long __v, true_type) _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000206#endif // _LIBCPP_HAS_NO_CONSTEXPR
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
Howard Hinnant90d87232012-07-07 17:04:52 +0000222#ifndef _LIBCPP_HAS_NO_CONSTEXPR
223 : __first_{0}
224#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225{
Howard Hinnant90d87232012-07-07 17:04:52 +0000226#ifdef _LIBCPP_HAS_NO_CONSTEXPR
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
Howard Hinnant90d87232012-07-07 17:04:52 +0000231#ifdef _LIBCPP_HAS_NO_CONSTEXPR
232
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
Howard Hinnant90d87232012-07-07 17:04:52 +0000254#endif // _LIBCPP_HAS_NO_CONSTEXPR
255
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
Howard Hinnant90d87232012-07-07 17:04:52 +0000260#ifndef _LIBCPP_HAS_NO_CONSTEXPR
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
Howard Hinnant11a31d02013-03-06 17:30:26 +0000264 : __first_{__v, __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{
Howard Hinnant90d87232012-07-07 17:04:52 +0000270#ifdef _LIBCPP_HAS_NO_CONSTEXPR
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)
328#ifndef _LIBCPP_NO_EXCEPTIONS
329 throw overflow_error("bitset to_ulong overflow error");
330#else
331 assert(!"bitset to_ulong overflow error");
332#endif
333 return __first_[0];
334}
335
336template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000337inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338unsigned long
339__bitset<_N_words, _Size>::to_ulong(true_type) const
340{
341 return __first_[0];
342}
343
344template <size_t _N_words, size_t _Size>
345unsigned long long
346__bitset<_N_words, _Size>::to_ullong(false_type) const
347{
348 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000349 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350 if (__i != __e)
351#ifndef _LIBCPP_NO_EXCEPTIONS
352 throw overflow_error("bitset to_ullong overflow error");
353#else
354 assert(!"bitset to_ullong overflow error");
355#endif
356 return to_ullong(true_type());
357}
358
359template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000360inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361unsigned long long
362__bitset<_N_words, _Size>::to_ullong(true_type) const
363{
364 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
365}
366
367template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000368inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369unsigned long long
370__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
371{
372 return __first_[0];
373}
374
375template <size_t _N_words, size_t _Size>
376unsigned long long
377__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
378{
379 unsigned long long __r = __first_[0];
380 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
381 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
382 return __r;
383}
384
385template <size_t _N_words, size_t _Size>
386bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000387__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388{
389 // do middle whole words
390 size_type __n = _Size;
391 __const_storage_pointer __p = __first_;
392 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
393 if (~*__p)
394 return false;
395 // do last partial word
396 if (__n > 0)
397 {
398 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
399 if (~*__p & __m)
400 return false;
401 }
402 return true;
403}
404
405template <size_t _N_words, size_t _Size>
406bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000407__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408{
409 // do middle whole words
410 size_type __n = _Size;
411 __const_storage_pointer __p = __first_;
412 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
413 if (*__p)
414 return true;
415 // do last partial word
416 if (__n > 0)
417 {
418 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
419 if (*__p & __m)
420 return true;
421 }
422 return false;
423}
424
425template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000426inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000428__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429{
430 size_t __h = 0;
431 for (size_type __i = 0; __i < _N_words; ++__i)
432 __h ^= __first_[__i];
433 return __h;
434}
435
436template <size_t _Size>
437class __bitset<1, _Size>
438{
439public:
440 typedef ptrdiff_t difference_type;
441 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000442 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443protected:
444 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 typedef __storage_type* __storage_pointer;
446 typedef const __storage_type* __const_storage_pointer;
447 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
448
449 friend class __bit_reference<__bitset>;
450 friend class __bit_const_reference<__bitset>;
451 friend class __bit_iterator<__bitset, false>;
452 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +0000453 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454
455 __storage_type __first_;
456
457 typedef __bit_reference<__bitset> reference;
458 typedef __bit_const_reference<__bitset> const_reference;
459 typedef __bit_iterator<__bitset, false> iterator;
460 typedef __bit_iterator<__bitset, true> const_iterator;
461
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000463 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000465 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466
Howard Hinnant10f25d22011-05-27 20:52:28 +0000467 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000471 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000473 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
475
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000477 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000479 void operator|=(const __bitset& __v) _NOEXCEPT;
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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000484 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 unsigned long long to_ullong() const;
490
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000492 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000494 bool any() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000497 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498};
499
500template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000501inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000502_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000503__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 : __first_(0)
505{
506}
507
508template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000509inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000510_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000511__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 : __first_(static_cast<__storage_type>(__v))
513{
514}
515
516template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000517inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000519__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520{
521 __first_ &= __v.__first_;
522}
523
524template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000525inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000527__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528{
529 __first_ |= __v.__first_;
530}
531
532template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000533inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000535__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536{
537 __first_ ^= __v.__first_;
538}
539
540template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000541inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000543__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544{
545 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
546 __first_ = ~__first_;
547 __first_ &= __m;
548}
549
550template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000551inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552unsigned long
553__bitset<1, _Size>::to_ulong() const
554{
555 return __first_;
556}
557
558template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000559inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560unsigned long long
561__bitset<1, _Size>::to_ullong() const
562{
563 return __first_;
564}
565
566template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000567inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000569__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570{
571 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
572 return !(~__first_ & __m);
573}
574
575template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000576inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000578__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579{
580 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
581 return __first_ & __m;
582}
583
584template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000585inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000587__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588{
589 return __first_;
590}
591
592template <>
593class __bitset<0, 0>
594{
595public:
596 typedef ptrdiff_t difference_type;
597 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000598 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599protected:
600 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601 typedef __storage_type* __storage_pointer;
602 typedef const __storage_type* __const_storage_pointer;
603 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
604
605 friend class __bit_reference<__bitset>;
606 friend class __bit_const_reference<__bitset>;
607 friend class __bit_iterator<__bitset, false>;
608 friend class __bit_iterator<__bitset, true>;
Howard Hinnantec3773c2011-12-01 20:21:04 +0000609 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610
611 typedef __bit_reference<__bitset> reference;
612 typedef __bit_const_reference<__bitset> const_reference;
613 typedef __bit_iterator<__bitset, false> iterator;
614 typedef __bit_iterator<__bitset, true> const_iterator;
615
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000617 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000619 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620
Howard Hinnant10f25d22011-05-27 20:52:28 +0000621 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622 {return reference(0, 1);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000623 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 {return const_reference(0, 1);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000625 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626 {return iterator(0, 0);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000627 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 {return const_iterator(0, 0);}
629
Howard Hinnant10f25d22011-05-27 20:52:28 +0000630 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
631 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
632 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633
Howard Hinnant10f25d22011-05-27 20:52:28 +0000634 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635
636 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
637 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
638
Howard Hinnant10f25d22011-05-27 20:52:28 +0000639 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
640 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641
Howard Hinnant10f25d22011-05-27 20:52:28 +0000642 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643};
644
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000645inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000646_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000647__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648{
649}
650
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000651inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000652_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000653__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654{
655}
656
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000657template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset;
658template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659
660template <size_t _Size>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000661class _LIBCPP_TYPE_VIS_ONLY bitset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
663{
Howard Hinnant11a31d02013-03-06 17:30:26 +0000664public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
666 typedef __bitset<__n_words, _Size> base;
667
Howard Hinnant324bb032010-08-22 00:02:43 +0000668public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669 typedef typename base::reference reference;
670 typedef typename base::const_reference const_reference;
671
Howard Hinnant324bb032010-08-22 00:02:43 +0000672 // 23.3.5.1 constructors:
Howard Hinnant90d87232012-07-07 17:04:52 +0000673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
675 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Howard Hinnant34d6b192010-11-17 21:53:14 +0000676 template<class _CharT>
677 explicit bitset(const _CharT* __str,
678 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
679 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant324bb032010-08-22 00:02:43 +0000680 template<class _CharT, class _Traits, class _Allocator>
681 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
682 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
683 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant324bb032010-08-22 00:02:43 +0000685 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686
Howard Hinnant324bb032010-08-22 00:02:43 +0000687 // 23.3.5.2 bitset operations:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000689 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000691 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000693 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
694 bitset& operator<<=(size_t __pos) _NOEXCEPT;
695 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000697 bitset& set() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000698 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000700 bitset& reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000701 bitset& reset(size_t __pos);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000703 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000705 bitset& flip() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000706 bitset& flip(size_t __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707
Howard Hinnant324bb032010-08-22 00:02:43 +0000708 // element access:
Howard Hinnant90d87232012-07-07 17:04:52 +0000709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
710 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000713 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000715 unsigned long long to_ullong() const;
716 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000718 _CharT __one = _CharT('1')) const;
719 template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000722 _CharT __one = _CharT('1')) const;
723 template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000726 _CharT __one = _CharT('1')) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant324bb032010-08-22 00:02:43 +0000729 char __one = '1') const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000731 size_t count() const _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000734 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000736 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000737 bool test(size_t __pos) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000739 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000741 bool any() const _NOEXCEPT;
742 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000744 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000746 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747
748private:
749
Howard Hinnant422a53f2010-09-21 21:28:23 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000751 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752
753 friend struct hash<bitset>;
754};
755
756template <size_t _Size>
Howard Hinnant34d6b192010-11-17 21:53:14 +0000757template<class _CharT>
758bitset<_Size>::bitset(const _CharT* __str,
759 typename basic_string<_CharT>::size_type __n,
760 _CharT __zero, _CharT __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000762 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant34d6b192010-11-17 21:53:14 +0000764 if (__str[__i] != __zero && __str[__i] != __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765#ifndef _LIBCPP_NO_EXCEPTIONS
766 throw invalid_argument("bitset string ctor has invalid argument");
767#else
768 assert(!"bitset string ctor has invalid argument");
769#endif
Howard Hinnant99968442011-11-29 18:15:50 +0000770 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000772 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773 {
Howard Hinnant99968442011-11-29 18:15:50 +0000774 _CharT __c = __str[_Mp - 1 - __i];
Howard Hinnant34d6b192010-11-17 21:53:14 +0000775 if (__c == __zero)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 (*this)[__i] = false;
Howard Hinnant34d6b192010-11-17 21:53:14 +0000777 else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778 (*this)[__i] = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000780 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781}
782
783template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000784template<class _CharT, class _Traits, class _Allocator>
785bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
786 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
788 _CharT __zero, _CharT __one)
789{
790 if (__pos > __str.size())
791#ifndef _LIBCPP_NO_EXCEPTIONS
792 throw out_of_range("bitset string pos out of range");
793#else
794 assert(!"bitset string pos out of range");
795#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +0000796 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
798 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
799#ifndef _LIBCPP_NO_EXCEPTIONS
800 throw invalid_argument("bitset string ctor has invalid argument");
801#else
802 assert(!"bitset string ctor has invalid argument");
803#endif
Howard Hinnant99968442011-11-29 18:15:50 +0000804 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000806 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 {
Howard Hinnant99968442011-11-29 18:15:50 +0000808 _CharT __c = __str[__pos + _Mp - 1 - __i];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 if (_Traits::eq(__c, __zero))
810 (*this)[__i] = false;
811 else
812 (*this)[__i] = true;
813 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000814 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815}
816
817template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000818inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000820bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821{
822 base::operator&=(__rhs);
823 return *this;
824}
825
826template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000827inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000829bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830{
831 base::operator|=(__rhs);
832 return *this;
833}
834
835template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000836inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000838bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839{
840 base::operator^=(__rhs);
841 return *this;
842}
843
844template <size_t _Size>
845bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000846bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000848 __pos = _VSTD::min(__pos, _Size);
849 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
850 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 return *this;
852}
853
854template <size_t _Size>
855bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000856bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000858 __pos = _VSTD::min(__pos, _Size);
859 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
860 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 return *this;
862}
863
864template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000865inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000867bitset<_Size>::set() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000869 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 return *this;
871}
872
873template <size_t _Size>
874bitset<_Size>&
875bitset<_Size>::set(size_t __pos, bool __val)
876{
877 if (__pos >= _Size)
878#ifndef _LIBCPP_NO_EXCEPTIONS
879 throw out_of_range("bitset set argument out of range");
880#else
881 assert(!"bitset set argument out of range");
882#endif
883 (*this)[__pos] = __val;
884 return *this;
885}
886
887template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000888inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000890bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000892 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 return *this;
894}
895
896template <size_t _Size>
897bitset<_Size>&
898bitset<_Size>::reset(size_t __pos)
899{
900 if (__pos >= _Size)
901#ifndef _LIBCPP_NO_EXCEPTIONS
902 throw out_of_range("bitset reset argument out of range");
903#else
904 assert(!"bitset reset argument out of range");
905#endif
906 (*this)[__pos] = false;
907 return *this;
908}
909
910template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000911inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +0000913bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914{
915 bitset __x(*this);
916 __x.flip();
917 return __x;
918}
919
920template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000921inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000922bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000923bitset<_Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924{
925 base::flip();
926 return *this;
927}
928
929template <size_t _Size>
930bitset<_Size>&
931bitset<_Size>::flip(size_t __pos)
932{
933 if (__pos >= _Size)
934#ifndef _LIBCPP_NO_EXCEPTIONS
935 throw out_of_range("bitset flip argument out of range");
936#else
937 assert(!"bitset flip argument out of range");
938#endif
939 reference r = base::__make_ref(__pos);
940 r = ~r;
941 return *this;
942}
943
944template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000945inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946unsigned long
947bitset<_Size>::to_ulong() const
948{
949 return base::to_ulong();
950}
951
952template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000953inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954unsigned long long
955bitset<_Size>::to_ullong() const
956{
957 return base::to_ullong();
958}
959
960template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000961template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962basic_string<_CharT, _Traits, _Allocator>
963bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
964{
965 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
966 for (size_t __i = 0; __i < _Size; ++__i)
967 {
968 if ((*this)[__i])
969 __r[_Size - 1 - __i] = __one;
970 }
971 return __r;
972}
973
974template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000975template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000976inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977basic_string<_CharT, _Traits, allocator<_CharT> >
978bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
979{
980 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
981}
982
983template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000984template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000985inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
987bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
988{
989 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
990}
991
992template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000993inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994basic_string<char, char_traits<char>, allocator<char> >
995bitset<_Size>::to_string(char __zero, char __one) const
996{
997 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
998}
999
1000template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001001inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +00001003bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001005 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006}
1007
1008template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001009inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001011bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001013 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014}
1015
1016template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001017inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001019bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020{
1021 return !(*this == __rhs);
1022}
1023
1024template <size_t _Size>
1025bool
1026bitset<_Size>::test(size_t __pos) const
1027{
1028 if (__pos >= _Size)
1029#ifndef _LIBCPP_NO_EXCEPTIONS
1030 throw out_of_range("bitset test argument out of range");
1031#else
1032 assert(!"bitset test argument out of range");
1033#endif
1034 return (*this)[__pos];
1035}
1036
1037template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001038inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001040bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041{
1042 return base::all();
1043}
1044
1045template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001046inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001048bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049{
1050 return base::any();
1051}
1052
1053template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001054inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001056bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057{
1058 bitset __r = *this;
1059 __r <<= __pos;
1060 return __r;
1061}
1062
1063template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001064inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001066bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067{
1068 bitset __r = *this;
1069 __r >>= __pos;
1070 return __r;
1071}
1072
1073template <size_t _Size>
1074inline _LIBCPP_INLINE_VISIBILITY
1075bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001076operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077{
1078 bitset<_Size> __r = __x;
1079 __r &= __y;
1080 return __r;
1081}
1082
1083template <size_t _Size>
1084inline _LIBCPP_INLINE_VISIBILITY
1085bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001086operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087{
1088 bitset<_Size> __r = __x;
1089 __r |= __y;
1090 return __r;
1091}
1092
1093template <size_t _Size>
1094inline _LIBCPP_INLINE_VISIBILITY
1095bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001096operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097{
1098 bitset<_Size> __r = __x;
1099 __r ^= __y;
1100 return __r;
1101}
1102
1103template <size_t _Size>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001104struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 : public unary_function<bitset<_Size>, size_t>
1106{
Howard Hinnant422a53f2010-09-21 21:28:23 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +00001108 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 {return __bs.__hash_code();}
1110};
1111
Howard Hinnant464aa5c2011-07-18 15:51:59 +00001112template <class _CharT, class _Traits, size_t _Size>
1113basic_istream<_CharT, _Traits>&
1114operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1115
1116template <class _CharT, class _Traits, size_t _Size>
1117basic_ostream<_CharT, _Traits>&
1118operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120_LIBCPP_END_NAMESPACE_STD
1121
1122#endif // _LIBCPP_BITSET