blob: 87d7afca5a738fe38a9aeee37489e9e244bfdae8 [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;
Evgeniy Stepanov28c02db2015-12-09 22:32:36 +0000205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000206 void __init(unsigned long long __v, true_type) _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000207#endif // _LIBCPP_HAS_NO_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 unsigned long to_ulong(false_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210 unsigned long to_ulong(true_type) const;
211 unsigned long long to_ullong(false_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213 unsigned long long to_ullong(true_type) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215 unsigned long long to_ullong(true_type, false_type) const;
216 unsigned long long to_ullong(true_type, true_type) const;
217};
218
219template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000220inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000221_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000222__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
Howard Hinnant90d87232012-07-07 17:04:52 +0000223#ifndef _LIBCPP_HAS_NO_CONSTEXPR
224 : __first_{0}
225#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226{
Howard Hinnant90d87232012-07-07 17:04:52 +0000227#ifdef _LIBCPP_HAS_NO_CONSTEXPR
Howard Hinnant0949eed2011-06-30 21:18:19 +0000228 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
Howard Hinnant90d87232012-07-07 17:04:52 +0000229#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230}
231
Howard Hinnant90d87232012-07-07 17:04:52 +0000232#ifdef _LIBCPP_HAS_NO_CONSTEXPR
233
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234template <size_t _N_words, size_t _Size>
235void
Howard Hinnantec3773c2011-12-01 20:21:04 +0000236__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237{
238 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
239 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word)
240 __t[__i] = static_cast<__storage_type>(__v);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000241 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
242 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243 __storage_type(0));
244}
245
246template <size_t _N_words, size_t _Size>
247inline _LIBCPP_INLINE_VISIBILITY
248void
Howard Hinnantec3773c2011-12-01 20:21:04 +0000249__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250{
251 __first_[0] = __v;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000252 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253}
254
Howard Hinnant90d87232012-07-07 17:04:52 +0000255#endif // _LIBCPP_HAS_NO_CONSTEXPR
256
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000257template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000258inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000259_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000260__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Howard Hinnant90d87232012-07-07 17:04:52 +0000261#ifndef _LIBCPP_HAS_NO_CONSTEXPR
Nico Weber0211e862014-06-04 15:46:56 +0000262#if __SIZEOF_SIZE_T__ == 8
Howard Hinnant90d87232012-07-07 17:04:52 +0000263 : __first_{__v}
Nico Weber0211e862014-06-04 15:46:56 +0000264#elif __SIZEOF_SIZE_T__ == 4
Howard Hinnant11a31d02013-03-06 17:30:26 +0000265 : __first_{__v, __v >> __bits_per_word}
Howard Hinnant31014742013-03-06 18:16:12 +0000266#else
Howard Hinnant11a31d02013-03-06 17:30:26 +0000267#error This constructor has not been ported to this platform
268#endif
Howard Hinnant90d87232012-07-07 17:04:52 +0000269#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270{
Howard Hinnant90d87232012-07-07 17:04:52 +0000271#ifdef _LIBCPP_HAS_NO_CONSTEXPR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
Howard Hinnant90d87232012-07-07 17:04:52 +0000273#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274}
275
276template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000277inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000279__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280{
281 for (size_type __i = 0; __i < _N_words; ++__i)
282 __first_[__i] &= __v.__first_[__i];
283}
284
285template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000286inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000288__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289{
290 for (size_type __i = 0; __i < _N_words; ++__i)
291 __first_[__i] |= __v.__first_[__i];
292}
293
294template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000295inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000297__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298{
299 for (size_type __i = 0; __i < _N_words; ++__i)
300 __first_[__i] ^= __v.__first_[__i];
301}
302
303template <size_t _N_words, size_t _Size>
304void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000305__bitset<_N_words, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306{
307 // do middle whole words
308 size_type __n = _Size;
309 __storage_pointer __p = __first_;
310 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
311 *__p = ~*__p;
312 // do last partial word
313 if (__n > 0)
314 {
315 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
316 __storage_type __b = *__p & __m;
317 *__p &= ~__m;
318 *__p |= ~__b & __m;
319 }
320}
321
322template <size_t _N_words, size_t _Size>
323unsigned long
324__bitset<_N_words, _Size>::to_ulong(false_type) const
325{
326 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000327 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328 if (__i != __e)
329#ifndef _LIBCPP_NO_EXCEPTIONS
330 throw overflow_error("bitset to_ulong overflow error");
331#else
332 assert(!"bitset to_ulong overflow error");
333#endif
334 return __first_[0];
335}
336
337template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000338inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339unsigned long
340__bitset<_N_words, _Size>::to_ulong(true_type) const
341{
342 return __first_[0];
343}
344
345template <size_t _N_words, size_t _Size>
346unsigned long long
347__bitset<_N_words, _Size>::to_ullong(false_type) const
348{
349 const_iterator __e = __make_iter(_Size);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000350 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351 if (__i != __e)
352#ifndef _LIBCPP_NO_EXCEPTIONS
353 throw overflow_error("bitset to_ullong overflow error");
354#else
355 assert(!"bitset to_ullong overflow error");
356#endif
357 return to_ullong(true_type());
358}
359
360template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000361inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362unsigned long long
363__bitset<_N_words, _Size>::to_ullong(true_type) const
364{
365 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
366}
367
368template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000369inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370unsigned long long
371__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
372{
373 return __first_[0];
374}
375
376template <size_t _N_words, size_t _Size>
377unsigned long long
378__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
379{
380 unsigned long long __r = __first_[0];
381 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
382 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
383 return __r;
384}
385
386template <size_t _N_words, size_t _Size>
387bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000388__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389{
390 // do middle whole words
391 size_type __n = _Size;
392 __const_storage_pointer __p = __first_;
393 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
394 if (~*__p)
395 return false;
396 // do last partial word
397 if (__n > 0)
398 {
399 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
400 if (~*__p & __m)
401 return false;
402 }
403 return true;
404}
405
406template <size_t _N_words, size_t _Size>
407bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000408__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409{
410 // do middle whole words
411 size_type __n = _Size;
412 __const_storage_pointer __p = __first_;
413 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
414 if (*__p)
415 return true;
416 // do last partial word
417 if (__n > 0)
418 {
419 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
420 if (*__p & __m)
421 return true;
422 }
423 return false;
424}
425
426template <size_t _N_words, size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000427inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000429__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430{
431 size_t __h = 0;
432 for (size_type __i = 0; __i < _N_words; ++__i)
433 __h ^= __first_[__i];
434 return __h;
435}
436
437template <size_t _Size>
438class __bitset<1, _Size>
439{
440public:
441 typedef ptrdiff_t difference_type;
442 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000443 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444protected:
445 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 typedef __storage_type* __storage_pointer;
447 typedef const __storage_type* __const_storage_pointer;
448 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
449
450 friend class __bit_reference<__bitset>;
451 friend class __bit_const_reference<__bitset>;
452 friend class __bit_iterator<__bitset, false>;
453 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +0000454 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455
456 __storage_type __first_;
457
458 typedef __bit_reference<__bitset> reference;
459 typedef __bit_const_reference<__bitset> const_reference;
460 typedef __bit_iterator<__bitset, false> iterator;
461 typedef __bit_iterator<__bitset, true> const_iterator;
462
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000464 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000466 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467
Howard Hinnant10f25d22011-05-27 20:52:28 +0000468 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000472 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant10f25d22011-05-27 20:52:28 +0000474 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
476
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000478 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000480 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000482 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000485 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 unsigned long long to_ullong() const;
491
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000493 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000495 bool any() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000498 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499};
500
501template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000502inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000503_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000504__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 : __first_(0)
506{
507}
508
509template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000510inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000511_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000512__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 : __first_(static_cast<__storage_type>(__v))
514{
515}
516
517template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000518inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000520__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521{
522 __first_ &= __v.__first_;
523}
524
525template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000526inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000528__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529{
530 __first_ |= __v.__first_;
531}
532
533template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000534inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000536__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537{
538 __first_ ^= __v.__first_;
539}
540
541template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000542inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543void
Howard Hinnant10f25d22011-05-27 20:52:28 +0000544__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545{
546 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
547 __first_ = ~__first_;
548 __first_ &= __m;
549}
550
551template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000552inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553unsigned long
554__bitset<1, _Size>::to_ulong() const
555{
556 return __first_;
557}
558
559template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000560inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561unsigned long long
562__bitset<1, _Size>::to_ullong() const
563{
564 return __first_;
565}
566
567template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000568inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000570__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571{
572 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
573 return !(~__first_ & __m);
574}
575
576template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000577inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578bool
Howard Hinnant10f25d22011-05-27 20:52:28 +0000579__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580{
581 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
582 return __first_ & __m;
583}
584
585template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000586inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +0000588__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589{
590 return __first_;
591}
592
593template <>
594class __bitset<0, 0>
595{
596public:
597 typedef ptrdiff_t difference_type;
598 typedef size_t size_type;
Howard Hinnantf867f632012-05-07 16:50:38 +0000599 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600protected:
601 typedef __bitset __self;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602 typedef __storage_type* __storage_pointer;
603 typedef const __storage_type* __const_storage_pointer;
604 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
605
606 friend class __bit_reference<__bitset>;
607 friend class __bit_const_reference<__bitset>;
608 friend class __bit_iterator<__bitset, false>;
609 friend class __bit_iterator<__bitset, true>;
Howard Hinnantec3773c2011-12-01 20:21:04 +0000610 friend struct __bit_array<__bitset>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611
612 typedef __bit_reference<__bitset> reference;
613 typedef __bit_const_reference<__bitset> const_reference;
614 typedef __bit_iterator<__bitset, false> iterator;
615 typedef __bit_iterator<__bitset, true> const_iterator;
616
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000618 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant90d87232012-07-07 17:04:52 +0000620 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621
Howard Hinnant10f25d22011-05-27 20:52:28 +0000622 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 {return reference(0, 1);}
Howard Hinnant90d87232012-07-07 17:04:52 +0000624 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 {return const_reference(0, 1);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000626 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627 {return iterator(0, 0);}
Howard Hinnantec3773c2011-12-01 20:21:04 +0000628 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629 {return const_iterator(0, 0);}
630
Howard Hinnant10f25d22011-05-27 20:52:28 +0000631 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
632 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
633 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634
Howard Hinnant10f25d22011-05-27 20:52:28 +0000635 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636
637 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
638 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
639
Howard Hinnant10f25d22011-05-27 20:52:28 +0000640 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
641 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642
Howard Hinnant10f25d22011-05-27 20:52:28 +0000643 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644};
645
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000646inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000647_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000648__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649{
650}
651
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000652inline
Howard Hinnant90d87232012-07-07 17:04:52 +0000653_LIBCPP_CONSTEXPR
Howard Hinnant10f25d22011-05-27 20:52:28 +0000654__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655{
656}
657
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000658template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset;
659template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660
661template <size_t _Size>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000662class _LIBCPP_TYPE_VIS_ONLY bitset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
664{
Howard Hinnant11a31d02013-03-06 17:30:26 +0000665public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
667 typedef __bitset<__n_words, _Size> base;
668
Howard Hinnant324bb032010-08-22 00:02:43 +0000669public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 typedef typename base::reference reference;
671 typedef typename base::const_reference const_reference;
672
Howard Hinnant324bb032010-08-22 00:02:43 +0000673 // 23.3.5.1 constructors:
Howard Hinnant90d87232012-07-07 17:04:52 +0000674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
676 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Howard Hinnant34d6b192010-11-17 21:53:14 +0000677 template<class _CharT>
678 explicit bitset(const _CharT* __str,
679 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
680 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant324bb032010-08-22 00:02:43 +0000681 template<class _CharT, class _Traits, class _Allocator>
682 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
683 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
684 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant324bb032010-08-22 00:02:43 +0000686 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687
Howard Hinnant324bb032010-08-22 00:02:43 +0000688 // 23.3.5.2 bitset operations:
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;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000692 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000694 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
695 bitset& operator<<=(size_t __pos) _NOEXCEPT;
696 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000698 bitset& set() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000699 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000701 bitset& reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000702 bitset& reset(size_t __pos);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000704 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000706 bitset& flip() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000707 bitset& flip(size_t __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708
Howard Hinnant324bb032010-08-22 00:02:43 +0000709 // element access:
Howard Hinnant90d87232012-07-07 17:04:52 +0000710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
711 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000714 unsigned long to_ulong() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +0000716 unsigned long long to_ullong() const;
717 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000719 _CharT __one = _CharT('1')) const;
720 template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000723 _CharT __one = _CharT('1')) const;
724 template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant324bb032010-08-22 00:02:43 +0000727 _CharT __one = _CharT('1')) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant324bb032010-08-22 00:02:43 +0000730 char __one = '1') const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000732 size_t count() const _NOEXCEPT;
Howard Hinnant90d87232012-07-07 17:04:52 +0000733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000735 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000737 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +0000738 bool test(size_t __pos) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000740 bool all() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000742 bool any() const _NOEXCEPT;
743 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000745 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000747 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748
749private:
750
Howard Hinnant422a53f2010-09-21 21:28:23 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +0000752 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753
754 friend struct hash<bitset>;
755};
756
757template <size_t _Size>
Howard Hinnant34d6b192010-11-17 21:53:14 +0000758template<class _CharT>
759bitset<_Size>::bitset(const _CharT* __str,
760 typename basic_string<_CharT>::size_type __n,
761 _CharT __zero, _CharT __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000763 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant34d6b192010-11-17 21:53:14 +0000765 if (__str[__i] != __zero && __str[__i] != __one)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766#ifndef _LIBCPP_NO_EXCEPTIONS
767 throw invalid_argument("bitset string ctor has invalid argument");
768#else
769 assert(!"bitset string ctor has invalid argument");
770#endif
Howard Hinnant99968442011-11-29 18:15:50 +0000771 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000773 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 {
Howard Hinnant99968442011-11-29 18:15:50 +0000775 _CharT __c = __str[_Mp - 1 - __i];
Howard Hinnant34d6b192010-11-17 21:53:14 +0000776 if (__c == __zero)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 (*this)[__i] = false;
Howard Hinnant34d6b192010-11-17 21:53:14 +0000778 else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 (*this)[__i] = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000781 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782}
783
784template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000785template<class _CharT, class _Traits, class _Allocator>
786bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
789 _CharT __zero, _CharT __one)
790{
791 if (__pos > __str.size())
792#ifndef _LIBCPP_NO_EXCEPTIONS
793 throw out_of_range("bitset string pos out of range");
794#else
795 assert(!"bitset string pos out of range");
796#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +0000797 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
799 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
800#ifndef _LIBCPP_NO_EXCEPTIONS
801 throw invalid_argument("bitset string ctor has invalid argument");
802#else
803 assert(!"bitset string ctor has invalid argument");
804#endif
Howard Hinnant99968442011-11-29 18:15:50 +0000805 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 size_t __i = 0;
Howard Hinnant99968442011-11-29 18:15:50 +0000807 for (; __i < _Mp; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 {
Howard Hinnant99968442011-11-29 18:15:50 +0000809 _CharT __c = __str[__pos + _Mp - 1 - __i];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 if (_Traits::eq(__c, __zero))
811 (*this)[__i] = false;
812 else
813 (*this)[__i] = true;
814 }
Howard Hinnant0949eed2011-06-30 21:18:19 +0000815 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816}
817
818template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000819inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000821bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822{
823 base::operator&=(__rhs);
824 return *this;
825}
826
827template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000828inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000830bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831{
832 base::operator|=(__rhs);
833 return *this;
834}
835
836template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000837inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000839bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840{
841 base::operator^=(__rhs);
842 return *this;
843}
844
845template <size_t _Size>
846bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000847bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000849 __pos = _VSTD::min(__pos, _Size);
850 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
851 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 return *this;
853}
854
855template <size_t _Size>
856bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000857bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000859 __pos = _VSTD::min(__pos, _Size);
860 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
861 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 return *this;
863}
864
865template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000866inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000868bitset<_Size>::set() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000870 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 return *this;
872}
873
874template <size_t _Size>
875bitset<_Size>&
876bitset<_Size>::set(size_t __pos, bool __val)
877{
878 if (__pos >= _Size)
879#ifndef _LIBCPP_NO_EXCEPTIONS
880 throw out_of_range("bitset set argument out of range");
881#else
882 assert(!"bitset set argument out of range");
883#endif
884 (*this)[__pos] = __val;
885 return *this;
886}
887
888template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000889inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000891bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000893 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 return *this;
895}
896
897template <size_t _Size>
898bitset<_Size>&
899bitset<_Size>::reset(size_t __pos)
900{
901 if (__pos >= _Size)
902#ifndef _LIBCPP_NO_EXCEPTIONS
903 throw out_of_range("bitset reset argument out of range");
904#else
905 assert(!"bitset reset argument out of range");
906#endif
907 (*this)[__pos] = false;
908 return *this;
909}
910
911template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000912inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +0000914bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915{
916 bitset __x(*this);
917 __x.flip();
918 return __x;
919}
920
921template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000922inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923bitset<_Size>&
Howard Hinnant10f25d22011-05-27 20:52:28 +0000924bitset<_Size>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925{
926 base::flip();
927 return *this;
928}
929
930template <size_t _Size>
931bitset<_Size>&
932bitset<_Size>::flip(size_t __pos)
933{
934 if (__pos >= _Size)
935#ifndef _LIBCPP_NO_EXCEPTIONS
936 throw out_of_range("bitset flip argument out of range");
937#else
938 assert(!"bitset flip argument out of range");
939#endif
940 reference r = base::__make_ref(__pos);
941 r = ~r;
942 return *this;
943}
944
945template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000946inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947unsigned long
948bitset<_Size>::to_ulong() const
949{
950 return base::to_ulong();
951}
952
953template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000954inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955unsigned long long
956bitset<_Size>::to_ullong() const
957{
958 return base::to_ullong();
959}
960
961template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000962template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963basic_string<_CharT, _Traits, _Allocator>
964bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
965{
966 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
967 for (size_t __i = 0; __i < _Size; ++__i)
968 {
969 if ((*this)[__i])
970 __r[_Size - 1 - __i] = __one;
971 }
972 return __r;
973}
974
975template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000976template <class _CharT, class _Traits>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000977inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978basic_string<_CharT, _Traits, allocator<_CharT> >
979bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
980{
981 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
982}
983
984template <size_t _Size>
Howard Hinnant324bb032010-08-22 00:02:43 +0000985template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000986inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
988bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
989{
990 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
991}
992
993template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000994inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995basic_string<char, char_traits<char>, allocator<char> >
996bitset<_Size>::to_string(char __zero, char __one) const
997{
998 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
999}
1000
1001template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001002inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003size_t
Howard Hinnant10f25d22011-05-27 20:52:28 +00001004bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001006 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007}
1008
1009template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001010inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001012bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001014 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015}
1016
1017template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001018inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001020bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021{
1022 return !(*this == __rhs);
1023}
1024
1025template <size_t _Size>
1026bool
1027bitset<_Size>::test(size_t __pos) const
1028{
1029 if (__pos >= _Size)
1030#ifndef _LIBCPP_NO_EXCEPTIONS
1031 throw out_of_range("bitset test argument out of range");
1032#else
1033 assert(!"bitset test argument out of range");
1034#endif
1035 return (*this)[__pos];
1036}
1037
1038template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001039inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001041bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042{
1043 return base::all();
1044}
1045
1046template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001047inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048bool
Howard Hinnant10f25d22011-05-27 20:52:28 +00001049bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050{
1051 return base::any();
1052}
1053
1054template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001055inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001057bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058{
1059 bitset __r = *this;
1060 __r <<= __pos;
1061 return __r;
1062}
1063
1064template <size_t _Size>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001065inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001067bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068{
1069 bitset __r = *this;
1070 __r >>= __pos;
1071 return __r;
1072}
1073
1074template <size_t _Size>
1075inline _LIBCPP_INLINE_VISIBILITY
1076bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001077operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078{
1079 bitset<_Size> __r = __x;
1080 __r &= __y;
1081 return __r;
1082}
1083
1084template <size_t _Size>
1085inline _LIBCPP_INLINE_VISIBILITY
1086bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001087operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088{
1089 bitset<_Size> __r = __x;
1090 __r |= __y;
1091 return __r;
1092}
1093
1094template <size_t _Size>
1095inline _LIBCPP_INLINE_VISIBILITY
1096bitset<_Size>
Howard Hinnant10f25d22011-05-27 20:52:28 +00001097operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098{
1099 bitset<_Size> __r = __x;
1100 __r ^= __y;
1101 return __r;
1102}
1103
1104template <size_t _Size>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001105struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 : public unary_function<bitset<_Size>, size_t>
1107{
Howard Hinnant422a53f2010-09-21 21:28:23 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant10f25d22011-05-27 20:52:28 +00001109 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110 {return __bs.__hash_code();}
1111};
1112
Howard Hinnant464aa5c2011-07-18 15:51:59 +00001113template <class _CharT, class _Traits, size_t _Size>
1114basic_istream<_CharT, _Traits>&
1115operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1116
1117template <class _CharT, class _Traits, size_t _Size>
1118basic_ostream<_CharT, _Traits>&
1119operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1120
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121_LIBCPP_END_NAMESPACE_STD
1122
1123#endif // _LIBCPP_BITSET