2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP___BIT_REFERENCE
12 #define _LIBCPP___BIT_REFERENCE
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #pragma GCC system_header
22 #include <__undef_macros>
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
28 template <class _Cp> class __bit_const_reference;
31 struct __has_storage_type
33 static const bool value = false;
36 template <class _Cp, bool = __has_storage_type<_Cp>::value>
39 typedef typename _Cp::__storage_type __storage_type;
40 typedef typename _Cp::__storage_pointer __storage_pointer;
42 __storage_pointer __seg_;
43 __storage_type __mask_;
45 friend typename _Cp::__self;
47 friend class __bit_const_reference<_Cp>;
48 friend class __bit_iterator<_Cp, false>;
50 _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
51 {return static_cast<bool>(*__seg_ & __mask_);}
52 _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT
53 {return !static_cast<bool>(*this);}
55 _LIBCPP_INLINE_VISIBILITY
56 __bit_reference& operator=(bool __x) _NOEXCEPT
65 _LIBCPP_INLINE_VISIBILITY
66 __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT
67 {return operator=(static_cast<bool>(__x));}
69 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;}
70 _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT
71 {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
73 _LIBCPP_INLINE_VISIBILITY
74 __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
75 : __seg_(__s), __mask_(__m) {}
79 class __bit_reference<_Cp, false>
84 inline _LIBCPP_INLINE_VISIBILITY
86 swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
93 template <class _Cp, class _Dp>
94 inline _LIBCPP_INLINE_VISIBILITY
96 swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
104 inline _LIBCPP_INLINE_VISIBILITY
106 swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
114 inline _LIBCPP_INLINE_VISIBILITY
116 swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT
124 class __bit_const_reference
126 typedef typename _Cp::__storage_type __storage_type;
127 typedef typename _Cp::__const_storage_pointer __storage_pointer;
129 __storage_pointer __seg_;
130 __storage_type __mask_;
132 friend typename _Cp::__self;
133 friend class __bit_iterator<_Cp, true>;
135 _LIBCPP_INLINE_VISIBILITY
136 __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
137 : __seg_(__x.__seg_), __mask_(__x.__mask_) {}
139 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
140 {return static_cast<bool>(*__seg_ & __mask_);}
142 _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
143 {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
145 _LIBCPP_INLINE_VISIBILITY
147 __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
148 : __seg_(__s), __mask_(__m) {}
150 __bit_const_reference& operator=(const __bit_const_reference& __x);
155 template <class _Cp, bool _IsConst>
156 __bit_iterator<_Cp, _IsConst>
157 __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
159 typedef __bit_iterator<_Cp, _IsConst> _It;
160 typedef typename _It::__storage_type __storage_type;
161 static const int __bits_per_word = _It::__bits_per_word;
162 // do first partial word
163 if (__first.__ctz_ != 0)
165 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
166 __storage_type __dn = _VSTD::min(__clz_f, __n);
167 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
168 __storage_type __b = *__first.__seg_ & __m;
170 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
172 return __first + __n;
176 // do middle whole words
177 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
179 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(*__first.__seg_)));
180 // do last partial word
183 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
184 __storage_type __b = *__first.__seg_ & __m;
186 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
188 return _It(__first.__seg_, static_cast<unsigned>(__n));
191 template <class _Cp, bool _IsConst>
192 __bit_iterator<_Cp, _IsConst>
193 __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
195 typedef __bit_iterator<_Cp, _IsConst> _It;
196 typedef typename _It::__storage_type __storage_type;
197 const int __bits_per_word = _It::__bits_per_word;
198 // do first partial word
199 if (__first.__ctz_ != 0)
201 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
202 __storage_type __dn = _VSTD::min(__clz_f, __n);
203 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
204 __storage_type __b = ~*__first.__seg_ & __m;
206 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
208 return __first + __n;
212 // do middle whole words
213 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
215 __storage_type __b = ~*__first.__seg_;
217 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
219 // do last partial word
222 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
223 __storage_type __b = ~*__first.__seg_ & __m;
225 return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
227 return _It(__first.__seg_, static_cast<unsigned>(__n));
230 template <class _Cp, bool _IsConst, class _Tp>
231 inline _LIBCPP_INLINE_VISIBILITY
232 __bit_iterator<_Cp, _IsConst>
233 find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
235 if (static_cast<bool>(__value_))
236 return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
237 return __find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
242 template <class _Cp, bool _IsConst>
243 typename __bit_iterator<_Cp, _IsConst>::difference_type
244 __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
246 typedef __bit_iterator<_Cp, _IsConst> _It;
247 typedef typename _It::__storage_type __storage_type;
248 typedef typename _It::difference_type difference_type;
249 const int __bits_per_word = _It::__bits_per_word;
250 difference_type __r = 0;
251 // do first partial word
252 if (__first.__ctz_ != 0)
254 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
255 __storage_type __dn = _VSTD::min(__clz_f, __n);
256 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
257 __r = _VSTD::__pop_count(*__first.__seg_ & __m);
261 // do middle whole words
262 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
263 __r += _VSTD::__pop_count(*__first.__seg_);
264 // do last partial word
267 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
268 __r += _VSTD::__pop_count(*__first.__seg_ & __m);
273 template <class _Cp, bool _IsConst>
274 typename __bit_iterator<_Cp, _IsConst>::difference_type
275 __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
277 typedef __bit_iterator<_Cp, _IsConst> _It;
278 typedef typename _It::__storage_type __storage_type;
279 typedef typename _It::difference_type difference_type;
280 const int __bits_per_word = _It::__bits_per_word;
281 difference_type __r = 0;
282 // do first partial word
283 if (__first.__ctz_ != 0)
285 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
286 __storage_type __dn = _VSTD::min(__clz_f, __n);
287 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
288 __r = _VSTD::__pop_count(~*__first.__seg_ & __m);
292 // do middle whole words
293 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
294 __r += _VSTD::__pop_count(~*__first.__seg_);
295 // do last partial word
298 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
299 __r += _VSTD::__pop_count(~*__first.__seg_ & __m);
304 template <class _Cp, bool _IsConst, class _Tp>
305 inline _LIBCPP_INLINE_VISIBILITY
306 typename __bit_iterator<_Cp, _IsConst>::difference_type
307 count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
309 if (static_cast<bool>(__value_))
310 return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
311 return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
318 __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
320 typedef __bit_iterator<_Cp, false> _It;
321 typedef typename _It::__storage_type __storage_type;
322 const int __bits_per_word = _It::__bits_per_word;
323 // do first partial word
324 if (__first.__ctz_ != 0)
326 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
327 __storage_type __dn = _VSTD::min(__clz_f, __n);
328 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
329 *__first.__seg_ &= ~__m;
333 // do middle whole words
334 __storage_type __nw = __n / __bits_per_word;
335 _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type));
336 __n -= __nw * __bits_per_word;
337 // do last partial word
340 __first.__seg_ += __nw;
341 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
342 *__first.__seg_ &= ~__m;
348 __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
350 typedef __bit_iterator<_Cp, false> _It;
351 typedef typename _It::__storage_type __storage_type;
352 const int __bits_per_word = _It::__bits_per_word;
353 // do first partial word
354 if (__first.__ctz_ != 0)
356 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
357 __storage_type __dn = _VSTD::min(__clz_f, __n);
358 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
359 *__first.__seg_ |= __m;
363 // do middle whole words
364 __storage_type __nw = __n / __bits_per_word;
365 _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type));
366 __n -= __nw * __bits_per_word;
367 // do last partial word
370 __first.__seg_ += __nw;
371 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
372 *__first.__seg_ |= __m;
377 inline _LIBCPP_INLINE_VISIBILITY
379 fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_)
384 __fill_n_true(__first, __n);
386 __fill_n_false(__first, __n);
393 inline _LIBCPP_INLINE_VISIBILITY
395 fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_)
397 _VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value_);
402 template <class _Cp, bool _IsConst>
403 __bit_iterator<_Cp, false>
404 __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
405 __bit_iterator<_Cp, false> __result)
407 typedef __bit_iterator<_Cp, _IsConst> _In;
408 typedef typename _In::difference_type difference_type;
409 typedef typename _In::__storage_type __storage_type;
410 const int __bits_per_word = _In::__bits_per_word;
411 difference_type __n = __last - __first;
415 if (__first.__ctz_ != 0)
417 unsigned __clz = __bits_per_word - __first.__ctz_;
418 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
420 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
421 __storage_type __b = *__first.__seg_ & __m;
422 *__result.__seg_ &= ~__m;
423 *__result.__seg_ |= __b;
424 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
425 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
427 // __first.__ctz_ = 0;
429 // __first.__ctz_ == 0;
431 __storage_type __nw = __n / __bits_per_word;
432 _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
433 _VSTD::__to_raw_pointer(__first.__seg_),
434 __nw * sizeof(__storage_type));
435 __n -= __nw * __bits_per_word;
436 __result.__seg_ += __nw;
440 __first.__seg_ += __nw;
441 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
442 __storage_type __b = *__first.__seg_ & __m;
443 *__result.__seg_ &= ~__m;
444 *__result.__seg_ |= __b;
445 __result.__ctz_ = static_cast<unsigned>(__n);
451 template <class _Cp, bool _IsConst>
452 __bit_iterator<_Cp, false>
453 __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
454 __bit_iterator<_Cp, false> __result)
456 typedef __bit_iterator<_Cp, _IsConst> _In;
457 typedef typename _In::difference_type difference_type;
458 typedef typename _In::__storage_type __storage_type;
459 static const int __bits_per_word = _In::__bits_per_word;
460 difference_type __n = __last - __first;
464 if (__first.__ctz_ != 0)
466 unsigned __clz_f = __bits_per_word - __first.__ctz_;
467 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
469 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
470 __storage_type __b = *__first.__seg_ & __m;
471 unsigned __clz_r = __bits_per_word - __result.__ctz_;
472 __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
473 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
474 *__result.__seg_ &= ~__m;
475 if (__result.__ctz_ > __first.__ctz_)
476 *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
478 *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
479 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
480 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
484 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
485 *__result.__seg_ &= ~__m;
486 *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
487 __result.__ctz_ = static_cast<unsigned>(__dn);
490 // __first.__ctz_ = 0;
492 // __first.__ctz_ == 0;
494 unsigned __clz_r = __bits_per_word - __result.__ctz_;
495 __storage_type __m = ~__storage_type(0) << __result.__ctz_;
496 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
498 __storage_type __b = *__first.__seg_;
499 *__result.__seg_ &= ~__m;
500 *__result.__seg_ |= __b << __result.__ctz_;
502 *__result.__seg_ &= __m;
503 *__result.__seg_ |= __b >> __clz_r;
508 __m = ~__storage_type(0) >> (__bits_per_word - __n);
509 __storage_type __b = *__first.__seg_ & __m;
510 __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
511 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
512 *__result.__seg_ &= ~__m;
513 *__result.__seg_ |= __b << __result.__ctz_;
514 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
515 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
519 __m = ~__storage_type(0) >> (__bits_per_word - __n);
520 *__result.__seg_ &= ~__m;
521 *__result.__seg_ |= __b >> __dn;
522 __result.__ctz_ = static_cast<unsigned>(__n);
529 template <class _Cp, bool _IsConst>
530 inline _LIBCPP_INLINE_VISIBILITY
531 __bit_iterator<_Cp, false>
532 copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
534 if (__first.__ctz_ == __result.__ctz_)
535 return __copy_aligned(__first, __last, __result);
536 return __copy_unaligned(__first, __last, __result);
541 template <class _Cp, bool _IsConst>
542 __bit_iterator<_Cp, false>
543 __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
544 __bit_iterator<_Cp, false> __result)
546 typedef __bit_iterator<_Cp, _IsConst> _In;
547 typedef typename _In::difference_type difference_type;
548 typedef typename _In::__storage_type __storage_type;
549 const int __bits_per_word = _In::__bits_per_word;
550 difference_type __n = __last - __first;
554 if (__last.__ctz_ != 0)
556 difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
558 unsigned __clz = __bits_per_word - __last.__ctz_;
559 __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz);
560 __storage_type __b = *__last.__seg_ & __m;
561 *__result.__seg_ &= ~__m;
562 *__result.__seg_ |= __b;
563 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
564 __result.__ctz_) % __bits_per_word);
567 // __last.__ctz_ == 0 || __n == 0
568 // __result.__ctz_ == 0 || __n == 0
570 __storage_type __nw = __n / __bits_per_word;
571 __result.__seg_ -= __nw;
572 __last.__seg_ -= __nw;
573 _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
574 _VSTD::__to_raw_pointer(__last.__seg_),
575 __nw * sizeof(__storage_type));
576 __n -= __nw * __bits_per_word;
580 __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n);
581 __storage_type __b = *--__last.__seg_ & __m;
582 *--__result.__seg_ &= ~__m;
583 *__result.__seg_ |= __b;
584 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
590 template <class _Cp, bool _IsConst>
591 __bit_iterator<_Cp, false>
592 __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
593 __bit_iterator<_Cp, false> __result)
595 typedef __bit_iterator<_Cp, _IsConst> _In;
596 typedef typename _In::difference_type difference_type;
597 typedef typename _In::__storage_type __storage_type;
598 const int __bits_per_word = _In::__bits_per_word;
599 difference_type __n = __last - __first;
603 if (__last.__ctz_ != 0)
605 difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
607 unsigned __clz_l = __bits_per_word - __last.__ctz_;
608 __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l);
609 __storage_type __b = *__last.__seg_ & __m;
610 unsigned __clz_r = __bits_per_word - __result.__ctz_;
611 __storage_type __ddn = _VSTD::min(__dn, static_cast<difference_type>(__result.__ctz_));
614 __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r);
615 *__result.__seg_ &= ~__m;
616 if (__result.__ctz_ > __last.__ctz_)
617 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
619 *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
620 __result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) +
621 __result.__ctz_) % __bits_per_word);
626 // __result.__ctz_ == 0
628 __result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
629 __m = ~__storage_type(0) << __result.__ctz_;
630 *__result.__seg_ &= ~__m;
631 __last.__ctz_ -= __dn + __ddn;
632 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
636 // __last.__ctz_ == 0 || __n == 0
637 // __result.__ctz_ != 0 || __n == 0
639 unsigned __clz_r = __bits_per_word - __result.__ctz_;
640 __storage_type __m = ~__storage_type(0) >> __clz_r;
641 for (; __n >= __bits_per_word; __n -= __bits_per_word)
643 __storage_type __b = *--__last.__seg_;
644 *__result.__seg_ &= ~__m;
645 *__result.__seg_ |= __b >> __clz_r;
646 *--__result.__seg_ &= __m;
647 *__result.__seg_ |= __b << __result.__ctz_;
652 __m = ~__storage_type(0) << (__bits_per_word - __n);
653 __storage_type __b = *--__last.__seg_ & __m;
654 __clz_r = __bits_per_word - __result.__ctz_;
655 __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__result.__ctz_));
656 __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
657 *__result.__seg_ &= ~__m;
658 *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
659 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
660 __result.__ctz_) % __bits_per_word);
664 // __result.__ctz_ == 0
666 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
667 __m = ~__storage_type(0) << __result.__ctz_;
668 *__result.__seg_ &= ~__m;
669 *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
676 template <class _Cp, bool _IsConst>
677 inline _LIBCPP_INLINE_VISIBILITY
678 __bit_iterator<_Cp, false>
679 copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
681 if (__last.__ctz_ == __result.__ctz_)
682 return __copy_backward_aligned(__first, __last, __result);
683 return __copy_backward_unaligned(__first, __last, __result);
688 template <class _Cp, bool _IsConst>
689 inline _LIBCPP_INLINE_VISIBILITY
690 __bit_iterator<_Cp, false>
691 move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
693 return _VSTD::copy(__first, __last, __result);
698 template <class _Cp, bool _IsConst>
699 inline _LIBCPP_INLINE_VISIBILITY
700 __bit_iterator<_Cp, false>
701 move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
703 return _VSTD::copy_backward(__first, __last, __result);
708 template <class __C1, class __C2>
709 __bit_iterator<__C2, false>
710 __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
711 __bit_iterator<__C2, false> __result)
713 typedef __bit_iterator<__C1, false> _I1;
714 typedef typename _I1::difference_type difference_type;
715 typedef typename _I1::__storage_type __storage_type;
716 const int __bits_per_word = _I1::__bits_per_word;
717 difference_type __n = __last - __first;
721 if (__first.__ctz_ != 0)
723 unsigned __clz = __bits_per_word - __first.__ctz_;
724 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
726 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
727 __storage_type __b1 = *__first.__seg_ & __m;
728 *__first.__seg_ &= ~__m;
729 __storage_type __b2 = *__result.__seg_ & __m;
730 *__result.__seg_ &= ~__m;
731 *__result.__seg_ |= __b1;
732 *__first.__seg_ |= __b2;
733 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
734 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
736 // __first.__ctz_ = 0;
738 // __first.__ctz_ == 0;
740 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_)
741 swap(*__first.__seg_, *__result.__seg_);
745 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
746 __storage_type __b1 = *__first.__seg_ & __m;
747 *__first.__seg_ &= ~__m;
748 __storage_type __b2 = *__result.__seg_ & __m;
749 *__result.__seg_ &= ~__m;
750 *__result.__seg_ |= __b1;
751 *__first.__seg_ |= __b2;
752 __result.__ctz_ = static_cast<unsigned>(__n);
758 template <class __C1, class __C2>
759 __bit_iterator<__C2, false>
760 __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
761 __bit_iterator<__C2, false> __result)
763 typedef __bit_iterator<__C1, false> _I1;
764 typedef typename _I1::difference_type difference_type;
765 typedef typename _I1::__storage_type __storage_type;
766 const int __bits_per_word = _I1::__bits_per_word;
767 difference_type __n = __last - __first;
771 if (__first.__ctz_ != 0)
773 unsigned __clz_f = __bits_per_word - __first.__ctz_;
774 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
776 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
777 __storage_type __b1 = *__first.__seg_ & __m;
778 *__first.__seg_ &= ~__m;
779 unsigned __clz_r = __bits_per_word - __result.__ctz_;
780 __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
781 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
782 __storage_type __b2 = *__result.__seg_ & __m;
783 *__result.__seg_ &= ~__m;
784 if (__result.__ctz_ > __first.__ctz_)
786 unsigned __s = __result.__ctz_ - __first.__ctz_;
787 *__result.__seg_ |= __b1 << __s;
788 *__first.__seg_ |= __b2 >> __s;
792 unsigned __s = __first.__ctz_ - __result.__ctz_;
793 *__result.__seg_ |= __b1 >> __s;
794 *__first.__seg_ |= __b2 << __s;
796 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
797 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
801 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
802 __b2 = *__result.__seg_ & __m;
803 *__result.__seg_ &= ~__m;
804 unsigned __s = __first.__ctz_ + __ddn;
805 *__result.__seg_ |= __b1 >> __s;
806 *__first.__seg_ |= __b2 << __s;
807 __result.__ctz_ = static_cast<unsigned>(__dn);
810 // __first.__ctz_ = 0;
812 // __first.__ctz_ == 0;
814 __storage_type __m = ~__storage_type(0) << __result.__ctz_;
815 unsigned __clz_r = __bits_per_word - __result.__ctz_;
816 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
818 __storage_type __b1 = *__first.__seg_;
819 __storage_type __b2 = *__result.__seg_ & __m;
820 *__result.__seg_ &= ~__m;
821 *__result.__seg_ |= __b1 << __result.__ctz_;
822 *__first.__seg_ = __b2 >> __result.__ctz_;
824 __b2 = *__result.__seg_ & ~__m;
825 *__result.__seg_ &= __m;
826 *__result.__seg_ |= __b1 >> __clz_r;
827 *__first.__seg_ |= __b2 << __clz_r;
832 __m = ~__storage_type(0) >> (__bits_per_word - __n);
833 __storage_type __b1 = *__first.__seg_ & __m;
834 *__first.__seg_ &= ~__m;
835 __storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r);
836 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
837 __storage_type __b2 = *__result.__seg_ & __m;
838 *__result.__seg_ &= ~__m;
839 *__result.__seg_ |= __b1 << __result.__ctz_;
840 *__first.__seg_ |= __b2 >> __result.__ctz_;
841 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
842 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
846 __m = ~__storage_type(0) >> (__bits_per_word - __n);
847 __b2 = *__result.__seg_ & __m;
848 *__result.__seg_ &= ~__m;
849 *__result.__seg_ |= __b1 >> __dn;
850 *__first.__seg_ |= __b2 << __dn;
851 __result.__ctz_ = static_cast<unsigned>(__n);
858 template <class __C1, class __C2>
859 inline _LIBCPP_INLINE_VISIBILITY
860 __bit_iterator<__C2, false>
861 swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1,
862 __bit_iterator<__C2, false> __first2)
864 if (__first1.__ctz_ == __first2.__ctz_)
865 return __swap_ranges_aligned(__first1, __last1, __first2);
866 return __swap_ranges_unaligned(__first1, __last1, __first2);
874 typedef typename _Cp::difference_type difference_type;
875 typedef typename _Cp::__storage_type __storage_type;
876 typedef typename _Cp::__storage_pointer __storage_pointer;
877 typedef typename _Cp::iterator iterator;
878 static const unsigned __bits_per_word = _Cp::__bits_per_word;
879 static const unsigned _Np = 4;
881 difference_type __size_;
882 __storage_type __word_[_Np];
884 _LIBCPP_INLINE_VISIBILITY static difference_type capacity()
885 {return static_cast<difference_type>(_Np * __bits_per_word);}
886 _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
887 _LIBCPP_INLINE_VISIBILITY iterator begin()
889 return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
891 _LIBCPP_INLINE_VISIBILITY iterator end()
893 return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
894 static_cast<unsigned>(__size_ % __bits_per_word));
899 __bit_iterator<_Cp, false>
900 rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last)
902 typedef __bit_iterator<_Cp, false> _I1;
903 typedef typename _I1::difference_type difference_type;
904 difference_type __d1 = __middle - __first;
905 difference_type __d2 = __last - __middle;
906 _I1 __r = __first + __d2;
907 while (__d1 != 0 && __d2 != 0)
911 if (__d1 <= __bit_array<_Cp>::capacity())
913 __bit_array<_Cp> __b(__d1);
914 _VSTD::copy(__first, __middle, __b.begin());
915 _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first));
920 __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle);
928 if (__d2 <= __bit_array<_Cp>::capacity())
930 __bit_array<_Cp> __b(__d2);
931 _VSTD::copy(__middle, __last, __b.begin());
932 _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last));
937 __bit_iterator<_Cp, false> __mp = __first + __d2;
938 _VSTD::swap_ranges(__first, __mp, __middle);
949 template <class _Cp, bool _IC1, bool _IC2>
951 __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
952 __bit_iterator<_Cp, _IC2> __first2)
954 typedef __bit_iterator<_Cp, _IC1> _It;
955 typedef typename _It::difference_type difference_type;
956 typedef typename _It::__storage_type __storage_type;
957 static const int __bits_per_word = _It::__bits_per_word;
958 difference_type __n = __last1 - __first1;
962 if (__first1.__ctz_ != 0)
964 unsigned __clz_f = __bits_per_word - __first1.__ctz_;
965 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
967 __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
968 __storage_type __b = *__first1.__seg_ & __m;
969 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
970 __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
971 __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
972 if (__first2.__ctz_ > __first1.__ctz_)
974 if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_)))
979 if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_)))
982 __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word;
983 __first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_) % __bits_per_word);
987 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
988 if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn)))
990 __first2.__ctz_ = static_cast<unsigned>(__dn);
993 // __first1.__ctz_ = 0;
995 // __first1.__ctz_ == 0;
997 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
998 __storage_type __m = ~__storage_type(0) << __first2.__ctz_;
999 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_)
1001 __storage_type __b = *__first1.__seg_;
1002 if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
1005 if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r))
1011 __m = ~__storage_type(0) >> (__bits_per_word - __n);
1012 __storage_type __b = *__first1.__seg_ & __m;
1013 __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
1014 __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
1015 if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
1017 __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word;
1018 __first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_) % __bits_per_word);
1022 __m = ~__storage_type(0) >> (__bits_per_word - __n);
1023 if ((*__first2.__seg_ & __m) != (__b >> __dn))
1031 template <class _Cp, bool _IC1, bool _IC2>
1033 __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
1034 __bit_iterator<_Cp, _IC2> __first2)
1036 typedef __bit_iterator<_Cp, _IC1> _It;
1037 typedef typename _It::difference_type difference_type;
1038 typedef typename _It::__storage_type __storage_type;
1039 static const int __bits_per_word = _It::__bits_per_word;
1040 difference_type __n = __last1 - __first1;
1044 if (__first1.__ctz_ != 0)
1046 unsigned __clz = __bits_per_word - __first1.__ctz_;
1047 difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
1049 __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
1050 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
1054 // __first1.__ctz_ = 0;
1055 // __first2.__ctz_ = 0;
1057 // __first1.__ctz_ == 0;
1058 // __first2.__ctz_ == 0;
1060 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_)
1061 if (*__first2.__seg_ != *__first1.__seg_)
1066 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
1067 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
1074 template <class _Cp, bool _IC1, bool _IC2>
1075 inline _LIBCPP_INLINE_VISIBILITY
1077 equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2)
1079 if (__first1.__ctz_ == __first2.__ctz_)
1080 return __equal_aligned(__first1, __last1, __first2);
1081 return __equal_unaligned(__first1, __last1, __first2);
1084 template <class _Cp, bool _IsConst,
1085 typename _Cp::__storage_type>
1086 class __bit_iterator
1089 typedef typename _Cp::difference_type difference_type;
1090 typedef bool value_type;
1091 typedef __bit_iterator pointer;
1092 typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference;
1093 typedef random_access_iterator_tag iterator_category;
1096 typedef typename _Cp::__storage_type __storage_type;
1097 typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer,
1098 typename _Cp::__storage_pointer>::type __storage_pointer;
1099 static const unsigned __bits_per_word = _Cp::__bits_per_word;
1101 __storage_pointer __seg_;
1105 _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT
1106 #if _LIBCPP_STD_VER > 11
1107 : __seg_(nullptr), __ctz_(0)
1111 _LIBCPP_INLINE_VISIBILITY
1112 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
1113 : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
1115 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1116 {return reference(__seg_, __storage_type(1) << __ctz_);}
1118 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++()
1120 if (__ctz_ != __bits_per_word-1)
1130 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int)
1132 __bit_iterator __tmp = *this;
1137 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--()
1143 __ctz_ = __bits_per_word - 1;
1149 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int)
1151 __bit_iterator __tmp = *this;
1156 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n)
1159 __seg_ += (__n + __ctz_) / __bits_per_word;
1161 __seg_ += static_cast<difference_type>(__n - __bits_per_word + __ctz_ + 1)
1162 / static_cast<difference_type>(__bits_per_word);
1163 __n &= (__bits_per_word - 1);
1164 __ctz_ = static_cast<unsigned>((__n + __ctz_) % __bits_per_word);
1168 _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n)
1170 return *this += -__n;
1173 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const
1175 __bit_iterator __t(*this);
1180 _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const
1182 __bit_iterator __t(*this);
1187 _LIBCPP_INLINE_VISIBILITY
1188 friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;}
1190 _LIBCPP_INLINE_VISIBILITY
1191 friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y)
1192 {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;}
1194 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);}
1196 _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y)
1197 {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;}
1199 _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y)
1200 {return !(__x == __y);}
1202 _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y)
1203 {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);}
1205 _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y)
1208 _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y)
1209 {return !(__y < __x);}
1211 _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y)
1212 {return !(__x < __y);}
1215 _LIBCPP_INLINE_VISIBILITY
1216 __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
1217 : __seg_(__s), __ctz_(__ctz) {}
1219 friend typename _Cp::__self;
1221 friend class __bit_reference<_Cp>;
1222 friend class __bit_const_reference<_Cp>;
1223 friend class __bit_iterator<_Cp, true>;
1224 template <class _Dp> friend struct __bit_array;
1225 template <class _Dp> friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1226 template <class _Dp> friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1227 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first,
1228 __bit_iterator<_Dp, _IC> __last,
1229 __bit_iterator<_Dp, false> __result);
1230 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first,
1231 __bit_iterator<_Dp, _IC> __last,
1232 __bit_iterator<_Dp, false> __result);
1233 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first,
1234 __bit_iterator<_Dp, _IC> __last,
1235 __bit_iterator<_Dp, false> __result);
1236 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first,
1237 __bit_iterator<_Dp, _IC> __last,
1238 __bit_iterator<_Dp, false> __result);
1239 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first,
1240 __bit_iterator<_Dp, _IC> __last,
1241 __bit_iterator<_Dp, false> __result);
1242 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
1243 __bit_iterator<_Dp, _IC> __last,
1244 __bit_iterator<_Dp, false> __result);
1245 template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
1246 __bit_iterator<__C1, false>,
1247 __bit_iterator<__C2, false>);
1248 template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>,
1249 __bit_iterator<__C1, false>,
1250 __bit_iterator<__C2, false>);
1251 template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
1252 __bit_iterator<__C1, false>,
1253 __bit_iterator<__C2, false>);
1254 template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
1255 __bit_iterator<_Dp, false>,
1256 __bit_iterator<_Dp, false>);
1257 template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
1258 __bit_iterator<_Dp, _IC1>,
1259 __bit_iterator<_Dp, _IC2>);
1260 template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
1261 __bit_iterator<_Dp, _IC1>,
1262 __bit_iterator<_Dp, _IC2>);
1263 template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
1264 __bit_iterator<_Dp, _IC1>,
1265 __bit_iterator<_Dp, _IC2>);
1266 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
1267 typename _Dp::size_type);
1268 template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
1269 typename _Dp::size_type);
1270 template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
1271 __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1272 template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
1273 __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1276 _LIBCPP_END_NAMESPACE_STD
1280 #endif // _LIBCPP___BIT_REFERENCE