xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/bitset (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_BITSET
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_BITSET
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric// clang-format off
14*700637cbSDimitry Andric
15*700637cbSDimitry Andric/*
16*700637cbSDimitry Andric    bitset synopsis
17*700637cbSDimitry Andric
18*700637cbSDimitry Andricnamespace std
19*700637cbSDimitry Andric{
20*700637cbSDimitry Andric
21*700637cbSDimitry Andricnamespace std {
22*700637cbSDimitry Andric
23*700637cbSDimitry Andrictemplate <size_t N>
24*700637cbSDimitry Andricclass bitset
25*700637cbSDimitry Andric{
26*700637cbSDimitry Andricpublic:
27*700637cbSDimitry Andric    // bit reference:
28*700637cbSDimitry Andric    class reference
29*700637cbSDimitry Andric    {
30*700637cbSDimitry Andric        friend class bitset;
31*700637cbSDimitry Andric        reference() noexcept;
32*700637cbSDimitry Andric    public:
33*700637cbSDimitry Andric        ~reference() noexcept;
34*700637cbSDimitry Andric        reference& operator=(bool x) noexcept;           // for b[i] = x;
35*700637cbSDimitry Andric        reference& operator=(const reference&) noexcept; // for b[i] = b[j];
36*700637cbSDimitry Andric        bool operator~() const noexcept;                 // flips the bit
37*700637cbSDimitry Andric        operator bool() const noexcept;                  // for x = b[i];
38*700637cbSDimitry Andric        reference& flip() noexcept;                      // for b[i].flip();
39*700637cbSDimitry Andric    };
40*700637cbSDimitry Andric
41*700637cbSDimitry Andric    // 23.3.5.1 constructors:
42*700637cbSDimitry Andric    constexpr bitset() noexcept;
43*700637cbSDimitry Andric    constexpr bitset(unsigned long long val) noexcept;
44*700637cbSDimitry Andric    template <class charT>
45*700637cbSDimitry Andric        constexpr explicit bitset(const charT* str,
46*700637cbSDimitry Andric            typename basic_string<charT>::size_type n = basic_string<charT>::npos,
47*700637cbSDimitry Andric            charT zero = charT('0'), charT one = charT('1'));                                // until C++26, constexpr since C++23
48*700637cbSDimitry Andric    template <class charT>
49*700637cbSDimitry Andric        constexpr explicit bitset(const charT* str,
50*700637cbSDimitry Andric            typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
51*700637cbSDimitry Andric            charT zero = charT('0'), charT one = charT('1'));                                // since C++26
52*700637cbSDimitry Andric    template<class charT, class traits>
53*700637cbSDimitry Andric        explicit bitset(
54*700637cbSDimitry Andric            const basic_string_view<charT,traits>& str,
55*700637cbSDimitry Andric            typename basic_string_view<charT,traits>::size_type pos = 0,
56*700637cbSDimitry Andric            typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos,
57*700637cbSDimitry Andric            charT zero = charT('0'), charT one = charT('1'));                                // since C++26
58*700637cbSDimitry Andric    template<class charT, class traits, class Allocator>
59*700637cbSDimitry Andric        constexpr explicit bitset(
60*700637cbSDimitry Andric            const basic_string<charT,traits,Allocator>& str,
61*700637cbSDimitry Andric            typename basic_string<charT,traits,Allocator>::size_type pos = 0,
62*700637cbSDimitry Andric            typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos,
63*700637cbSDimitry Andric            charT zero = charT('0'), charT one = charT('1'));                                // constexpr since C++23
64*700637cbSDimitry Andric
65*700637cbSDimitry Andric    // 23.3.5.2 bitset operations:
66*700637cbSDimitry Andric    bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23
67*700637cbSDimitry Andric    bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23
68*700637cbSDimitry Andric    bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23
69*700637cbSDimitry Andric    bitset& operator<<=(size_t pos) noexcept;       // constexpr since C++23
70*700637cbSDimitry Andric    bitset& operator>>=(size_t pos) noexcept;       // constexpr since C++23
71*700637cbSDimitry Andric    bitset& set() noexcept;                         // constexpr since C++23
72*700637cbSDimitry Andric    bitset& set(size_t pos, bool val = true);       // constexpr since C++23
73*700637cbSDimitry Andric    bitset& reset() noexcept;                       // constexpr since C++23
74*700637cbSDimitry Andric    bitset& reset(size_t pos);                      // constexpr since C++23
75*700637cbSDimitry Andric    bitset operator~() const noexcept;              // constexpr since C++23
76*700637cbSDimitry Andric    bitset& flip() noexcept;                        // constexpr since C++23
77*700637cbSDimitry Andric    bitset& flip(size_t pos);                       // constexpr since C++23
78*700637cbSDimitry Andric
79*700637cbSDimitry Andric    // element access:
80*700637cbSDimitry Andric    constexpr bool operator[](size_t pos) const;
81*700637cbSDimitry Andric    reference operator[](size_t pos);            // constexpr since C++23
82*700637cbSDimitry Andric    unsigned long to_ulong() const;              // constexpr since C++23
83*700637cbSDimitry Andric    unsigned long long to_ullong() const;        // constexpr since C++23
84*700637cbSDimitry Andric    template <class charT, class traits, class Allocator> // constexpr since C++23
85*700637cbSDimitry Andric        basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
86*700637cbSDimitry Andric    template <class charT, class traits> // constexpr since C++23
87*700637cbSDimitry Andric        basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
88*700637cbSDimitry Andric    template <class charT> // constexpr since C++23
89*700637cbSDimitry Andric        basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
90*700637cbSDimitry Andric    basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23
91*700637cbSDimitry Andric    size_t count() const noexcept;                     // constexpr since C++23
92*700637cbSDimitry Andric    constexpr size_t size() const noexcept;            // constexpr since C++23
93*700637cbSDimitry Andric    bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23
94*700637cbSDimitry Andric    bool operator!=(const bitset& rhs) const noexcept; // removed in C++20
95*700637cbSDimitry Andric    bool test(size_t pos) const;                       // constexpr since C++23
96*700637cbSDimitry Andric    bool all() const noexcept;                         // constexpr since C++23
97*700637cbSDimitry Andric    bool any() const noexcept;                         // constexpr since C++23
98*700637cbSDimitry Andric    bool none() const noexcept;                        // constexpr since C++23
99*700637cbSDimitry Andric    bitset<N> operator<<(size_t pos) const noexcept;   // constexpr since C++23
100*700637cbSDimitry Andric    bitset<N> operator>>(size_t pos) const noexcept;   // constexpr since C++23
101*700637cbSDimitry Andric};
102*700637cbSDimitry Andric
103*700637cbSDimitry Andric// 23.3.5.3 bitset operators:
104*700637cbSDimitry Andrictemplate <size_t N>
105*700637cbSDimitry Andricbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
106*700637cbSDimitry Andric
107*700637cbSDimitry Andrictemplate <size_t N>
108*700637cbSDimitry Andricbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
109*700637cbSDimitry Andric
110*700637cbSDimitry Andrictemplate <size_t N>
111*700637cbSDimitry Andricbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
112*700637cbSDimitry Andric
113*700637cbSDimitry Andrictemplate <class charT, class traits, size_t N>
114*700637cbSDimitry Andricbasic_istream<charT, traits>&
115*700637cbSDimitry Andricoperator>>(basic_istream<charT, traits>& is, bitset<N>& x);
116*700637cbSDimitry Andric
117*700637cbSDimitry Andrictemplate <class charT, class traits, size_t N>
118*700637cbSDimitry Andricbasic_ostream<charT, traits>&
119*700637cbSDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
120*700637cbSDimitry Andric
121*700637cbSDimitry Andrictemplate <size_t N> struct hash<std::bitset<N>>;
122*700637cbSDimitry Andric
123*700637cbSDimitry Andric}  // std
124*700637cbSDimitry Andric
125*700637cbSDimitry Andric*/
126*700637cbSDimitry Andric
127*700637cbSDimitry Andric// clang-format on
128*700637cbSDimitry Andric
129*700637cbSDimitry Andric#include <__cxx03/__algorithm/count.h>
130*700637cbSDimitry Andric#include <__cxx03/__algorithm/fill.h>
131*700637cbSDimitry Andric#include <__cxx03/__algorithm/find.h>
132*700637cbSDimitry Andric#include <__cxx03/__bit_reference>
133*700637cbSDimitry Andric#include <__cxx03/__config>
134*700637cbSDimitry Andric#include <__cxx03/__functional/hash.h>
135*700637cbSDimitry Andric#include <__cxx03/__functional/unary_function.h>
136*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_char_like_type.h>
137*700637cbSDimitry Andric#include <__cxx03/climits>
138*700637cbSDimitry Andric#include <__cxx03/cstddef>
139*700637cbSDimitry Andric#include <__cxx03/stdexcept>
140*700637cbSDimitry Andric#include <__cxx03/string_view>
141*700637cbSDimitry Andric#include <__cxx03/version>
142*700637cbSDimitry Andric
143*700637cbSDimitry Andric// standard-mandated includes
144*700637cbSDimitry Andric
145*700637cbSDimitry Andric// [bitset.syn]
146*700637cbSDimitry Andric#include <__cxx03/iosfwd>
147*700637cbSDimitry Andric#include <__cxx03/string>
148*700637cbSDimitry Andric
149*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
150*700637cbSDimitry Andric#  pragma GCC system_header
151*700637cbSDimitry Andric#endif
152*700637cbSDimitry Andric
153*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS
154*700637cbSDimitry Andric#include <__cxx03/__undef_macros>
155*700637cbSDimitry Andric
156*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
157*700637cbSDimitry Andric
158*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
159*700637cbSDimitry Andricclass __bitset;
160*700637cbSDimitry Andric
161*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
162*700637cbSDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > {
163*700637cbSDimitry Andric  static const bool value = true;
164*700637cbSDimitry Andric};
165*700637cbSDimitry Andric
166*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
167*700637cbSDimitry Andricclass __bitset {
168*700637cbSDimitry Andricpublic:
169*700637cbSDimitry Andric  typedef ptrdiff_t difference_type;
170*700637cbSDimitry Andric  typedef size_t size_type;
171*700637cbSDimitry Andric  typedef size_type __storage_type;
172*700637cbSDimitry Andric
173*700637cbSDimitry Andricprotected:
174*700637cbSDimitry Andric  typedef __bitset __self;
175*700637cbSDimitry Andric  typedef __storage_type* __storage_pointer;
176*700637cbSDimitry Andric  typedef const __storage_type* __const_storage_pointer;
177*700637cbSDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
178*700637cbSDimitry Andric
179*700637cbSDimitry Andric  friend class __bit_reference<__bitset>;
180*700637cbSDimitry Andric  friend class __bit_const_reference<__bitset>;
181*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, false>;
182*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, true>;
183*700637cbSDimitry Andric  friend struct __bit_array<__bitset>;
184*700637cbSDimitry Andric
185*700637cbSDimitry Andric  __storage_type __first_[_N_words];
186*700637cbSDimitry Andric
187*700637cbSDimitry Andric  typedef __bit_reference<__bitset> reference;
188*700637cbSDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
189*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
190*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
191*700637cbSDimitry Andric
192*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __bitset() _NOEXCEPT;
193*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __bitset(unsigned long long __v) _NOEXCEPT;
194*700637cbSDimitry Andric
195*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference __make_ref(size_t __pos) _NOEXCEPT {
196*700637cbSDimitry Andric    return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
197*700637cbSDimitry Andric  }
198*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference __make_ref(size_t __pos) const _NOEXCEPT {
199*700637cbSDimitry Andric    return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
200*700637cbSDimitry Andric  }
201*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __make_iter(size_t __pos) _NOEXCEPT {
202*700637cbSDimitry Andric    return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
203*700637cbSDimitry Andric  }
204*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
205*700637cbSDimitry Andric    return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
206*700637cbSDimitry Andric  }
207*700637cbSDimitry Andric
208*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator&=(const __bitset& __v) _NOEXCEPT;
209*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator|=(const __bitset& __v) _NOEXCEPT;
210*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator^=(const __bitset& __v) _NOEXCEPT;
211*700637cbSDimitry Andric
212*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void flip() _NOEXCEPT;
213*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong() const {
214*700637cbSDimitry Andric    return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
215*700637cbSDimitry Andric  }
216*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong() const {
217*700637cbSDimitry Andric    return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
218*700637cbSDimitry Andric  }
219*700637cbSDimitry Andric
220*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool all() const _NOEXCEPT;
221*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool any() const _NOEXCEPT;
222*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
223*700637cbSDimitry Andric
224*700637cbSDimitry Andricprivate:
225*700637cbSDimitry Andric  void __init(unsigned long long __v, false_type) _NOEXCEPT;
226*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
227*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong(false_type) const;
228*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong(true_type) const;
229*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong(false_type) const;
230*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong(true_type) const;
231*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong(true_type, false_type) const;
232*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong(true_type, true_type) const;
233*700637cbSDimitry Andric};
234*700637cbSDimitry Andric
235*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
236*700637cbSDimitry Andricinline __bitset<_N_words, _Size>::__bitset() _NOEXCEPT {
237*700637cbSDimitry Andric  std::fill_n(__first_, _N_words, __storage_type(0));
238*700637cbSDimitry Andric}
239*700637cbSDimitry Andric
240*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
241*700637cbSDimitry Andricvoid __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
242*700637cbSDimitry Andric  __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
243*700637cbSDimitry Andric  size_t __sz = _Size;
244*700637cbSDimitry Andric  for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
245*700637cbSDimitry Andric    if (__sz < __bits_per_word)
246*700637cbSDimitry Andric      __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
247*700637cbSDimitry Andric    else
248*700637cbSDimitry Andric      __t[__i] = static_cast<__storage_type>(__v);
249*700637cbSDimitry Andric
250*700637cbSDimitry Andric  std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
251*700637cbSDimitry Andric  std::fill(
252*700637cbSDimitry Andric      __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
253*700637cbSDimitry Andric}
254*700637cbSDimitry Andric
255*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
256*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
257*700637cbSDimitry Andric  __first_[0] = __v;
258*700637cbSDimitry Andric  if (_Size < __bits_per_word)
259*700637cbSDimitry Andric    __first_[0] &= (1ULL << _Size) - 1;
260*700637cbSDimitry Andric
261*700637cbSDimitry Andric  std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
262*700637cbSDimitry Andric}
263*700637cbSDimitry Andric
264*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
265*700637cbSDimitry Andricinline __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT {
266*700637cbSDimitry Andric  __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
267*700637cbSDimitry Andric}
268*700637cbSDimitry Andric
269*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
270*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
271*700637cbSDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
272*700637cbSDimitry Andric    __first_[__i] &= __v.__first_[__i];
273*700637cbSDimitry Andric}
274*700637cbSDimitry Andric
275*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
276*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
277*700637cbSDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
278*700637cbSDimitry Andric    __first_[__i] |= __v.__first_[__i];
279*700637cbSDimitry Andric}
280*700637cbSDimitry Andric
281*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
282*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
283*700637cbSDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
284*700637cbSDimitry Andric    __first_[__i] ^= __v.__first_[__i];
285*700637cbSDimitry Andric}
286*700637cbSDimitry Andric
287*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
288*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
289*700637cbSDimitry Andric  // do middle whole words
290*700637cbSDimitry Andric  size_type __n         = _Size;
291*700637cbSDimitry Andric  __storage_pointer __p = __first_;
292*700637cbSDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
293*700637cbSDimitry Andric    *__p = ~*__p;
294*700637cbSDimitry Andric  // do last partial word
295*700637cbSDimitry Andric  if (__n > 0) {
296*700637cbSDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
297*700637cbSDimitry Andric    __storage_type __b = *__p & __m;
298*700637cbSDimitry Andric    *__p &= ~__m;
299*700637cbSDimitry Andric    *__p |= ~__b & __m;
300*700637cbSDimitry Andric  }
301*700637cbSDimitry Andric}
302*700637cbSDimitry Andric
303*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
304*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI unsigned long __bitset<_N_words, _Size>::to_ulong(false_type) const {
305*700637cbSDimitry Andric  const_iterator __e = __make_iter(_Size);
306*700637cbSDimitry Andric  const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
307*700637cbSDimitry Andric  if (__i != __e)
308*700637cbSDimitry Andric    __throw_overflow_error("bitset to_ulong overflow error");
309*700637cbSDimitry Andric
310*700637cbSDimitry Andric  return __first_[0];
311*700637cbSDimitry Andric}
312*700637cbSDimitry Andric
313*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
314*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long __bitset<_N_words, _Size>::to_ulong(true_type) const {
315*700637cbSDimitry Andric  return __first_[0];
316*700637cbSDimitry Andric}
317*700637cbSDimitry Andric
318*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
319*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI unsigned long long __bitset<_N_words, _Size>::to_ullong(false_type) const {
320*700637cbSDimitry Andric  const_iterator __e = __make_iter(_Size);
321*700637cbSDimitry Andric  const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
322*700637cbSDimitry Andric  if (__i != __e)
323*700637cbSDimitry Andric    __throw_overflow_error("bitset to_ullong overflow error");
324*700637cbSDimitry Andric
325*700637cbSDimitry Andric  return to_ullong(true_type());
326*700637cbSDimitry Andric}
327*700637cbSDimitry Andric
328*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
329*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type) const {
330*700637cbSDimitry Andric  return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
331*700637cbSDimitry Andric}
332*700637cbSDimitry Andric
333*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
334*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
335*700637cbSDimitry Andric  return __first_[0];
336*700637cbSDimitry Andric}
337*700637cbSDimitry Andric
338*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
339*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
340*700637cbSDimitry Andric  unsigned long long __r = __first_[0];
341*700637cbSDimitry Andric  _LIBCPP_DIAGNOSTIC_PUSH
342*700637cbSDimitry Andric  _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
343*700637cbSDimitry Andric  for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
344*700637cbSDimitry Andric    __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
345*700637cbSDimitry Andric  _LIBCPP_DIAGNOSTIC_POP
346*700637cbSDimitry Andric  return __r;
347*700637cbSDimitry Andric}
348*700637cbSDimitry Andric
349*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
350*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
351*700637cbSDimitry Andric  // do middle whole words
352*700637cbSDimitry Andric  size_type __n               = _Size;
353*700637cbSDimitry Andric  __const_storage_pointer __p = __first_;
354*700637cbSDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
355*700637cbSDimitry Andric    if (~*__p)
356*700637cbSDimitry Andric      return false;
357*700637cbSDimitry Andric  // do last partial word
358*700637cbSDimitry Andric  if (__n > 0) {
359*700637cbSDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
360*700637cbSDimitry Andric    if (~*__p & __m)
361*700637cbSDimitry Andric      return false;
362*700637cbSDimitry Andric  }
363*700637cbSDimitry Andric  return true;
364*700637cbSDimitry Andric}
365*700637cbSDimitry Andric
366*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
367*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
368*700637cbSDimitry Andric  // do middle whole words
369*700637cbSDimitry Andric  size_type __n               = _Size;
370*700637cbSDimitry Andric  __const_storage_pointer __p = __first_;
371*700637cbSDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
372*700637cbSDimitry Andric    if (*__p)
373*700637cbSDimitry Andric      return true;
374*700637cbSDimitry Andric  // do last partial word
375*700637cbSDimitry Andric  if (__n > 0) {
376*700637cbSDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
377*700637cbSDimitry Andric    if (*__p & __m)
378*700637cbSDimitry Andric      return true;
379*700637cbSDimitry Andric  }
380*700637cbSDimitry Andric  return false;
381*700637cbSDimitry Andric}
382*700637cbSDimitry Andric
383*700637cbSDimitry Andrictemplate <size_t _N_words, size_t _Size>
384*700637cbSDimitry Andricinline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
385*700637cbSDimitry Andric  size_t __h = 0;
386*700637cbSDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
387*700637cbSDimitry Andric    __h ^= __first_[__i];
388*700637cbSDimitry Andric  return __h;
389*700637cbSDimitry Andric}
390*700637cbSDimitry Andric
391*700637cbSDimitry Andrictemplate <size_t _Size>
392*700637cbSDimitry Andricclass __bitset<1, _Size> {
393*700637cbSDimitry Andricpublic:
394*700637cbSDimitry Andric  typedef ptrdiff_t difference_type;
395*700637cbSDimitry Andric  typedef size_t size_type;
396*700637cbSDimitry Andric  typedef size_type __storage_type;
397*700637cbSDimitry Andric
398*700637cbSDimitry Andricprotected:
399*700637cbSDimitry Andric  typedef __bitset __self;
400*700637cbSDimitry Andric  typedef __storage_type* __storage_pointer;
401*700637cbSDimitry Andric  typedef const __storage_type* __const_storage_pointer;
402*700637cbSDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
403*700637cbSDimitry Andric
404*700637cbSDimitry Andric  friend class __bit_reference<__bitset>;
405*700637cbSDimitry Andric  friend class __bit_const_reference<__bitset>;
406*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, false>;
407*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, true>;
408*700637cbSDimitry Andric  friend struct __bit_array<__bitset>;
409*700637cbSDimitry Andric
410*700637cbSDimitry Andric  __storage_type __first_;
411*700637cbSDimitry Andric
412*700637cbSDimitry Andric  typedef __bit_reference<__bitset> reference;
413*700637cbSDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
414*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
415*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
416*700637cbSDimitry Andric
417*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __bitset() _NOEXCEPT;
418*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __bitset(unsigned long long __v) _NOEXCEPT;
419*700637cbSDimitry Andric
420*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference __make_ref(size_t __pos) _NOEXCEPT {
421*700637cbSDimitry Andric    return reference(&__first_, __storage_type(1) << __pos);
422*700637cbSDimitry Andric  }
423*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference __make_ref(size_t __pos) const _NOEXCEPT {
424*700637cbSDimitry Andric    return const_reference(&__first_, __storage_type(1) << __pos);
425*700637cbSDimitry Andric  }
426*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __make_iter(size_t __pos) _NOEXCEPT {
427*700637cbSDimitry Andric    return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
428*700637cbSDimitry Andric  }
429*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
430*700637cbSDimitry Andric    return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
431*700637cbSDimitry Andric  }
432*700637cbSDimitry Andric
433*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator&=(const __bitset& __v) _NOEXCEPT;
434*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator|=(const __bitset& __v) _NOEXCEPT;
435*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator^=(const __bitset& __v) _NOEXCEPT;
436*700637cbSDimitry Andric
437*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void flip() _NOEXCEPT;
438*700637cbSDimitry Andric
439*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong() const;
440*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong() const;
441*700637cbSDimitry Andric
442*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool all() const _NOEXCEPT;
443*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool any() const _NOEXCEPT;
444*700637cbSDimitry Andric
445*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
446*700637cbSDimitry Andric};
447*700637cbSDimitry Andric
448*700637cbSDimitry Andrictemplate <size_t _Size>
449*700637cbSDimitry Andricinline __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}
450*700637cbSDimitry Andric
451*700637cbSDimitry Andrictemplate <size_t _Size>
452*700637cbSDimitry Andricinline __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
453*700637cbSDimitry Andric    : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
454*700637cbSDimitry Andric                                        : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
455*700637cbSDimitry Andric
456*700637cbSDimitry Andrictemplate <size_t _Size>
457*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
458*700637cbSDimitry Andric  __first_ &= __v.__first_;
459*700637cbSDimitry Andric}
460*700637cbSDimitry Andric
461*700637cbSDimitry Andrictemplate <size_t _Size>
462*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
463*700637cbSDimitry Andric  __first_ |= __v.__first_;
464*700637cbSDimitry Andric}
465*700637cbSDimitry Andric
466*700637cbSDimitry Andrictemplate <size_t _Size>
467*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
468*700637cbSDimitry Andric  __first_ ^= __v.__first_;
469*700637cbSDimitry Andric}
470*700637cbSDimitry Andric
471*700637cbSDimitry Andrictemplate <size_t _Size>
472*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<1, _Size>::flip() _NOEXCEPT {
473*700637cbSDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
474*700637cbSDimitry Andric  __first_           = ~__first_;
475*700637cbSDimitry Andric  __first_ &= __m;
476*700637cbSDimitry Andric}
477*700637cbSDimitry Andric
478*700637cbSDimitry Andrictemplate <size_t _Size>
479*700637cbSDimitry Andricinline unsigned long __bitset<1, _Size>::to_ulong() const {
480*700637cbSDimitry Andric  return __first_;
481*700637cbSDimitry Andric}
482*700637cbSDimitry Andric
483*700637cbSDimitry Andrictemplate <size_t _Size>
484*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long long __bitset<1, _Size>::to_ullong() const {
485*700637cbSDimitry Andric  return __first_;
486*700637cbSDimitry Andric}
487*700637cbSDimitry Andric
488*700637cbSDimitry Andrictemplate <size_t _Size>
489*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool __bitset<1, _Size>::all() const _NOEXCEPT {
490*700637cbSDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
491*700637cbSDimitry Andric  return !(~__first_ & __m);
492*700637cbSDimitry Andric}
493*700637cbSDimitry Andric
494*700637cbSDimitry Andrictemplate <size_t _Size>
495*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool __bitset<1, _Size>::any() const _NOEXCEPT {
496*700637cbSDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
497*700637cbSDimitry Andric  return __first_ & __m;
498*700637cbSDimitry Andric}
499*700637cbSDimitry Andric
500*700637cbSDimitry Andrictemplate <size_t _Size>
501*700637cbSDimitry Andricinline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
502*700637cbSDimitry Andric  return __first_;
503*700637cbSDimitry Andric}
504*700637cbSDimitry Andric
505*700637cbSDimitry Andrictemplate <>
506*700637cbSDimitry Andricclass __bitset<0, 0> {
507*700637cbSDimitry Andricpublic:
508*700637cbSDimitry Andric  typedef ptrdiff_t difference_type;
509*700637cbSDimitry Andric  typedef size_t size_type;
510*700637cbSDimitry Andric  typedef size_type __storage_type;
511*700637cbSDimitry Andric
512*700637cbSDimitry Andricprotected:
513*700637cbSDimitry Andric  typedef __bitset __self;
514*700637cbSDimitry Andric  typedef __storage_type* __storage_pointer;
515*700637cbSDimitry Andric  typedef const __storage_type* __const_storage_pointer;
516*700637cbSDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
517*700637cbSDimitry Andric
518*700637cbSDimitry Andric  friend class __bit_reference<__bitset>;
519*700637cbSDimitry Andric  friend class __bit_const_reference<__bitset>;
520*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, false>;
521*700637cbSDimitry Andric  friend class __bit_iterator<__bitset, true>;
522*700637cbSDimitry Andric  friend struct __bit_array<__bitset>;
523*700637cbSDimitry Andric
524*700637cbSDimitry Andric  typedef __bit_reference<__bitset> reference;
525*700637cbSDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
526*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
527*700637cbSDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
528*700637cbSDimitry Andric
529*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __bitset() _NOEXCEPT;
530*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __bitset(unsigned long long) _NOEXCEPT;
531*700637cbSDimitry Andric
532*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference __make_ref(size_t) _NOEXCEPT { return reference(nullptr, 1); }
533*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference __make_ref(size_t) const _NOEXCEPT { return const_reference(nullptr, 1); }
534*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __make_iter(size_t) _NOEXCEPT { return iterator(nullptr, 0); }
535*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(size_t) const _NOEXCEPT { return const_iterator(nullptr, 0); }
536*700637cbSDimitry Andric
537*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator&=(const __bitset&) _NOEXCEPT {}
538*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator|=(const __bitset&) _NOEXCEPT {}
539*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator^=(const __bitset&) _NOEXCEPT {}
540*700637cbSDimitry Andric
541*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void flip() _NOEXCEPT {}
542*700637cbSDimitry Andric
543*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong() const { return 0; }
544*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong() const { return 0; }
545*700637cbSDimitry Andric
546*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool all() const _NOEXCEPT { return true; }
547*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool any() const _NOEXCEPT { return false; }
548*700637cbSDimitry Andric
549*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }
550*700637cbSDimitry Andric};
551*700637cbSDimitry Andric
552*700637cbSDimitry Andricinline __bitset<0, 0>::__bitset() _NOEXCEPT {}
553*700637cbSDimitry Andric
554*700637cbSDimitry Andricinline __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
555*700637cbSDimitry Andric
556*700637cbSDimitry Andrictemplate <size_t _Size>
557*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset;
558*700637cbSDimitry Andrictemplate <size_t _Size>
559*700637cbSDimitry Andricstruct hash<bitset<_Size> >;
560*700637cbSDimitry Andric
561*700637cbSDimitry Andrictemplate <size_t _Size>
562*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset
563*700637cbSDimitry Andric    : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
564*700637cbSDimitry Andricpublic:
565*700637cbSDimitry Andric  static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
566*700637cbSDimitry Andric  typedef __bitset<__n_words, _Size> base;
567*700637cbSDimitry Andric
568*700637cbSDimitry Andricpublic:
569*700637cbSDimitry Andric  typedef typename base::reference reference;
570*700637cbSDimitry Andric  typedef typename base::const_reference const_reference;
571*700637cbSDimitry Andric
572*700637cbSDimitry Andric  // 23.3.5.1 constructors:
573*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset() _NOEXCEPT {}
574*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
575*700637cbSDimitry Andric  template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
576*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit bitset(
577*700637cbSDimitry Andric      const _CharT* __str,
578*700637cbSDimitry Andric      typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
579*700637cbSDimitry Andric      _CharT __zero                                = _CharT('0'),
580*700637cbSDimitry Andric      _CharT __one                                 = _CharT('1')) {
581*700637cbSDimitry Andric    size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
582*700637cbSDimitry Andric    __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
583*700637cbSDimitry Andric  }
584*700637cbSDimitry Andric
585*700637cbSDimitry Andric  template <class _CharT, class _Traits, class _Allocator>
586*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit bitset(
587*700637cbSDimitry Andric      const basic_string<_CharT, _Traits, _Allocator>& __str,
588*700637cbSDimitry Andric      typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,
589*700637cbSDimitry Andric      typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =
590*700637cbSDimitry Andric          basic_string<_CharT, _Traits, _Allocator>::npos,
591*700637cbSDimitry Andric      _CharT __zero = _CharT('0'),
592*700637cbSDimitry Andric      _CharT __one  = _CharT('1')) {
593*700637cbSDimitry Andric    if (__pos > __str.size())
594*700637cbSDimitry Andric      std::__throw_out_of_range("bitset string pos out of range");
595*700637cbSDimitry Andric
596*700637cbSDimitry Andric    size_t __rlen = std::min(__n, __str.size() - __pos);
597*700637cbSDimitry Andric    __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
598*700637cbSDimitry Andric  }
599*700637cbSDimitry Andric
600*700637cbSDimitry Andric  // 23.3.5.2 bitset operations:
601*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
602*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
603*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
604*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& operator<<=(size_t __pos) _NOEXCEPT;
605*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& operator>>=(size_t __pos) _NOEXCEPT;
606*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& set() _NOEXCEPT;
607*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& set(size_t __pos, bool __val = true);
608*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& reset() _NOEXCEPT;
609*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& reset(size_t __pos);
610*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset operator~() const _NOEXCEPT;
611*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& flip() _NOEXCEPT;
612*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset& flip(size_t __pos);
613*700637cbSDimitry Andric
614*700637cbSDimitry Andric  // element access:
615*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
616*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator[](size_t __p) const { return base::__make_ref(__p); }
617*700637cbSDimitry Andric#else
618*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_t __p) const { return base::__make_ref(__p); }
619*700637cbSDimitry Andric#endif
620*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __p) { return base::__make_ref(__p); }
621*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long to_ulong() const;
622*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong() const;
623*700637cbSDimitry Andric  template <class _CharT, class _Traits, class _Allocator>
624*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _Traits, _Allocator>
625*700637cbSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
626*700637cbSDimitry Andric  template <class _CharT, class _Traits>
627*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _Traits, allocator<_CharT> >
628*700637cbSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
629*700637cbSDimitry Andric  template <class _CharT>
630*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
631*700637cbSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
632*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string<char, char_traits<char>, allocator<char> >
633*700637cbSDimitry Andric  to_string(char __zero = '0', char __one = '1') const;
634*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t count() const _NOEXCEPT;
635*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t size() const _NOEXCEPT { return _Size; }
636*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator==(const bitset& __rhs) const _NOEXCEPT;
637*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
638*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool test(size_t __pos) const;
639*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool all() const _NOEXCEPT;
640*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool any() const _NOEXCEPT;
641*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool none() const _NOEXCEPT { return !any(); }
642*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset operator<<(size_t __pos) const _NOEXCEPT;
643*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bitset operator>>(size_t __pos) const _NOEXCEPT;
644*700637cbSDimitry Andric
645*700637cbSDimitry Andricprivate:
646*700637cbSDimitry Andric  template <class _CharT, class _Traits>
647*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void
648*700637cbSDimitry Andric  __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {
649*700637cbSDimitry Andric    for (size_t __i = 0; __i < __str.size(); ++__i)
650*700637cbSDimitry Andric      if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
651*700637cbSDimitry Andric        std::__throw_invalid_argument("bitset string ctor has invalid argument");
652*700637cbSDimitry Andric
653*700637cbSDimitry Andric    size_t __mp = std::min(__str.size(), _Size);
654*700637cbSDimitry Andric    size_t __i  = 0;
655*700637cbSDimitry Andric    for (; __i < __mp; ++__i) {
656*700637cbSDimitry Andric      _CharT __c   = __str[__mp - 1 - __i];
657*700637cbSDimitry Andric      (*this)[__i] = _Traits::eq(__c, __one);
658*700637cbSDimitry Andric    }
659*700637cbSDimitry Andric    std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
660*700637cbSDimitry Andric  }
661*700637cbSDimitry Andric
662*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }
663*700637cbSDimitry Andric
664*700637cbSDimitry Andric  friend struct hash<bitset>;
665*700637cbSDimitry Andric};
666*700637cbSDimitry Andric
667*700637cbSDimitry Andrictemplate <size_t _Size>
668*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
669*700637cbSDimitry Andric  base::operator&=(__rhs);
670*700637cbSDimitry Andric  return *this;
671*700637cbSDimitry Andric}
672*700637cbSDimitry Andric
673*700637cbSDimitry Andrictemplate <size_t _Size>
674*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
675*700637cbSDimitry Andric  base::operator|=(__rhs);
676*700637cbSDimitry Andric  return *this;
677*700637cbSDimitry Andric}
678*700637cbSDimitry Andric
679*700637cbSDimitry Andrictemplate <size_t _Size>
680*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
681*700637cbSDimitry Andric  base::operator^=(__rhs);
682*700637cbSDimitry Andric  return *this;
683*700637cbSDimitry Andric}
684*700637cbSDimitry Andric
685*700637cbSDimitry Andrictemplate <size_t _Size>
686*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
687*700637cbSDimitry Andric  __pos = std::min(__pos, _Size);
688*700637cbSDimitry Andric  std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
689*700637cbSDimitry Andric  std::fill_n(base::__make_iter(0), __pos, false);
690*700637cbSDimitry Andric  return *this;
691*700637cbSDimitry Andric}
692*700637cbSDimitry Andric
693*700637cbSDimitry Andrictemplate <size_t _Size>
694*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {
695*700637cbSDimitry Andric  __pos = std::min(__pos, _Size);
696*700637cbSDimitry Andric  std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
697*700637cbSDimitry Andric  std::fill_n(base::__make_iter(_Size - __pos), __pos, false);
698*700637cbSDimitry Andric  return *this;
699*700637cbSDimitry Andric}
700*700637cbSDimitry Andric
701*700637cbSDimitry Andrictemplate <size_t _Size>
702*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
703*700637cbSDimitry Andric  std::fill_n(base::__make_iter(0), _Size, true);
704*700637cbSDimitry Andric  return *this;
705*700637cbSDimitry Andric}
706*700637cbSDimitry Andric
707*700637cbSDimitry Andrictemplate <size_t _Size>
708*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
709*700637cbSDimitry Andric  if (__pos >= _Size)
710*700637cbSDimitry Andric    __throw_out_of_range("bitset set argument out of range");
711*700637cbSDimitry Andric
712*700637cbSDimitry Andric  (*this)[__pos] = __val;
713*700637cbSDimitry Andric  return *this;
714*700637cbSDimitry Andric}
715*700637cbSDimitry Andric
716*700637cbSDimitry Andrictemplate <size_t _Size>
717*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
718*700637cbSDimitry Andric  std::fill_n(base::__make_iter(0), _Size, false);
719*700637cbSDimitry Andric  return *this;
720*700637cbSDimitry Andric}
721*700637cbSDimitry Andric
722*700637cbSDimitry Andrictemplate <size_t _Size>
723*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
724*700637cbSDimitry Andric  if (__pos >= _Size)
725*700637cbSDimitry Andric    __throw_out_of_range("bitset reset argument out of range");
726*700637cbSDimitry Andric
727*700637cbSDimitry Andric  (*this)[__pos] = false;
728*700637cbSDimitry Andric  return *this;
729*700637cbSDimitry Andric}
730*700637cbSDimitry Andric
731*700637cbSDimitry Andrictemplate <size_t _Size>
732*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {
733*700637cbSDimitry Andric  bitset __x(*this);
734*700637cbSDimitry Andric  __x.flip();
735*700637cbSDimitry Andric  return __x;
736*700637cbSDimitry Andric}
737*700637cbSDimitry Andric
738*700637cbSDimitry Andrictemplate <size_t _Size>
739*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
740*700637cbSDimitry Andric  base::flip();
741*700637cbSDimitry Andric  return *this;
742*700637cbSDimitry Andric}
743*700637cbSDimitry Andric
744*700637cbSDimitry Andrictemplate <size_t _Size>
745*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
746*700637cbSDimitry Andric  if (__pos >= _Size)
747*700637cbSDimitry Andric    __throw_out_of_range("bitset flip argument out of range");
748*700637cbSDimitry Andric
749*700637cbSDimitry Andric  reference __r = base::__make_ref(__pos);
750*700637cbSDimitry Andric  __r           = ~__r;
751*700637cbSDimitry Andric  return *this;
752*700637cbSDimitry Andric}
753*700637cbSDimitry Andric
754*700637cbSDimitry Andrictemplate <size_t _Size>
755*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long bitset<_Size>::to_ulong() const {
756*700637cbSDimitry Andric  return base::to_ulong();
757*700637cbSDimitry Andric}
758*700637cbSDimitry Andric
759*700637cbSDimitry Andrictemplate <size_t _Size>
760*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned long long bitset<_Size>::to_ullong() const {
761*700637cbSDimitry Andric  return base::to_ullong();
762*700637cbSDimitry Andric}
763*700637cbSDimitry Andric
764*700637cbSDimitry Andrictemplate <size_t _Size>
765*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
766*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _Traits, _Allocator>
767*700637cbSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
768*700637cbSDimitry Andric  basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
769*700637cbSDimitry Andric  for (size_t __i = 0; __i != _Size; ++__i) {
770*700637cbSDimitry Andric    if ((*this)[__i])
771*700637cbSDimitry Andric      __r[_Size - 1 - __i] = __one;
772*700637cbSDimitry Andric  }
773*700637cbSDimitry Andric  return __r;
774*700637cbSDimitry Andric}
775*700637cbSDimitry Andric
776*700637cbSDimitry Andrictemplate <size_t _Size>
777*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
778*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _Traits, allocator<_CharT> >
779*700637cbSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
780*700637cbSDimitry Andric  return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
781*700637cbSDimitry Andric}
782*700637cbSDimitry Andric
783*700637cbSDimitry Andrictemplate <size_t _Size>
784*700637cbSDimitry Andrictemplate <class _CharT>
785*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
786*700637cbSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
787*700637cbSDimitry Andric  return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
788*700637cbSDimitry Andric}
789*700637cbSDimitry Andric
790*700637cbSDimitry Andrictemplate <size_t _Size>
791*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<char, char_traits<char>, allocator<char> >
792*700637cbSDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const {
793*700637cbSDimitry Andric  return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
794*700637cbSDimitry Andric}
795*700637cbSDimitry Andric
796*700637cbSDimitry Andrictemplate <size_t _Size>
797*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI size_t bitset<_Size>::count() const _NOEXCEPT {
798*700637cbSDimitry Andric  return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));
799*700637cbSDimitry Andric}
800*700637cbSDimitry Andric
801*700637cbSDimitry Andrictemplate <size_t _Size>
802*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
803*700637cbSDimitry Andric  return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
804*700637cbSDimitry Andric}
805*700637cbSDimitry Andric
806*700637cbSDimitry Andrictemplate <size_t _Size>
807*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
808*700637cbSDimitry Andric  return !(*this == __rhs);
809*700637cbSDimitry Andric}
810*700637cbSDimitry Andric
811*700637cbSDimitry Andrictemplate <size_t _Size>
812*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::test(size_t __pos) const {
813*700637cbSDimitry Andric  if (__pos >= _Size)
814*700637cbSDimitry Andric    __throw_out_of_range("bitset test argument out of range");
815*700637cbSDimitry Andric
816*700637cbSDimitry Andric  return (*this)[__pos];
817*700637cbSDimitry Andric}
818*700637cbSDimitry Andric
819*700637cbSDimitry Andrictemplate <size_t _Size>
820*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::all() const _NOEXCEPT {
821*700637cbSDimitry Andric  return base::all();
822*700637cbSDimitry Andric}
823*700637cbSDimitry Andric
824*700637cbSDimitry Andrictemplate <size_t _Size>
825*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::any() const _NOEXCEPT {
826*700637cbSDimitry Andric  return base::any();
827*700637cbSDimitry Andric}
828*700637cbSDimitry Andric
829*700637cbSDimitry Andrictemplate <size_t _Size>
830*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
831*700637cbSDimitry Andric  bitset __r = *this;
832*700637cbSDimitry Andric  __r <<= __pos;
833*700637cbSDimitry Andric  return __r;
834*700637cbSDimitry Andric}
835*700637cbSDimitry Andric
836*700637cbSDimitry Andrictemplate <size_t _Size>
837*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {
838*700637cbSDimitry Andric  bitset __r = *this;
839*700637cbSDimitry Andric  __r >>= __pos;
840*700637cbSDimitry Andric  return __r;
841*700637cbSDimitry Andric}
842*700637cbSDimitry Andric
843*700637cbSDimitry Andrictemplate <size_t _Size>
844*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
845*700637cbSDimitry Andric  bitset<_Size> __r = __x;
846*700637cbSDimitry Andric  __r &= __y;
847*700637cbSDimitry Andric  return __r;
848*700637cbSDimitry Andric}
849*700637cbSDimitry Andric
850*700637cbSDimitry Andrictemplate <size_t _Size>
851*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
852*700637cbSDimitry Andric  bitset<_Size> __r = __x;
853*700637cbSDimitry Andric  __r |= __y;
854*700637cbSDimitry Andric  return __r;
855*700637cbSDimitry Andric}
856*700637cbSDimitry Andric
857*700637cbSDimitry Andrictemplate <size_t _Size>
858*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bitset<_Size> operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
859*700637cbSDimitry Andric  bitset<_Size> __r = __x;
860*700637cbSDimitry Andric  __r ^= __y;
861*700637cbSDimitry Andric  return __r;
862*700637cbSDimitry Andric}
863*700637cbSDimitry Andric
864*700637cbSDimitry Andrictemplate <size_t _Size>
865*700637cbSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
866*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
867*700637cbSDimitry Andric};
868*700637cbSDimitry Andric
869*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size>
870*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
871*700637cbSDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
872*700637cbSDimitry Andric
873*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size>
874*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
875*700637cbSDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
876*700637cbSDimitry Andric
877*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD
878*700637cbSDimitry Andric
879*700637cbSDimitry Andric_LIBCPP_POP_MACROS
880*700637cbSDimitry Andric
881*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
882*700637cbSDimitry Andric#  include <__cxx03/cstdlib>
883*700637cbSDimitry Andric#  include <__cxx03/type_traits>
884*700637cbSDimitry Andric#endif
885*700637cbSDimitry Andric
886*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_BITSET
887