Index: stable/12/contrib/llvm-project/libcxx/include/__bit_reference =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/__bit_reference (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/__bit_reference (revision 356466) @@ -1,1280 +1,1284 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP___BIT_REFERENCE #define _LIBCPP___BIT_REFERENCE #include <__config> #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD template class __bit_iterator; template class __bit_const_reference; template struct __has_storage_type { static const bool value = false; }; template ::value> class __bit_reference { typedef typename _Cp::__storage_type __storage_type; typedef typename _Cp::__storage_pointer __storage_pointer; __storage_pointer __seg_; __storage_type __mask_; friend typename _Cp::__self; friend class __bit_const_reference<_Cp>; friend class __bit_iterator<_Cp, false>; public: _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT {return static_cast(*__seg_ & __mask_);} _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT {return !static_cast(*this);} _LIBCPP_INLINE_VISIBILITY __bit_reference& operator=(bool __x) _NOEXCEPT { if (__x) *__seg_ |= __mask_; else *__seg_ &= ~__mask_; return *this; } _LIBCPP_INLINE_VISIBILITY __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT {return operator=(static_cast(__x));} _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT {return __bit_iterator<_Cp, false>(__seg_, static_cast(__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT : __seg_(__s), __mask_(__m) {} }; template class __bit_reference<_Cp, false> { }; template inline _LIBCPP_INLINE_VISIBILITY void swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT { bool __t = __x; __x = __y; __y = __t; } template inline _LIBCPP_INLINE_VISIBILITY void swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT { bool __t = __x; __x = __y; __y = __t; } template inline _LIBCPP_INLINE_VISIBILITY void swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT { bool __t = __x; __x = __y; __y = __t; } template inline _LIBCPP_INLINE_VISIBILITY void swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT { bool __t = __x; __x = __y; __y = __t; } template class __bit_const_reference { typedef typename _Cp::__storage_type __storage_type; typedef typename _Cp::__const_storage_pointer __storage_pointer; __storage_pointer __seg_; __storage_type __mask_; friend typename _Cp::__self; friend class __bit_iterator<_Cp, true>; public: _LIBCPP_INLINE_VISIBILITY __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT : __seg_(__x.__seg_), __mask_(__x.__mask_) {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT {return static_cast(*__seg_ & __mask_);} _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT {return __bit_iterator<_Cp, true>(__seg_, static_cast(__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT : __seg_(__s), __mask_(__m) {} __bit_const_reference& operator=(const __bit_const_reference& __x); }; // find template __bit_iterator<_Cp, _IsConst> __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; static const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = *__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(__b))); if (__n == __dn) return __first + __n; __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) if (*__first.__seg_) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(*__first.__seg_))); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(__b))); } return _It(__first.__seg_, static_cast(__n)); } template __bit_iterator<_Cp, _IsConst> __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = ~*__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(__b))); if (__n == __dn) return __first + __n; __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) { __storage_type __b = ~*__first.__seg_; if (__b) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(__b))); } // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = ~*__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast(_VSTD::__libcpp_ctz(__b))); } return _It(__first.__seg_, static_cast(__n)); } template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, _IsConst> find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) { if (static_cast(__value_)) return __find_bool_true(__first, static_cast(__last - __first)); return __find_bool_false(__first, static_cast(__last - __first)); } // count template typename __bit_iterator<_Cp, _IsConst>::difference_type __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; typedef typename _It::difference_type difference_type; const int __bits_per_word = _It::__bits_per_word; difference_type __r = 0; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __r = _VSTD::__libcpp_popcount(*__first.__seg_ & __m); __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) __r += _VSTD::__libcpp_popcount(*__first.__seg_); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __r += _VSTD::__libcpp_popcount(*__first.__seg_ & __m); } return __r; } template typename __bit_iterator<_Cp, _IsConst>::difference_type __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; typedef typename _It::difference_type difference_type; const int __bits_per_word = _It::__bits_per_word; difference_type __r = 0; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __r = _VSTD::__libcpp_popcount(~*__first.__seg_ & __m); __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) __r += _VSTD::__libcpp_popcount(~*__first.__seg_); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __r += _VSTD::__libcpp_popcount(~*__first.__seg_ & __m); } return __r; } template inline _LIBCPP_INLINE_VISIBILITY typename __bit_iterator<_Cp, _IsConst>::difference_type count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_) { if (static_cast(__value_)) return __count_bool_true(__first, static_cast(__last - __first)); return __count_bool_false(__first, static_cast(__last - __first)); } // fill_n template void __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; typedef typename _It::__storage_type __storage_type; const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); *__first.__seg_ &= ~__m; __n -= __dn; ++__first.__seg_; } // do middle whole words __storage_type __nw = __n / __bits_per_word; _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last partial word if (__n > 0) { __first.__seg_ += __nw; __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); *__first.__seg_ &= ~__m; } } template void __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; typedef typename _It::__storage_type __storage_type; const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); *__first.__seg_ |= __m; __n -= __dn; ++__first.__seg_; } // do middle whole words __storage_type __nw = __n / __bits_per_word; _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last partial word if (__n > 0) { __first.__seg_ += __nw; __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); *__first.__seg_ |= __m; } } template inline _LIBCPP_INLINE_VISIBILITY void fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_) { if (__n > 0) { if (__value_) __fill_n_true(__first, __n); else __fill_n_false(__first, __n); } } // fill template inline _LIBCPP_INLINE_VISIBILITY void fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_) { _VSTD::fill_n(__first, static_cast(__last - __first), __value_); } // copy template __bit_iterator<_Cp, false> __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__first.__ctz_ != 0) { unsigned __clz = __bits_per_word - __first.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); __storage_type __b = *__first.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b; __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); ++__first.__seg_; // __first.__ctz_ = 0; } // __first.__ctz_ == 0; // do middle words __storage_type __nw = __n / __bits_per_word; _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), _VSTD::__to_raw_pointer(__first.__seg_), __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; __result.__seg_ += __nw; // do last word if (__n > 0) { __first.__seg_ += __nw; __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__first.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b; __result.__ctz_ = static_cast(__n); } } return __result; } template __bit_iterator<_Cp, false> __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; static const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__first.__ctz_ != 0) { unsigned __clz_f = __bits_per_word - __first.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = *__first.__seg_ & __m; unsigned __clz_r = __bits_per_word - __result.__ctz_; __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); *__result.__seg_ &= ~__m; if (__result.__ctz_ > __first.__ctz_) *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_); else *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_); __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); __dn -= __ddn; if (__dn > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __dn); *__result.__seg_ &= ~__m; *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn); __result.__ctz_ = static_cast(__dn); } ++__first.__seg_; // __first.__ctz_ = 0; } // __first.__ctz_ == 0; // do middle words unsigned __clz_r = __bits_per_word - __result.__ctz_; __storage_type __m = ~__storage_type(0) << __result.__ctz_; for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { __storage_type __b = *__first.__seg_; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b << __result.__ctz_; ++__result.__seg_; *__result.__seg_ &= __m; *__result.__seg_ |= __b >> __clz_r; } // do last word if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__first.__seg_ & __m; __storage_type __dn = _VSTD::min(__n, static_cast(__clz_r)); __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); *__result.__seg_ &= ~__m; *__result.__seg_ |= __b << __result.__ctz_; __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); __n -= __dn; if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); *__result.__seg_ &= ~__m; *__result.__seg_ |= __b >> __dn; __result.__ctz_ = static_cast(__n); } } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { if (__first.__ctz_ == __result.__ctz_) return __copy_aligned(__first, __last, __result); return __copy_unaligned(__first, __last, __result); } // copy_backward template __bit_iterator<_Cp, false> __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__last.__ctz_ != 0) { difference_type __dn = _VSTD::min(static_cast(__last.__ctz_), __n); __n -= __dn; unsigned __clz = __bits_per_word - __last.__ctz_; __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz); __storage_type __b = *__last.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b; __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); // __last.__ctz_ = 0 } // __last.__ctz_ == 0 || __n == 0 // __result.__ctz_ == 0 || __n == 0 // do middle words __storage_type __nw = __n / __bits_per_word; __result.__seg_ -= __nw; __last.__seg_ -= __nw; _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), _VSTD::__to_raw_pointer(__last.__seg_), __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last word if (__n > 0) { __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n); __storage_type __b = *--__last.__seg_ & __m; *--__result.__seg_ &= ~__m; *__result.__seg_ |= __b; __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); } } return __result; } template __bit_iterator<_Cp, false> __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__last.__ctz_ != 0) { difference_type __dn = _VSTD::min(static_cast(__last.__ctz_), __n); __n -= __dn; unsigned __clz_l = __bits_per_word - __last.__ctz_; __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l); __storage_type __b = *__last.__seg_ & __m; unsigned __clz_r = __bits_per_word - __result.__ctz_; __storage_type __ddn = _VSTD::min(__dn, static_cast(__result.__ctz_)); if (__ddn > 0) { __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r); *__result.__seg_ &= ~__m; if (__result.__ctz_ > __last.__ctz_) *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); else *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_); __result.__ctz_ = static_cast(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); __dn -= __ddn; } if (__dn > 0) { // __result.__ctz_ == 0 --__result.__seg_; __result.__ctz_ = static_cast(-__dn & (__bits_per_word - 1)); __m = ~__storage_type(0) << __result.__ctz_; *__result.__seg_ &= ~__m; __last.__ctz_ -= __dn + __ddn; *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_); } // __last.__ctz_ = 0 } // __last.__ctz_ == 0 || __n == 0 // __result.__ctz_ != 0 || __n == 0 // do middle words unsigned __clz_r = __bits_per_word - __result.__ctz_; __storage_type __m = ~__storage_type(0) >> __clz_r; for (; __n >= __bits_per_word; __n -= __bits_per_word) { __storage_type __b = *--__last.__seg_; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b >> __clz_r; *--__result.__seg_ &= __m; *__result.__seg_ |= __b << __result.__ctz_; } // do last word if (__n > 0) { __m = ~__storage_type(0) << (__bits_per_word - __n); __storage_type __b = *--__last.__seg_ & __m; __clz_r = __bits_per_word - __result.__ctz_; __storage_type __dn = _VSTD::min(__n, static_cast(__result.__ctz_)); __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r); *__result.__seg_ &= ~__m; *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_); __result.__ctz_ = static_cast(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word); __n -= __dn; if (__n > 0) { // __result.__ctz_ == 0 --__result.__seg_; __result.__ctz_ = static_cast(-__n & (__bits_per_word - 1)); __m = ~__storage_type(0) << __result.__ctz_; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn)); } } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { if (__last.__ctz_ == __result.__ctz_) return __copy_backward_aligned(__first, __last, __result); return __copy_backward_unaligned(__first, __last, __result); } // move template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { return _VSTD::copy(__first, __last, __result); } // move_backward template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) { return _VSTD::copy_backward(__first, __last, __result); } // swap_ranges template __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, __bit_iterator<__C2, false> __result) { typedef __bit_iterator<__C1, false> _I1; typedef typename _I1::difference_type difference_type; typedef typename _I1::__storage_type __storage_type; const int __bits_per_word = _I1::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__first.__ctz_ != 0) { unsigned __clz = __bits_per_word - __first.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); __storage_type __b1 = *__first.__seg_ & __m; *__first.__seg_ &= ~__m; __storage_type __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b1; *__first.__seg_ |= __b2; __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); ++__first.__seg_; // __first.__ctz_ = 0; } // __first.__ctz_ == 0; // do middle words for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_) swap(*__first.__seg_, *__result.__seg_); // do last word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b1 = *__first.__seg_ & __m; *__first.__seg_ &= ~__m; __storage_type __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b1; *__first.__seg_ |= __b2; __result.__ctz_ = static_cast(__n); } } return __result; } template __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last, __bit_iterator<__C2, false> __result) { typedef __bit_iterator<__C1, false> _I1; typedef typename _I1::difference_type difference_type; typedef typename _I1::__storage_type __storage_type; const int __bits_per_word = _I1::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { // do first word if (__first.__ctz_ != 0) { unsigned __clz_f = __bits_per_word - __first.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b1 = *__first.__seg_ & __m; *__first.__seg_ &= ~__m; unsigned __clz_r = __bits_per_word - __result.__ctz_; __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); __storage_type __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; if (__result.__ctz_ > __first.__ctz_) { unsigned __s = __result.__ctz_ - __first.__ctz_; *__result.__seg_ |= __b1 << __s; *__first.__seg_ |= __b2 >> __s; } else { unsigned __s = __first.__ctz_ - __result.__ctz_; *__result.__seg_ |= __b1 >> __s; *__first.__seg_ |= __b2 << __s; } __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__ddn + __result.__ctz_) % __bits_per_word); __dn -= __ddn; if (__dn > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __dn); __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; unsigned __s = __first.__ctz_ + __ddn; *__result.__seg_ |= __b1 >> __s; *__first.__seg_ |= __b2 << __s; __result.__ctz_ = static_cast(__dn); } ++__first.__seg_; // __first.__ctz_ = 0; } // __first.__ctz_ == 0; // do middle words __storage_type __m = ~__storage_type(0) << __result.__ctz_; unsigned __clz_r = __bits_per_word - __result.__ctz_; for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) { __storage_type __b1 = *__first.__seg_; __storage_type __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b1 << __result.__ctz_; *__first.__seg_ = __b2 >> __result.__ctz_; ++__result.__seg_; __b2 = *__result.__seg_ & ~__m; *__result.__seg_ &= __m; *__result.__seg_ |= __b1 >> __clz_r; *__first.__seg_ |= __b2 << __clz_r; } // do last word if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b1 = *__first.__seg_ & __m; *__first.__seg_ &= ~__m; __storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r); __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); __storage_type __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b1 << __result.__ctz_; *__first.__seg_ |= __b2 >> __result.__ctz_; __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word; __result.__ctz_ = static_cast((__dn + __result.__ctz_) % __bits_per_word); __n -= __dn; if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); __b2 = *__result.__seg_ & __m; *__result.__seg_ &= ~__m; *__result.__seg_ |= __b1 >> __dn; *__first.__seg_ |= __b2 << __dn; __result.__ctz_ = static_cast(__n); } } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1, __bit_iterator<__C2, false> __first2) { if (__first1.__ctz_ == __first2.__ctz_) return __swap_ranges_aligned(__first1, __last1, __first2); return __swap_ranges_unaligned(__first1, __last1, __first2); } // rotate template struct __bit_array { typedef typename _Cp::difference_type difference_type; typedef typename _Cp::__storage_type __storage_type; typedef typename _Cp::__storage_pointer __storage_pointer; typedef typename _Cp::iterator iterator; static const unsigned __bits_per_word = _Cp::__bits_per_word; static const unsigned _Np = 4; difference_type __size_; __storage_type __word_[_Np]; _LIBCPP_INLINE_VISIBILITY static difference_type capacity() {return static_cast(_Np * __bits_per_word);} _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} _LIBCPP_INLINE_VISIBILITY iterator begin() { return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); } _LIBCPP_INLINE_VISIBILITY iterator end() { return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, static_cast(__size_ % __bits_per_word)); } }; template __bit_iterator<_Cp, false> rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) { typedef __bit_iterator<_Cp, false> _I1; typedef typename _I1::difference_type difference_type; difference_type __d1 = __middle - __first; difference_type __d2 = __last - __middle; _I1 __r = __first + __d2; while (__d1 != 0 && __d2 != 0) { if (__d1 <= __d2) { if (__d1 <= __bit_array<_Cp>::capacity()) { __bit_array<_Cp> __b(__d1); _VSTD::copy(__first, __middle, __b.begin()); _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first)); break; } else { __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle); __first = __middle; __middle = __mp; __d2 -= __d1; } } else { if (__d2 <= __bit_array<_Cp>::capacity()) { __bit_array<_Cp> __b(__d2); _VSTD::copy(__middle, __last, __b.begin()); _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last)); break; } else { __bit_iterator<_Cp, false> __mp = __first + __d2; _VSTD::swap_ranges(__first, __mp, __middle); __first = __mp; __d1 -= __d2; } } } return __r; } // equal template bool __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { typedef __bit_iterator<_Cp, _IC1> _It; typedef typename _It::difference_type difference_type; typedef typename _It::__storage_type __storage_type; static const int __bits_per_word = _It::__bits_per_word; difference_type __n = __last1 - __first1; if (__n > 0) { // do first word if (__first1.__ctz_ != 0) { unsigned __clz_f = __bits_per_word - __first1.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz_f), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = *__first1.__seg_ & __m; unsigned __clz_r = __bits_per_word - __first2.__ctz_; __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r); __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn)); if (__first2.__ctz_ > __first1.__ctz_) { if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_))) return false; } else { if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_))) return false; } __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word; __first2.__ctz_ = static_cast((__ddn + __first2.__ctz_) % __bits_per_word); __dn -= __ddn; if (__dn > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __dn); if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn))) return false; __first2.__ctz_ = static_cast(__dn); } ++__first1.__seg_; // __first1.__ctz_ = 0; } // __first1.__ctz_ == 0; // do middle words unsigned __clz_r = __bits_per_word - __first2.__ctz_; __storage_type __m = ~__storage_type(0) << __first2.__ctz_; for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) { __storage_type __b = *__first1.__seg_; if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) return false; ++__first2.__seg_; if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r)) return false; } // do last word if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__first1.__seg_ & __m; __storage_type __dn = _VSTD::min(__n, static_cast(__clz_r)); __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn)); if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_)) return false; __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word; __first2.__ctz_ = static_cast((__dn + __first2.__ctz_) % __bits_per_word); __n -= __dn; if (__n > 0) { __m = ~__storage_type(0) >> (__bits_per_word - __n); if ((*__first2.__seg_ & __m) != (__b >> __dn)) return false; } } } return true; } template bool __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { typedef __bit_iterator<_Cp, _IC1> _It; typedef typename _It::difference_type difference_type; typedef typename _It::__storage_type __storage_type; static const int __bits_per_word = _It::__bits_per_word; difference_type __n = __last1 - __first1; if (__n > 0) { // do first word if (__first1.__ctz_ != 0) { unsigned __clz = __bits_per_word - __first1.__ctz_; difference_type __dn = _VSTD::min(static_cast(__clz), __n); __n -= __dn; __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn)); if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) return false; ++__first2.__seg_; ++__first1.__seg_; // __first1.__ctz_ = 0; // __first2.__ctz_ = 0; } // __first1.__ctz_ == 0; // __first2.__ctz_ == 0; // do middle words for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_) if (*__first2.__seg_ != *__first1.__seg_) return false; // do last word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m)) return false; } } return true; } template inline _LIBCPP_INLINE_VISIBILITY bool equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) { if (__first1.__ctz_ == __first2.__ctz_) return __equal_aligned(__first1, __last1, __first2); return __equal_unaligned(__first1, __last1, __first2); } template class __bit_iterator { public: typedef typename _Cp::difference_type difference_type; typedef bool value_type; typedef __bit_iterator pointer; typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference; typedef random_access_iterator_tag iterator_category; private: typedef typename _Cp::__storage_type __storage_type; typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer>::type __storage_pointer; static const unsigned __bits_per_word = _Cp::__bits_per_word; __storage_pointer __seg_; unsigned __ctz_; public: _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __seg_(nullptr), __ctz_(0) #endif {} + // avoid re-declaring a copy constructor for the non-const version. + using __type_for_copy_to_const = + _If<_IsConst, __bit_iterator<_Cp, false>, struct __private_nat>; + _LIBCPP_INLINE_VISIBILITY - __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT + __bit_iterator(const __type_for_copy_to_const& __it) _NOEXCEPT : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT {return reference(__seg_, __storage_type(1) << __ctz_);} _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++() { if (__ctz_ != __bits_per_word-1) ++__ctz_; else { __ctz_ = 0; ++__seg_; } return *this; } _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int) { __bit_iterator __tmp = *this; ++(*this); return __tmp; } _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--() { if (__ctz_ != 0) --__ctz_; else { __ctz_ = __bits_per_word - 1; --__seg_; } return *this; } _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int) { __bit_iterator __tmp = *this; --(*this); return __tmp; } _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n) { if (__n >= 0) __seg_ += (__n + __ctz_) / __bits_per_word; else __seg_ += static_cast(__n - __bits_per_word + __ctz_ + 1) / static_cast(__bits_per_word); __n &= (__bits_per_word - 1); __ctz_ = static_cast((__n + __ctz_) % __bits_per_word); return *this; } _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n) { return *this += -__n; } _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const { __bit_iterator __t(*this); __t += __n; return __t; } _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const { __bit_iterator __t(*this); __t -= __n; return __t; } _LIBCPP_INLINE_VISIBILITY friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;} _LIBCPP_INLINE_VISIBILITY friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y) {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;} _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y) {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;} _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__x == __y);} _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y) {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);} _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y) {return __y < __x;} _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__y < __x);} _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y) {return !(__x < __y);} private: _LIBCPP_INLINE_VISIBILITY __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT : __seg_(__s), __ctz_(__ctz) {} friend typename _Cp::__self; friend class __bit_reference<_Cp>; friend class __bit_const_reference<_Cp>; friend class __bit_iterator<_Cp, true>; template friend struct __bit_array; template friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); template friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); template friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result); template friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>, __bit_iterator<__C1, false>, __bit_iterator<__C2, false>); template friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>, __bit_iterator<__C1, false>, __bit_iterator<__C2, false>); template friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>, __bit_iterator<__C1, false>, __bit_iterator<__C2, false>); template friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>); template friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template friend bool equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template friend typename __bit_iterator<_Dp, _IC>::difference_type __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); template friend typename __bit_iterator<_Dp, _IC>::difference_type __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); }; _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP___BIT_REFERENCE Index: stable/12/contrib/llvm-project/libcxx/include/__hash_table =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/__hash_table (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/__hash_table (revision 356466) @@ -1,2913 +1,2915 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP__HASH_TABLE #define _LIBCPP__HASH_TABLE #include <__config> #include #include #include #include #include #include #include #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD template struct __hash_value_type; #ifndef _LIBCPP_CXX03_LANG template struct __is_hash_value_type_imp : false_type {}; template struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; template struct __is_hash_value_type : false_type {}; template struct __is_hash_value_type<_One> : __is_hash_value_type_imp::type> {}; #endif _LIBCPP_FUNC_VIS size_t __next_prime(size_t __n); template struct __hash_node_base { typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef __hash_node_base __first_node; typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; typedef _NodePtr __node_pointer; #if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) typedef __node_base_pointer __next_pointer; #else typedef typename conditional< is_pointer<__node_pointer>::value, __node_base_pointer, __node_pointer>::type __next_pointer; #endif __next_pointer __next_; _LIBCPP_INLINE_VISIBILITY __next_pointer __ptr() _NOEXCEPT { return static_cast<__next_pointer>( pointer_traits<__node_base_pointer>::pointer_to(*this)); } _LIBCPP_INLINE_VISIBILITY __node_pointer __upcast() _NOEXCEPT { return static_cast<__node_pointer>( pointer_traits<__node_base_pointer>::pointer_to(*this)); } _LIBCPP_INLINE_VISIBILITY size_t __hash() const _NOEXCEPT { return static_cast<__node_type const&>(*this).__hash_; } _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} }; template struct __hash_node : public __hash_node_base < typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type > { typedef _Tp __node_value_type; size_t __hash_; __node_value_type __value_; }; inline _LIBCPP_INLINE_VISIBILITY bool __is_hash_power2(size_t __bc) { return __bc > 2 && !(__bc & (__bc - 1)); } inline _LIBCPP_INLINE_VISIBILITY size_t __constrain_hash(size_t __h, size_t __bc) { return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : (__h < __bc ? __h : __h % __bc); } inline _LIBCPP_INLINE_VISIBILITY size_t __next_hash_pow2(size_t __n) { return __n < 2 ? __n : (size_t(1) << (std::numeric_limits::digits - __libcpp_clz(__n-1))); } template class __hash_table; template class _LIBCPP_TEMPLATE_VIS __hash_iterator; template class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; template class _LIBCPP_TEMPLATE_VIS __hash_local_iterator; template class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; template class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; template class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; template struct __hash_key_value_types { static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); typedef _Tp key_type; typedef _Tp __node_value_type; typedef _Tp __container_value_type; static const bool __is_map = false; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(_Tp const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static __container_value_type&& __move(__node_value_type& __v) { return _VSTD::move(__v); } #endif }; template struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { typedef _Key key_type; typedef _Tp mapped_type; typedef __hash_value_type<_Key, _Tp> __node_value_type; typedef pair __container_value_type; typedef __container_value_type __map_value_type; static const bool __is_map = true; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(__container_value_type const& __v) { return __v.first; } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value, __container_value_type const&>::type __get_value(_Up& __t) { return __t.__get_value(); } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, __container_value_type const&>::type __get_value(_Up& __t) { return __t; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n.__get_value()); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static pair __move(__node_value_type& __v) { return __v.__move(); } #endif }; template , bool = _KVTypes::__is_map> struct __hash_map_pointer_types {}; template struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { typedef typename _KVTypes::__map_value_type _Mv; typedef typename __rebind_pointer<_AllocPtr, _Mv>::type __map_value_type_pointer; typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type __const_map_value_type_pointer; }; template ::element_type> struct __hash_node_types; template struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> { typedef __hash_key_value_types<_Tp> __base; public: typedef ptrdiff_t difference_type; typedef size_t size_type; typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef _NodePtr __node_pointer; typedef __hash_node_base<__node_pointer> __node_base_type; typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type __node_base_pointer; typedef typename __node_base_type::__next_pointer __next_pointer; typedef _Tp __node_value_type; typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type __node_value_type_pointer; typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type __const_node_value_type_pointer; private: static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); static_assert((is_same::element_type, void>::value), "_VoidPtr does not point to unqualified void type"); static_assert((is_same::type, _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); }; template struct __hash_node_types_from_iterator; template struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; template struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; template struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; template struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; template struct __make_hash_node_types { typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; typedef __hash_node_types<_NodePtr> type; }; template class _LIBCPP_TEMPLATE_VIS __hash_iterator { typedef __hash_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; typedef typename _NodeTypes::__next_pointer __next_pointer; __next_pointer __node_; public: typedef forward_iterator_tag iterator_category; typedef typename _NodeTypes::__node_value_type value_type; typedef typename _NodeTypes::difference_type difference_type; typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) { _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_iterator(const __hash_iterator& __i) : __node_(__i.__node_) { __get_db()->__iterator_copy(this, &__i); } _LIBCPP_INLINE_VISIBILITY ~__hash_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __hash_iterator& operator=(const __hash_iterator& __i) { if (this != &__i) { __get_db()->__iterator_copy(this, &__i); __node_ = __i.__node_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container iterator"); return __node_->__upcast()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container iterator"); return pointer_traits::pointer_to(__node_->__upcast()->__value_); } _LIBCPP_INLINE_VISIBILITY __hash_iterator& operator++() { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container iterator"); __node_ = __node_->__next_; return *this; } _LIBCPP_INLINE_VISIBILITY __hash_iterator operator++(int) { __hash_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) { return __x.__node_ == __y.__node_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) {return !(__x == __y);} private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY __hash_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif template friend class __hash_table; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; template friend class _LIBCPP_TEMPLATE_VIS unordered_map; template friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template class _LIBCPP_TEMPLATE_VIS __hash_const_iterator { static_assert(!is_const::element_type>::value, ""); typedef __hash_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; typedef typename _NodeTypes::__next_pointer __next_pointer; __next_pointer __node_; public: typedef __hash_iterator<_NodePtr> __non_const_iterator; typedef forward_iterator_tag iterator_category; typedef typename _NodeTypes::__node_value_type value_type; typedef typename _NodeTypes::difference_type difference_type; typedef const value_type& reference; typedef typename _NodeTypes::__const_node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) { _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_) { _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(const __hash_const_iterator& __i) : __node_(__i.__node_) { __get_db()->__iterator_copy(this, &__i); } _LIBCPP_INLINE_VISIBILITY ~__hash_const_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator& operator=(const __hash_const_iterator& __i) { if (this != &__i) { __get_db()->__iterator_copy(this, &__i); __node_ = __i.__node_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_iterator"); return __node_->__upcast()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_iterator"); return pointer_traits::pointer_to(__node_->__upcast()->__value_); } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator& operator++() { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container const_iterator"); __node_ = __node_->__next_; return *this; } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator operator++(int) { __hash_const_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) { return __x.__node_ == __y.__node_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) {return !(__x == __y);} private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif template friend class __hash_table; template friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS unordered_map; template friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template class _LIBCPP_TEMPLATE_VIS __hash_local_iterator { typedef __hash_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; typedef typename _NodeTypes::__next_pointer __next_pointer; __next_pointer __node_; size_t __bucket_; size_t __bucket_count_; public: typedef forward_iterator_tag iterator_category; typedef typename _NodeTypes::__node_value_type value_type; typedef typename _NodeTypes::difference_type difference_type; typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) { _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator(const __hash_local_iterator& __i) : __node_(__i.__node_), __bucket_(__i.__bucket_), __bucket_count_(__i.__bucket_count_) { __get_db()->__iterator_copy(this, &__i); } _LIBCPP_INLINE_VISIBILITY ~__hash_local_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __hash_local_iterator& operator=(const __hash_local_iterator& __i) { if (this != &__i) { __get_db()->__iterator_copy(this, &__i); __node_ = __i.__node_; __bucket_ = __i.__bucket_; __bucket_count_ = __i.__bucket_count_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container local_iterator"); return __node_->__upcast()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container local_iterator"); return pointer_traits::pointer_to(__node_->__upcast()->__value_); } _LIBCPP_INLINE_VISIBILITY __hash_local_iterator& operator++() { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container local_iterator"); __node_ = __node_->__next_; if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } _LIBCPP_INLINE_VISIBILITY __hash_local_iterator operator++(int) { __hash_local_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) { return __x.__node_ == __y.__node_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) {return !(__x == __y);} private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) { __get_db()->__insert_ic(this, __c); if (__node_ != nullptr) __node_ = __node_->__next_; } #else _LIBCPP_INLINE_VISIBILITY __hash_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) { if (__node_ != nullptr) __node_ = __node_->__next_; } #endif template friend class __hash_table; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; template friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; }; template class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator { typedef __hash_node_types<_ConstNodePtr> _NodeTypes; typedef _ConstNodePtr __node_pointer; typedef typename _NodeTypes::__next_pointer __next_pointer; __next_pointer __node_; size_t __bucket_; size_t __bucket_count_; typedef pointer_traits<__node_pointer> __pointer_traits; typedef typename __pointer_traits::element_type __node; typedef typename remove_const<__node>::type __non_const_node; typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type __non_const_node_pointer; public: typedef __hash_local_iterator<__non_const_node_pointer> __non_const_iterator; typedef forward_iterator_tag iterator_category; typedef typename _NodeTypes::__node_value_type value_type; typedef typename _NodeTypes::difference_type difference_type; typedef const value_type& reference; typedef typename _NodeTypes::__const_node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) { _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_), __bucket_(__x.__bucket_), __bucket_count_(__x.__bucket_count_) { _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(const __hash_const_local_iterator& __i) : __node_(__i.__node_), __bucket_(__i.__bucket_), __bucket_count_(__i.__bucket_count_) { __get_db()->__iterator_copy(this, &__i); } _LIBCPP_INLINE_VISIBILITY ~__hash_const_local_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) { if (this != &__i) { __get_db()->__iterator_copy(this, &__i); __node_ = __i.__node_; __bucket_ = __i.__bucket_; __bucket_count_ = __i.__bucket_count_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); return __node_->__upcast()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); return pointer_traits::pointer_to(__node_->__upcast()->__value_); } _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator& operator++() { _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container const_local_iterator"); __node_ = __node_->__next_; if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator operator++(int) { __hash_const_local_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) { return __x.__node_ == __y.__node_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) {return !(__x == __y);} private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) { __get_db()->__insert_ic(this, __c); if (__node_ != nullptr) __node_ = __node_->__next_; } #else _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) { if (__node_ != nullptr) __node_ = __node_->__next_; } #endif template friend class __hash_table; template friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; }; template class __bucket_list_deallocator { typedef _Alloc allocator_type; typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; __compressed_pair __data_; public: typedef typename __alloc_traits::pointer pointer; _LIBCPP_INLINE_VISIBILITY __bucket_list_deallocator() _NOEXCEPT_(is_nothrow_default_constructible::value) : __data_(0) {} _LIBCPP_INLINE_VISIBILITY __bucket_list_deallocator(const allocator_type& __a, size_type __size) _NOEXCEPT_(is_nothrow_copy_constructible::value) : __data_(__size, __a) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __bucket_list_deallocator(__bucket_list_deallocator&& __x) _NOEXCEPT_(is_nothrow_move_constructible::value) : __data_(_VSTD::move(__x.__data_)) { __x.size() = 0; } #endif _LIBCPP_INLINE_VISIBILITY size_type& size() _NOEXCEPT {return __data_.first();} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __data_.first();} _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() _NOEXCEPT {return __data_.second();} _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();} _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); } }; template class __hash_map_node_destructor; template class __hash_node_destructor { typedef _Alloc allocator_type; typedef allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; private: typedef __hash_node_types _NodeTypes; allocator_type& __na_; - __hash_node_destructor& operator=(const __hash_node_destructor&); - public: bool __value_constructed; + + __hash_node_destructor(__hash_node_destructor const&) = default; + __hash_node_destructor& operator=(const __hash_node_destructor&) = delete; + _LIBCPP_INLINE_VISIBILITY explicit __hash_node_destructor(allocator_type& __na, bool __constructed = false) _NOEXCEPT : __na_(__na), __value_constructed(__constructed) {} _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT { if (__value_constructed) __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } template friend class __hash_map_node_destructor; }; #if _LIBCPP_STD_VER > 14 template struct __generic_container_node_destructor; template struct __generic_container_node_destructor<__hash_node<_Tp, _VoidPtr>, _Alloc> : __hash_node_destructor<_Alloc> { using __hash_node_destructor<_Alloc>::__hash_node_destructor; }; #endif template struct __enforce_unordered_container_requirements { #ifndef _LIBCPP_CXX03_LANG static_assert(__check_hash_requirements<_Key, _Hash>::value, "the specified hash does not meet the Hash requirements"); static_assert(is_copy_constructible<_Equal>::value, "the specified comparator is required to be copy constructible"); #endif typedef int type; }; template #ifndef _LIBCPP_CXX03_LANG _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, "the specified comparator type does not provide a viable const call operator") _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, "the specified hash functor does not provide a viable const call operator") #endif typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type __diagnose_unordered_container_requirements(int); // This dummy overload is used so that the compiler won't emit a spurious // "no matching function for call to __diagnose_unordered_xxx" diagnostic // when the overload above causes a hard error. template int __diagnose_unordered_container_requirements(void*); template class __hash_table { public: typedef _Tp value_type; typedef _Hash hasher; typedef _Equal key_equal; typedef _Alloc allocator_type; private: typedef allocator_traits __alloc_traits; typedef typename __make_hash_node_types::type _NodeTypes; public: typedef typename _NodeTypes::__node_value_type __node_value_type; typedef typename _NodeTypes::__container_value_type __container_value_type; typedef typename _NodeTypes::key_type key_type; typedef value_type& reference; typedef const value_type& const_reference; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; #ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE typedef typename __alloc_traits::size_type size_type; #else typedef typename _NodeTypes::size_type size_type; #endif typedef typename _NodeTypes::difference_type difference_type; public: // Create __node typedef typename _NodeTypes::__node_type __node; typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename _NodeTypes::__void_pointer __void_pointer; typedef typename _NodeTypes::__node_pointer __node_pointer; typedef typename _NodeTypes::__node_pointer __node_const_pointer; typedef typename _NodeTypes::__node_base_type __first_node; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__next_pointer __next_pointer; private: // check for sane allocator pointer rebinding semantics. Rebinding the // allocator for a new pointer type should be exactly the same as rebinding // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); private: typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; // --- Member data begin --- __bucket_list __bucket_list_; __compressed_pair<__first_node, __node_allocator> __p1_; __compressed_pair __p2_; __compressed_pair __p3_; // --- Member data end --- _LIBCPP_INLINE_VISIBILITY size_type& size() _NOEXCEPT {return __p2_.first();} public: _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __p2_.first();} _LIBCPP_INLINE_VISIBILITY hasher& hash_function() _NOEXCEPT {return __p2_.second();} _LIBCPP_INLINE_VISIBILITY const hasher& hash_function() const _NOEXCEPT {return __p2_.second();} _LIBCPP_INLINE_VISIBILITY float& max_load_factor() _NOEXCEPT {return __p3_.first();} _LIBCPP_INLINE_VISIBILITY float max_load_factor() const _NOEXCEPT {return __p3_.first();} _LIBCPP_INLINE_VISIBILITY key_equal& key_eq() _NOEXCEPT {return __p3_.second();} _LIBCPP_INLINE_VISIBILITY const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();} _LIBCPP_INLINE_VISIBILITY __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();} _LIBCPP_INLINE_VISIBILITY const __node_allocator& __node_alloc() const _NOEXCEPT {return __p1_.second();} public: typedef __hash_iterator<__node_pointer> iterator; typedef __hash_const_iterator<__node_pointer> const_iterator; typedef __hash_local_iterator<__node_pointer> local_iterator; typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; _LIBCPP_INLINE_VISIBILITY __hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value && is_nothrow_default_constructible<__first_node>::value && is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_default_constructible::value && is_nothrow_default_constructible::value); _LIBCPP_INLINE_VISIBILITY __hash_table(const hasher& __hf, const key_equal& __eql); __hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a); explicit __hash_table(const allocator_type& __a); __hash_table(const __hash_table& __u); __hash_table(const __hash_table& __u, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG __hash_table(__hash_table&& __u) _NOEXCEPT_( is_nothrow_move_constructible<__bucket_list>::value && is_nothrow_move_constructible<__first_node>::value && is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value && is_nothrow_move_constructible::value); __hash_table(__hash_table&& __u, const allocator_type& __a); #endif // _LIBCPP_CXX03_LANG ~__hash_table(); __hash_table& operator=(const __hash_table& __u); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_table& operator=(__hash_table&& __u) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value); #endif template void __assign_unique(_InputIterator __first, _InputIterator __last); template void __assign_multi(_InputIterator __first, _InputIterator __last); _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { return std::min( __node_traits::max_size(__node_alloc()), numeric_limits::max() ); } private: _LIBCPP_INLINE_VISIBILITY __next_pointer __node_insert_multi_prepare(size_t __cp_hash, value_type& __cp_val); _LIBCPP_INLINE_VISIBILITY void __node_insert_multi_perform(__node_pointer __cp, __next_pointer __pn) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY __next_pointer __node_insert_unique_prepare(size_t __nd_hash, value_type& __nd_val); _LIBCPP_INLINE_VISIBILITY void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT; public: _LIBCPP_INLINE_VISIBILITY pair __node_insert_unique(__node_pointer __nd); _LIBCPP_INLINE_VISIBILITY iterator __node_insert_multi(__node_pointer __nd); _LIBCPP_INLINE_VISIBILITY iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_key_args(_Key const& __k, _Args&&... __args); template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_impl(_Args&&... __args); template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Pp&& __x) { return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); } template _LIBCPP_INLINE_VISIBILITY typename enable_if< __can_extract_map_key<_First, key_type, __container_value_type>::value, pair >::type __emplace_unique(_First&& __f, _Second&& __s) { return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), _VSTD::forward<_Second>(__s)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Args&&... __args) { return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_multi(_Args&&... __args); template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); _LIBCPP_INLINE_VISIBILITY pair __insert_unique(__container_value_type&& __x) { return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x)); } template ::value >::type> _LIBCPP_INLINE_VISIBILITY pair __insert_unique(_Pp&& __x) { return __emplace_unique(_VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(_Pp&& __x) { return __emplace_multi(_VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, _Pp&& __x) { return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x)); } #else // !defined(_LIBCPP_CXX03_LANG) template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_key_args(_Key const&, _Args& __args); iterator __insert_multi(const __container_value_type& __x); iterator __insert_multi(const_iterator __p, const __container_value_type& __x); #endif _LIBCPP_INLINE_VISIBILITY pair __insert_unique(const __container_value_type& __x) { return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); } #if _LIBCPP_STD_VER > 14 template _LIBCPP_INLINE_VISIBILITY _InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_unique(const_iterator __hint, _NodeHandle&& __nh); template _LIBCPP_INLINE_VISIBILITY void __node_handle_merge_unique(_Table& __source); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_multi(_NodeHandle&& __nh); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh); template _LIBCPP_INLINE_VISIBILITY void __node_handle_merge_multi(_Table& __source); template _LIBCPP_INLINE_VISIBILITY _NodeHandle __node_handle_extract(key_type const& __key); template _LIBCPP_INLINE_VISIBILITY _NodeHandle __node_handle_extract(const_iterator __it); #endif void clear() _NOEXCEPT; void rehash(size_type __n); _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) {rehash(static_cast(ceil(__n / max_load_factor())));} _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const _NOEXCEPT { return __bucket_list_.get_deleter().size(); } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; template _LIBCPP_INLINE_VISIBILITY size_type bucket(const _Key& __k) const { _LIBCPP_ASSERT(bucket_count() > 0, "unordered container::bucket(key) called when bucket_count() == 0"); return __constrain_hash(hash_function()(__k), bucket_count()); } template iterator find(const _Key& __x); template const_iterator find(const _Key& __x) const; typedef __hash_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; iterator erase(const_iterator __p); iterator erase(const_iterator __first, const_iterator __last); template size_type __erase_unique(const _Key& __k); template size_type __erase_multi(const _Key& __k); __node_holder remove(const_iterator __p) _NOEXCEPT; template _LIBCPP_INLINE_VISIBILITY size_type __count_unique(const _Key& __k) const; template size_type __count_multi(const _Key& __k) const; template pair __equal_range_unique(const _Key& __k); template pair __equal_range_unique(const _Key& __k) const; template pair __equal_range_multi(const _Key& __k); template pair __equal_range_multi(const _Key& __k) const; void swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && __is_nothrow_swappable::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ); #else _NOEXCEPT_(__is_nothrow_swappable::value && __is_nothrow_swappable::value); #endif _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const _NOEXCEPT {return max_size(); } size_type bucket_size(size_type __n) const; _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT { size_type __bc = bucket_count(); return __bc != 0 ? (float)size() / __bc : 0.f; } _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT { _LIBCPP_ASSERT(__mlf > 0, "unordered container::max_load_factor(lf) called with lf <= 0"); max_load_factor() = _VSTD::max(__mlf, load_factor()); } _LIBCPP_INLINE_VISIBILITY local_iterator begin(size_type __n) { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::begin(n) called with n >= bucket_count()"); #if _LIBCPP_DEBUG_LEVEL >= 2 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); #else return local_iterator(__bucket_list_[__n], __n, bucket_count()); #endif } _LIBCPP_INLINE_VISIBILITY local_iterator end(size_type __n) { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::end(n) called with n >= bucket_count()"); #if _LIBCPP_DEBUG_LEVEL >= 2 return local_iterator(nullptr, __n, bucket_count(), this); #else return local_iterator(nullptr, __n, bucket_count()); #endif } _LIBCPP_INLINE_VISIBILITY const_local_iterator cbegin(size_type __n) const { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::cbegin(n) called with n >= bucket_count()"); #if _LIBCPP_DEBUG_LEVEL >= 2 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); #else return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); #endif } _LIBCPP_INLINE_VISIBILITY const_local_iterator cend(size_type __n) const { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::cend(n) called with n >= bucket_count()"); #if _LIBCPP_DEBUG_LEVEL >= 2 return const_local_iterator(nullptr, __n, bucket_count(), this); #else return const_local_iterator(nullptr, __n, bucket_count()); #endif } #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; bool __decrementable(const const_iterator* __i) const; bool __addable(const const_iterator* __i, ptrdiff_t __n) const; bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; #endif // _LIBCPP_DEBUG_LEVEL >= 2 private: void __rehash(size_type __n); #ifndef _LIBCPP_CXX03_LANG template __node_holder __construct_node(_Args&& ...__args); template __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); #else // _LIBCPP_CXX03_LANG __node_holder __construct_node(const __container_value_type& __v); __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v); #endif _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __hash_table& __u) {__copy_assign_alloc(__u, integral_constant());} void __copy_assign_alloc(const __hash_table& __u, true_type); _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __hash_table&, false_type) {} #ifndef _LIBCPP_CXX03_LANG void __move_assign(__hash_table& __u, false_type); void __move_assign(__hash_table& __u, true_type) _NOEXCEPT_( is_nothrow_move_assignable<__node_allocator>::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value); _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__hash_table& __u) _NOEXCEPT_( !__node_traits::propagate_on_container_move_assignment::value || (is_nothrow_move_assignable<__pointer_allocator>::value && is_nothrow_move_assignable<__node_allocator>::value)) {__move_assign_alloc(__u, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__hash_table& __u, true_type) _NOEXCEPT_( is_nothrow_move_assignable<__pointer_allocator>::value && is_nothrow_move_assignable<__node_allocator>::value) { __bucket_list_.get_deleter().__alloc() = _VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); __node_alloc() = _VSTD::move(__u.__node_alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} #endif // _LIBCPP_CXX03_LANG void __deallocate_node(__next_pointer __np) _NOEXCEPT; __next_pointer __detach() _NOEXCEPT; template friend class _LIBCPP_TEMPLATE_VIS unordered_map; template friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value && is_nothrow_default_constructible<__first_node>::value && is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_default_constructible::value && is_nothrow_default_constructible::value) : __p2_(0), __p3_(1.0f) { } template inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) { } template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, __hf), __p3_(1.0f, __eql) { } template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), __p1_(__second_tag(), __node_allocator(__a)), __p2_(0), __p3_(1.0f) { } template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) : __bucket_list_(nullptr, __bucket_list_deleter(allocator_traits<__pointer_allocator>:: select_on_container_copy_construction( __u.__bucket_list_.get_deleter().__alloc()), 0)), __p1_(__second_tag(), allocator_traits<__node_allocator>:: select_on_container_copy_construction(__u.__node_alloc())), __p2_(0, __u.hash_function()), __p3_(__u.__p3_) { } template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, __u.hash_function()), __p3_(__u.__p3_) { } #ifndef _LIBCPP_CXX03_LANG template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEXCEPT_( is_nothrow_move_constructible<__bucket_list>::value && is_nothrow_move_constructible<__first_node>::value && is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value && is_nothrow_move_constructible::value) : __bucket_list_(_VSTD::move(__u.__bucket_list_)), __p1_(_VSTD::move(__u.__p1_)), __p2_(_VSTD::move(__u.__p2_)), __p3_(_VSTD::move(__u.__p3_)) { if (size() > 0) { __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } } template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, _VSTD::move(__u.hash_function())), __p3_(_VSTD::move(__u.__p3_)) { if (__a == allocator_type(__u.__node_alloc())) { __bucket_list_.reset(__u.__bucket_list_.release()); __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); __u.__bucket_list_.get_deleter().size() = 0; if (__u.size() > 0) { __p1_.first().__next_ = __u.__p1_.first().__next_; __u.__p1_.first().__next_ = nullptr; __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); size() = __u.size(); __u.size() = 0; } } } #endif // _LIBCPP_CXX03_LANG template __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { #if defined(_LIBCPP_CXX03_LANG) static_assert((is_copy_constructible::value), "Predicate must be copy-constructible."); static_assert((is_copy_constructible::value), "Hasher must be copy-constructible."); #endif __deallocate_node(__p1_.first().__next_); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__erase_c(this); #endif } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( const __hash_table& __u, true_type) { if (__node_alloc() != __u.__node_alloc()) { clear(); __bucket_list_.reset(); __bucket_list_.get_deleter().size() = 0; } __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); __node_alloc() = __u.__node_alloc(); } template __hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) { if (this != &__u) { __copy_assign_alloc(__u); hash_function() = __u.hash_function(); key_eq() = __u.key_eq(); max_load_factor() = __u.max_load_factor(); __assign_multi(__u.begin(), __u.end()); } return *this; } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) _NOEXCEPT { __node_allocator& __na = __node_alloc(); while (__np != nullptr) { __next_pointer __next = __np->__next_; #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __p = __c->end_; __p != __c->beg_; ) { --__p; iterator* __i = static_cast((*__p)->__i_); if (__i->__node_ == __np) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif __node_pointer __real_np = __np->__upcast(); __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); __node_traits::deallocate(__na, __real_np, 1); __np = __next; } } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; size() = 0; __next_pointer __cache = __p1_.first().__next_; __p1_.first().__next_ = nullptr; return __cache; } #ifndef _LIBCPP_CXX03_LANG template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( __hash_table& __u, true_type) _NOEXCEPT_( is_nothrow_move_assignable<__node_allocator>::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value) { clear(); __bucket_list_.reset(__u.__bucket_list_.release()); __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); __u.__bucket_list_.get_deleter().size() = 0; __move_assign_alloc(__u); size() = __u.size(); hash_function() = _VSTD::move(__u.hash_function()); max_load_factor() = __u.max_load_factor(); key_eq() = _VSTD::move(__u.key_eq()); __p1_.first().__next_ = __u.__p1_.first().__next_; if (size() > 0) { __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__u); #endif } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( __hash_table& __u, false_type) { if (__node_alloc() == __u.__node_alloc()) __move_assign(__u, true_type()); else { hash_function() = _VSTD::move(__u.hash_function()); key_eq() = _VSTD::move(__u.key_eq()); max_load_factor() = __u.max_load_factor(); if (bucket_count() != 0) { __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS const_iterator __i = __u.begin(); while (__cache != nullptr && __u.size() != 0) { __cache->__upcast()->__value_ = _VSTD::move(__u.remove(__i++)->__value_); __next_pointer __next = __cache->__next_; __node_insert_multi(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS __deallocate_node(__cache); } const_iterator __i = __u.begin(); while (__u.size() != 0) { __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); __node_insert_multi(__h.get()); __h.release(); } } } template inline __hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value) { __move_assign(__u, integral_constant()); return *this; } #endif // _LIBCPP_CXX03_LANG template template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, _InputIterator __last) { typedef iterator_traits<_InputIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value), "__assign_unique may only be called with the containers value type"); if (bucket_count() != 0) { __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__upcast()->__value_ = *__first; __next_pointer __next = __cache->__next_; __node_insert_unique(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS __deallocate_node(__cache); } for (; __first != __last; ++__first) __insert_unique(*__first); } template template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, _InputIterator __last) { typedef iterator_traits<_InputIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value), "__assign_multi may only be called with the containers value type" " or the nodes value type"); if (bucket_count() != 0) { __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__upcast()->__value_ = *__first; __next_pointer __next = __cache->__next_; __node_insert_multi(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS __deallocate_node(__cache); } for (; __first != __last; ++__first) __insert_multi(_NodeTypes::__get_value(*__first)); } template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__p1_.first().__next_, this); #else return iterator(__p1_.first().__next_); #endif } template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(nullptr, this); #else return iterator(nullptr); #endif } template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(__p1_.first().__next_, this); #else return const_iterator(__p1_.first().__next_); #endif } template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(nullptr, this); #else return const_iterator(nullptr); #endif } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { if (size() > 0) { __deallocate_node(__p1_.first().__next_); __p1_.first().__next_ = nullptr; size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; size() = 0; } } // Prepare the container for an insertion of the value __value with the hash // __hash. This does a lookup into the container to see if __value is already // present, and performs a rehash if necessary. Returns a pointer to the // existing element if it exists, otherwise nullptr. // // Note that this function does forward exceptions if key_eq() throws, and never // mutates __value or actually inserts into the map. template _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare( size_t __hash, value_type& __value) { size_type __bc = bucket_count(); if (__bc != 0) { size_t __chash = __constrain_hash(__hash, __bc); __next_pointer __ndptr = __bucket_list_[__chash]; if (__ndptr != nullptr) { for (__ndptr = __ndptr->__next_; __ndptr != nullptr && __constrain_hash(__ndptr->__hash(), __bc) == __chash; __ndptr = __ndptr->__next_) { if (key_eq()(__ndptr->__upcast()->__value_, __value)) return __ndptr; } } } if (size()+1 > __bc * max_load_factor() || __bc == 0) { rehash(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), size_type(ceil(float(size() + 1) / max_load_factor())))); } return nullptr; } // Insert the node __nd into the container by pushing it into the right bucket, // and updating size(). Assumes that __nd->__hash is up-to-date, and that // rehashing has already occurred and that no element with the same key exists // in the map. template _LIBCPP_INLINE_VISIBILITY void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform( __node_pointer __nd) _NOEXCEPT { size_type __bc = bucket_count(); size_t __chash = __constrain_hash(__nd->__hash(), __bc); // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { __pn =__p1_.first().__ptr(); __nd->__next_ = __pn->__next_; __pn->__next_ = __nd->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__nd->__next_ != nullptr) __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); } else { __nd->__next_ = __pn->__next_; __pn->__next_ = __nd->__ptr(); } ++size(); } template pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) { __nd->__hash_ = hash_function()(__nd->__value_); __next_pointer __existing_node = __node_insert_unique_prepare(__nd->__hash(), __nd->__value_); // Insert the node, unless it already exists in the container. bool __inserted = false; if (__existing_node == nullptr) { __node_insert_unique_perform(__nd); __existing_node = __nd->__ptr(); __inserted = true; } #if _LIBCPP_DEBUG_LEVEL >= 2 return pair(iterator(__existing_node, this), __inserted); #else return pair(iterator(__existing_node), __inserted); #endif } // Prepare the container for an insertion of the value __cp_val with the hash // __cp_hash. This does a lookup into the container to see if __cp_value is // already present, and performs a rehash if necessary. Returns a pointer to the // last occurance of __cp_val in the map. // // Note that this function does forward exceptions if key_eq() throws, and never // mutates __value or actually inserts into the map. template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare( size_t __cp_hash, value_type& __cp_val) { size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) { rehash(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), size_type(ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } size_t __chash = __constrain_hash(__cp_hash, __bc); __next_pointer __pn = __bucket_list_[__chash]; if (__pn != nullptr) { for (bool __found = false; __pn->__next_ != nullptr && __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; __pn = __pn->__next_) { // __found key_eq() action // false false loop // true true loop // false true set __found to true // true false break if (__found != (__pn->__next_->__hash() == __cp_hash && key_eq()(__pn->__next_->__upcast()->__value_, __cp_val))) { if (!__found) __found = true; else break; } } } return __pn; } // Insert the node __cp into the container after __pn (which is the last node in // the bucket that compares equal to __cp). Rehashing, and checking for // uniqueness has already been performed (in __node_insert_multi_prepare), so // all we need to do is update the bucket and size(). Assumes that __cp->__hash // is up-to-date. template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( __node_pointer __cp, __next_pointer __pn) _NOEXCEPT { size_type __bc = bucket_count(); size_t __chash = __constrain_hash(__cp->__hash_, __bc); if (__pn == nullptr) { __pn =__p1_.first().__ptr(); __cp->__next_ = __pn->__next_; __pn->__next_ = __cp->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__cp->__next_ != nullptr) __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] = __cp->__ptr(); } else { __cp->__next_ = __pn->__next_; __pn->__next_ = __cp->__ptr(); if (__cp->__next_ != nullptr) { size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); if (__nhash != __chash) __bucket_list_[__nhash] = __cp->__ptr(); } } ++size(); } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) { __cp->__hash_ = hash_function()(__cp->__value_); __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_); __node_insert_multi_perform(__cp, __pn); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__cp->__ptr(), this); #else return iterator(__cp->__ptr()); #endif } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( const_iterator __p, __node_pointer __cp) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" " referring to this unordered container"); #endif if (__p != end() && key_eq()(*__p, __cp->__value_)) { __next_pointer __np = __p.__node_; __cp->__hash_ = __np->__hash(); size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) { rehash(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), size_type(ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } size_t __chash = __constrain_hash(__cp->__hash_, __bc); __next_pointer __pp = __bucket_list_[__chash]; while (__pp->__next_ != __np) __pp = __pp->__next_; __cp->__next_ = __np; __pp->__next_ = static_cast<__next_pointer>(__cp); ++size(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(static_cast<__next_pointer>(__cp), this); #else return iterator(static_cast<__next_pointer>(__cp)); #endif } return __node_insert_multi(__cp); } #ifndef _LIBCPP_CXX03_LANG template template pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) #else template template pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) #endif { size_t __hash = hash_function()(__k); size_type __bc = bucket_count(); bool __inserted = false; __next_pointer __nd; size_t __chash; if (__bc != 0) { __chash = __constrain_hash(__hash, __bc); __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if (key_eq()(__nd->__upcast()->__value_, __k)) goto __done; } } } { #ifndef _LIBCPP_CXX03_LANG __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...); #else __node_holder __h = __construct_node_hash(__hash, __args); #endif if (size()+1 > __bc * max_load_factor() || __bc == 0) { rehash(_VSTD::max(2 * __bc + !__is_hash_power2(__bc), size_type(ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); __chash = __constrain_hash(__hash, __bc); } // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { __pn = __p1_.first().__ptr(); __h->__next_ = __pn->__next_; __pn->__next_ = __h.get()->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__h->__next_ != nullptr) __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] = __h.get()->__ptr(); } else { __h->__next_ = __pn->__next_; __pn->__next_ = static_cast<__next_pointer>(__h.get()); } __nd = static_cast<__next_pointer>(__h.release()); // increment size ++size(); __inserted = true; } __done: #if _LIBCPP_DEBUG_LEVEL >= 2 return pair(iterator(__nd, this), __inserted); #else return pair(iterator(__nd), __inserted); #endif } #ifndef _LIBCPP_CXX03_LANG template template pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); pair __r = __node_insert_unique(__h.get()); if (__r.second) __h.release(); return __r; } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __node_insert_multi(__h.get()); __h.release(); return __r; } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( const_iterator __p, _Args&&... __args) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" " referring to this unordered container"); #endif __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __node_insert_multi(__p, __h.get()); __h.release(); return __r; } #else // _LIBCPP_CXX03_LANG template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x) { __node_holder __h = __construct_node(__x); iterator __r = __node_insert_multi(__h.get()); __h.release(); return __r; } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, const __container_value_type& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered container::insert(const_iterator, lvalue) called with an iterator not" " referring to this unordered container"); #endif __node_holder __h = __construct_node(__x); iterator __r = __node_insert_multi(__p, __h.get()); __h.release(); return __r; } #endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 template template _LIBCPP_INLINE_VISIBILITY _InsertReturnType __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( _NodeHandle&& __nh) { if (__nh.empty()) return _InsertReturnType{end(), false, _NodeHandle()}; pair __result = __node_insert_unique(__nh.__ptr_); if (__result.second) __nh.__release_ptr(); return _InsertReturnType{__result.first, __result.second, _VSTD::move(__nh)}; } template template _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( const_iterator, _NodeHandle&& __nh) { if (__nh.empty()) return end(); pair __result = __node_insert_unique(__nh.__ptr_); if (__result.second) __nh.__release_ptr(); return __result.first; } template template _LIBCPP_INLINE_VISIBILITY _NodeHandle __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( key_type const& __key) { iterator __i = find(__key); if (__i == end()) return _NodeHandle(); return __node_handle_extract<_NodeHandle>(__i); } template template _LIBCPP_INLINE_VISIBILITY _NodeHandle __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract( const_iterator __p) { allocator_type __alloc(__node_alloc()); return _NodeHandle(remove(__p).release(), __alloc); } template template _LIBCPP_INLINE_VISIBILITY void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique( _Table& __source) { static_assert(is_same<__node, typename _Table::__node>::value, ""); for (typename _Table::iterator __it = __source.begin(); __it != __source.end();) { __node_pointer __src_ptr = __it.__node_->__upcast(); size_t __hash = hash_function()(__src_ptr->__value_); __next_pointer __existing_node = __node_insert_unique_prepare(__hash, __src_ptr->__value_); auto __prev_iter = __it++; if (__existing_node == nullptr) { (void)__source.remove(__prev_iter).release(); __src_ptr->__hash_ = __hash; __node_insert_unique_perform(__src_ptr); } } } template template _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( _NodeHandle&& __nh) { if (__nh.empty()) return end(); iterator __result = __node_insert_multi(__nh.__ptr_); __nh.__release_ptr(); return __result; } template template _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( const_iterator __hint, _NodeHandle&& __nh) { if (__nh.empty()) return end(); iterator __result = __node_insert_multi(__hint, __nh.__ptr_); __nh.__release_ptr(); return __result; } template template _LIBCPP_INLINE_VISIBILITY void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi( _Table& __source) { static_assert(is_same::value, ""); for (typename _Table::iterator __it = __source.begin(); __it != __source.end();) { __node_pointer __src_ptr = __it.__node_->__upcast(); size_t __src_hash = hash_function()(__src_ptr->__value_); __next_pointer __pn = __node_insert_multi_prepare(__src_hash, __src_ptr->__value_); (void)__source.remove(__it++).release(); __src_ptr->__hash_ = __src_hash; __node_insert_multi_perform(__src_ptr, __pn); } } #endif // _LIBCPP_STD_VER > 14 template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { if (__n == 1) __n = 2; else if (__n & (__n - 1)) __n = __next_prime(__n); size_type __bc = bucket_count(); if (__n > __bc) __rehash(__n); else if (__n < __bc) { __n = _VSTD::max ( __n, __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : __next_prime(size_t(ceil(float(size()) / max_load_factor()))) ); if (__n < __bc) __rehash(__n); } } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif // _LIBCPP_DEBUG_LEVEL >= 2 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); __bucket_list_.reset(__nbc > 0 ? __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); __bucket_list_.get_deleter().size() = __nbc; if (__nbc > 0) { for (size_type __i = 0; __i < __nbc; ++__i) __bucket_list_[__i] = nullptr; __next_pointer __pp = __p1_.first().__ptr(); __next_pointer __cp = __pp->__next_; if (__cp != nullptr) { size_type __chash = __constrain_hash(__cp->__hash(), __nbc); __bucket_list_[__chash] = __pp; size_type __phash = __chash; for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; __cp = __pp->__next_) { __chash = __constrain_hash(__cp->__hash(), __nbc); if (__chash == __phash) __pp = __cp; else { if (__bucket_list_[__chash] == nullptr) { __bucket_list_[__chash] = __pp; __pp = __cp; __phash = __chash; } else { __next_pointer __np = __cp; for (; __np->__next_ != nullptr && key_eq()(__cp->__upcast()->__value_, __np->__next_->__upcast()->__value_); __np = __np->__next_) ; __pp->__next_ = __np->__next_; __np->__next_ = __bucket_list_[__chash]->__next_; __bucket_list_[__chash]->__next_ = __cp; } } } } } } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) { size_t __hash = hash_function()(__k); size_type __bc = bucket_count(); if (__bc != 0) { size_t __chash = __constrain_hash(__hash, __bc); __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__value_, __k)) #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__nd, this); #else return iterator(__nd); #endif } } } return end(); } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const { size_t __hash = hash_function()(__k); size_type __bc = bucket_count(); if (__bc != 0) { size_t __chash = __constrain_hash(__hash, __bc); __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && (__hash == __nd->__hash() || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__value_, __k)) #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(__nd, this); #else return const_iterator(__nd); #endif } } } return end(); } #ifndef _LIBCPP_CXX03_LANG template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) { static_assert(!__is_hash_value_type<_Args...>::value, "Construct cannot be called with a hash value type"); __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); __h.get_deleter().__value_constructed = true; __h->__hash_ = hash_function()(__h->__value_); __h->__next_ = nullptr; return __h; } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( size_t __hash, _First&& __f, _Rest&& ...__rest) { static_assert(!__is_hash_value_type<_First, _Rest...>::value, "Construct cannot be called with a hash value type"); __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_First>(__f), _VSTD::forward<_Rest>(__rest)...); __h.get_deleter().__value_constructed = true; __h->__hash_ = __hash; __h->__next_ = nullptr; return __h; } #else // _LIBCPP_CXX03_LANG template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v) { __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); __h.get_deleter().__value_constructed = true; __h->__hash_ = hash_function()(__h->__value_); __h->__next_ = nullptr; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, const __container_value_type& __v) { __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); __h.get_deleter().__value_constructed = true; __h->__hash_ = __hash; __h->__next_ = nullptr; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_CXX03_LANG template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) { __next_pointer __np = __p.__node_; #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered container erase(iterator) called with an iterator not" " referring to this container"); _LIBCPP_ASSERT(__p != end(), "unordered container erase(iterator) called with a non-dereferenceable iterator"); iterator __r(__np, this); #else iterator __r(__np); #endif ++__r; remove(__p); return __r; } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, const_iterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, "unodered container::erase(iterator, iterator) called with an iterator not" " referring to this unodered container"); _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, "unodered container::erase(iterator, iterator) called with an iterator not" " referring to this unodered container"); #endif for (const_iterator __p = __first; __first != __last; __p = __first) { ++__first; erase(__p); } __next_pointer __np = __last.__node_; #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator (__np, this); #else return iterator (__np); #endif } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) { iterator __i = find(__k); if (__i == end()) return 0; erase(__i); return 1; } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) { size_type __r = 0; iterator __i = find(__k); if (__i != end()) { iterator __e = end(); do { erase(__i++); ++__r; } while (__i != __e && key_eq()(*__i, __k)); } return __r; } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { // current node __next_pointer __cn = __p.__node_; size_type __bc = bucket_count(); size_t __chash = __constrain_hash(__cn->__hash(), __bc); // find previous node __next_pointer __pn = __bucket_list_[__chash]; for (; __pn->__next_ != __cn; __pn = __pn->__next_) ; // Fix up __bucket_list_ // if __pn is not in same bucket (before begin is not in same bucket) && // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) if (__pn == __p1_.first().__ptr() || __constrain_hash(__pn->__hash(), __bc) != __chash) { if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) __bucket_list_[__chash] = nullptr; } // if __cn->__next_ is not in same bucket (nullptr is in same bucket) if (__cn->__next_ != nullptr) { size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); if (__nhash != __chash) __bucket_list_[__nhash] = __pn; } // remove __cn __pn->__next_ = __cn->__next_; __cn->__next_ = nullptr; --size(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) { --__dp; iterator* __i = static_cast((*__dp)->__i_); if (__i->__node_ == __cn) { (*__dp)->__c_ = nullptr; if (--__c->end_ != __dp) memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); } template template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const { return static_cast(find(__k) != end()); } template template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const { size_type __r = 0; const_iterator __i = find(__k); if (__i != end()) { const_iterator __e = end(); do { ++__i; ++__r; } while (__i != __e && key_eq()(*__i, __k)); } return __r; } template template pair::iterator, typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( const _Key& __k) { iterator __i = find(__k); iterator __j = __i; if (__i != end()) ++__j; return pair(__i, __j); } template template pair::const_iterator, typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( const _Key& __k) const { const_iterator __i = find(__k); const_iterator __j = __i; if (__i != end()) ++__j; return pair(__i, __j); } template template pair::iterator, typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( const _Key& __k) { iterator __i = find(__k); iterator __j = __i; if (__i != end()) { iterator __e = end(); do { ++__j; } while (__j != __e && key_eq()(*__j, __k)); } return pair(__i, __j); } template template pair::const_iterator, typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( const _Key& __k) const { const_iterator __i = find(__k); const_iterator __j = __i; if (__i != end()) { const_iterator __e = end(); do { ++__j; } while (__j != __e && key_eq()(*__j, __k)); } return pair(__i, __j); } template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && __is_nothrow_swappable::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ) #else _NOEXCEPT_(__is_nothrow_swappable::value && __is_nothrow_swappable::value) #endif { _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value || this->__node_alloc() == __u.__node_alloc(), "list::swap: Either propagate_on_container_swap must be true" " or the allocators must compare equal"); { __node_pointer_pointer __npp = __bucket_list_.release(); __bucket_list_.reset(__u.__bucket_list_.release()); __u.__bucket_list_.reset(__npp); } _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); __swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc()); __swap_allocator(__node_alloc(), __u.__node_alloc()); _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); __p2_.swap(__u.__p2_); __p3_.swap(__u.__p3_); if (size() > 0) __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); if (__u.size() > 0) __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = __u.__p1_.first().__ptr(); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__u); #endif } template typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::bucket_size(n) called with n >= bucket_count()"); __next_pointer __np = __bucket_list_[__n]; size_type __bc = bucket_count(); size_type __r = 0; if (__np != nullptr) { for (__np = __np->__next_; __np != nullptr && __constrain_hash(__np->__hash(), __bc) == __n; __np = __np->__next_, ++__r) ; } return __r; } template inline _LIBCPP_INLINE_VISIBILITY void swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } #if _LIBCPP_DEBUG_LEVEL >= 2 template bool __hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const { return __i->__node_ != nullptr; } template bool __hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const { return false; } template bool __hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const { return false; } template bool __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const { return false; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP__HASH_TABLE Index: stable/12/contrib/llvm-project/libcxx/include/__tree =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/__tree (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/__tree (revision 356466) @@ -1,2843 +1,2846 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP___TREE #define _LIBCPP___TREE #include <__config> #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD #if defined(__GNUC__) && !defined(__clang__) // gcc.gnu.org/PR37804 template class _LIBCPP_TEMPLATE_VIS map; template class _LIBCPP_TEMPLATE_VIS multimap; template class _LIBCPP_TEMPLATE_VIS set; template class _LIBCPP_TEMPLATE_VIS multiset; #endif template class __tree; template class _LIBCPP_TEMPLATE_VIS __tree_iterator; template class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; template class __tree_end_node; template class __tree_node_base; template class __tree_node; template struct __value_type; template class __map_node_destructor; template class _LIBCPP_TEMPLATE_VIS __map_iterator; template class _LIBCPP_TEMPLATE_VIS __map_const_iterator; /* _NodePtr algorithms The algorithms taking _NodePtr are red black tree algorithms. Those algorithms taking a parameter named __root should assume that __root points to a proper red black tree (unless otherwise specified). Each algorithm herein assumes that __root->__parent_ points to a non-null structure which has a member __left_ which points back to __root. No other member is read or written to at __root->__parent_. __root->__parent_ will be referred to below (in comments only) as end_node. end_node->__left_ is an externably accessible lvalue for __root, and can be changed by node insertion and removal (without explicit reference to end_node). All nodes (with the exception of end_node), even the node referred to as __root, have a non-null __parent_ field. */ // Returns: true if __x is a left child of its parent, else false // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT { return __x == __x->__parent_->__left_; } // Determines if the subtree rooted at __x is a proper red black subtree. If // __x is a proper subtree, returns the black height (null counts as 1). If // __x is an improper subtree, returns 0. template unsigned __tree_sub_invariant(_NodePtr __x) { if (__x == nullptr) return 1; // parent consistency checked by caller // check __x->__left_ consistency if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x) return 0; // check __x->__right_ consistency if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x) return 0; // check __x->__left_ != __x->__right_ unless both are nullptr if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr) return 0; // If this is red, neither child can be red if (!__x->__is_black_) { if (__x->__left_ && !__x->__left_->__is_black_) return 0; if (__x->__right_ && !__x->__right_->__is_black_) return 0; } unsigned __h = __tree_sub_invariant(__x->__left_); if (__h == 0) return 0; // invalid left subtree if (__h != __tree_sub_invariant(__x->__right_)) return 0; // invalid or different height right subtree return __h + __x->__is_black_; // return black height of this node } // Determines if the red black tree rooted at __root is a proper red black tree. // __root == nullptr is a proper tree. Returns true is __root is a proper // red black tree, else returns false. template bool __tree_invariant(_NodePtr __root) { if (__root == nullptr) return true; // check __x->__parent_ consistency if (__root->__parent_ == nullptr) return false; if (!__tree_is_left_child(__root)) return false; // root must be black if (!__root->__is_black_) return false; // do normal node checks return __tree_sub_invariant(__root) != 0; } // Returns: pointer to the left-most node under __x. // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { while (__x->__left_ != nullptr) __x = __x->__left_; return __x; } // Returns: pointer to the right-most node under __x. // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { while (__x->__right_ != nullptr) __x = __x->__right_; return __x; } // Returns: pointer to the next in-order node after __x. // Precondition: __x != nullptr. template _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { if (__x->__right_ != nullptr) return __tree_min(__x->__right_); while (!__tree_is_left_child(__x)) __x = __x->__parent_unsafe(); return __x->__parent_unsafe(); } template inline _LIBCPP_INLINE_VISIBILITY _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEPT { if (__x->__right_ != nullptr) return static_cast<_EndNodePtr>(__tree_min(__x->__right_)); while (!__tree_is_left_child(__x)) __x = __x->__parent_unsafe(); return static_cast<_EndNodePtr>(__x->__parent_); } // Returns: pointer to the previous in-order node before __x. // Precondition: __x != nullptr. // Note: __x may be the end node. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT { if (__x->__left_ != nullptr) return __tree_max(__x->__left_); _NodePtr __xx = static_cast<_NodePtr>(__x); while (__tree_is_left_child(__xx)) __xx = __xx->__parent_unsafe(); return __xx->__parent_unsafe(); } // Returns: pointer to a node which has no children // Precondition: __x != nullptr. template _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { while (true) { if (__x->__left_ != nullptr) { __x = __x->__left_; continue; } if (__x->__right_ != nullptr) { __x = __x->__right_; continue; } break; } return __x; } // Effects: Makes __x->__right_ the subtree root with __x as its left child // while preserving in-order order. // Precondition: __x->__right_ != nullptr template void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { _NodePtr __y = __x->__right_; __x->__right_ = __y->__left_; if (__x->__right_ != nullptr) __x->__right_->__set_parent(__x); __y->__parent_ = __x->__parent_; if (__tree_is_left_child(__x)) __x->__parent_->__left_ = __y; else __x->__parent_unsafe()->__right_ = __y; __y->__left_ = __x; __x->__set_parent(__y); } // Effects: Makes __x->__left_ the subtree root with __x as its right child // while preserving in-order order. // Precondition: __x->__left_ != nullptr template void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { _NodePtr __y = __x->__left_; __x->__left_ = __y->__right_; if (__x->__left_ != nullptr) __x->__left_->__set_parent(__x); __y->__parent_ = __x->__parent_; if (__tree_is_left_child(__x)) __x->__parent_->__left_ = __y; else __x->__parent_unsafe()->__right_ = __y; __y->__right_ = __x; __x->__set_parent(__y); } // Effects: Rebalances __root after attaching __x to a leaf. // Precondition: __root != nulptr && __x != nullptr. // __x has no children. // __x == __root or == a direct or indirect child of __root. // If __x were to be unlinked from __root (setting __root to // nullptr if __root == __x), __tree_invariant(__root) == true. // Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ // may be different than the value passed in as __root. template void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT { __x->__is_black_ = __x == __root; while (__x != __root && !__x->__parent_unsafe()->__is_black_) { // __x->__parent_ != __root because __x->__parent_->__is_black == false if (__tree_is_left_child(__x->__parent_unsafe())) { _NodePtr __y = __x->__parent_unsafe()->__parent_unsafe()->__right_; if (__y != nullptr && !__y->__is_black_) { __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = __x == __root; __y->__is_black_ = true; } else { if (!__tree_is_left_child(__x)) { __x = __x->__parent_unsafe(); __tree_left_rotate(__x); } __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = false; __tree_right_rotate(__x); break; } } else { _NodePtr __y = __x->__parent_unsafe()->__parent_->__left_; if (__y != nullptr && !__y->__is_black_) { __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = __x == __root; __y->__is_black_ = true; } else { if (__tree_is_left_child(__x)) { __x = __x->__parent_unsafe(); __tree_right_rotate(__x); } __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = false; __tree_left_rotate(__x); break; } } } } // Precondition: __root != nullptr && __z != nullptr. // __tree_invariant(__root) == true. // __z == __root or == a direct or indirect child of __root. // Effects: unlinks __z from the tree rooted at __root, rebalancing as needed. // Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_ // nor any of its children refer to __z. end_node->__left_ // may be different than the value passed in as __root. template void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT { // __z will be removed from the tree. Client still needs to destruct/deallocate it // __y is either __z, or if __z has two children, __tree_next(__z). // __y will have at most one child. // __y will be the initial hole in the tree (make the hole at a leaf) _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ? __z : __tree_next(__z); // __x is __y's possibly null single child _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_; // __w is __x's possibly null uncle (will become __x's sibling) _NodePtr __w = nullptr; // link __x to __y's parent, and find __w if (__x != nullptr) __x->__parent_ = __y->__parent_; if (__tree_is_left_child(__y)) { __y->__parent_->__left_ = __x; if (__y != __root) __w = __y->__parent_unsafe()->__right_; else __root = __x; // __w == nullptr } else { __y->__parent_unsafe()->__right_ = __x; // __y can't be root if it is a right child __w = __y->__parent_->__left_; } bool __removed_black = __y->__is_black_; // If we didn't remove __z, do so now by splicing in __y for __z, // but copy __z's color. This does not impact __x or __w. if (__y != __z) { // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr __y->__parent_ = __z->__parent_; if (__tree_is_left_child(__z)) __y->__parent_->__left_ = __y; else __y->__parent_unsafe()->__right_ = __y; __y->__left_ = __z->__left_; __y->__left_->__set_parent(__y); __y->__right_ = __z->__right_; if (__y->__right_ != nullptr) __y->__right_->__set_parent(__y); __y->__is_black_ = __z->__is_black_; if (__root == __z) __root = __y; } // There is no need to rebalance if we removed a red, or if we removed // the last node. if (__removed_black && __root != nullptr) { // Rebalance: // __x has an implicit black color (transferred from the removed __y) // associated with it, no matter what its color is. // If __x is __root (in which case it can't be null), it is supposed // to be black anyway, and if it is doubly black, then the double // can just be ignored. // If __x is red (in which case it can't be null), then it can absorb // the implicit black just by setting its color to black. // Since __y was black and only had one child (which __x points to), __x // is either red with no children, else null, otherwise __y would have // different black heights under left and right pointers. // if (__x == __root || __x != nullptr && !__x->__is_black_) if (__x != nullptr) __x->__is_black_ = true; else { // Else __x isn't root, and is "doubly black", even though it may // be null. __w can not be null here, else the parent would // see a black height >= 2 on the __x side and a black height // of 1 on the __w side (__w must be a non-null black or a red // with a non-null black child). while (true) { if (!__tree_is_left_child(__w)) // if x is left child { if (!__w->__is_black_) { __w->__is_black_ = true; __w->__parent_unsafe()->__is_black_ = false; __tree_left_rotate(__w->__parent_unsafe()); // __x is still valid // reset __root only if necessary if (__root == __w->__left_) __root = __w; // reset sibling, and it still can't be null __w = __w->__left_->__right_; } // __w->__is_black_ is now true, __w may have null children if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && (__w->__right_ == nullptr || __w->__right_->__is_black_)) { __w->__is_black_ = false; __x = __w->__parent_unsafe(); // __x can no longer be null if (__x == __root || !__x->__is_black_) { __x->__is_black_ = true; break; } // reset sibling, and it still can't be null __w = __tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_; // continue; } else // __w has a red child { if (__w->__right_ == nullptr || __w->__right_->__is_black_) { // __w left child is non-null and red __w->__left_->__is_black_ = true; __w->__is_black_ = false; __tree_right_rotate(__w); // __w is known not to be root, so root hasn't changed // reset sibling, and it still can't be null __w = __w->__parent_unsafe(); } // __w has a right red child, left child may be null __w->__is_black_ = __w->__parent_unsafe()->__is_black_; __w->__parent_unsafe()->__is_black_ = true; __w->__right_->__is_black_ = true; __tree_left_rotate(__w->__parent_unsafe()); break; } } else { if (!__w->__is_black_) { __w->__is_black_ = true; __w->__parent_unsafe()->__is_black_ = false; __tree_right_rotate(__w->__parent_unsafe()); // __x is still valid // reset __root only if necessary if (__root == __w->__right_) __root = __w; // reset sibling, and it still can't be null __w = __w->__right_->__left_; } // __w->__is_black_ is now true, __w may have null children if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && (__w->__right_ == nullptr || __w->__right_->__is_black_)) { __w->__is_black_ = false; __x = __w->__parent_unsafe(); // __x can no longer be null if (!__x->__is_black_ || __x == __root) { __x->__is_black_ = true; break; } // reset sibling, and it still can't be null __w = __tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_; // continue; } else // __w has a red child { if (__w->__left_ == nullptr || __w->__left_->__is_black_) { // __w right child is non-null and red __w->__right_->__is_black_ = true; __w->__is_black_ = false; __tree_left_rotate(__w); // __w is known not to be root, so root hasn't changed // reset sibling, and it still can't be null __w = __w->__parent_unsafe(); } // __w has a left red child, right child may be null __w->__is_black_ = __w->__parent_unsafe()->__is_black_; __w->__parent_unsafe()->__is_black_ = true; __w->__left_->__is_black_ = true; __tree_right_rotate(__w->__parent_unsafe()); break; } } } } } } // node traits #ifndef _LIBCPP_CXX03_LANG template struct __is_tree_value_type_imp : false_type {}; template struct __is_tree_value_type_imp<__value_type<_Key, _Value>> : true_type {}; template struct __is_tree_value_type : false_type {}; template struct __is_tree_value_type<_One> : __is_tree_value_type_imp::type> {}; #endif template struct __tree_key_value_types { typedef _Tp key_type; typedef _Tp __node_value_type; typedef _Tp __container_value_type; static const bool __is_map = false; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(_Tp const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static __container_value_type&& __move(__node_value_type& __v) { return _VSTD::move(__v); } #endif }; template struct __tree_key_value_types<__value_type<_Key, _Tp> > { typedef _Key key_type; typedef _Tp mapped_type; typedef __value_type<_Key, _Tp> __node_value_type; typedef pair __container_value_type; typedef __container_value_type __map_value_type; static const bool __is_map = true; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(__node_value_type const& __t) { return __t.__get_value().first; } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, key_type const&>::type __get_key(_Up& __t) { return __t.first; } _LIBCPP_INLINE_VISIBILITY static __container_value_type const& __get_value(__node_value_type const& __t) { return __t.__get_value(); } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, __container_value_type const&>::type __get_value(_Up& __t) { return __t; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n.__get_value()); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static pair __move(__node_value_type& __v) { return __v.__move(); } #endif }; template struct __tree_node_base_types { typedef _VoidPtr __void_pointer; typedef __tree_node_base<__void_pointer> __node_base_type; typedef typename __rebind_pointer<_VoidPtr, __node_base_type>::type __node_base_pointer; typedef __tree_end_node<__node_base_pointer> __end_node_type; typedef typename __rebind_pointer<_VoidPtr, __end_node_type>::type __end_node_pointer; #if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) typedef __end_node_pointer __parent_pointer; #else typedef typename conditional< is_pointer<__end_node_pointer>::value, __end_node_pointer, __node_base_pointer>::type __parent_pointer; #endif private: static_assert((is_same::element_type, void>::value), "_VoidPtr does not point to unqualified void type"); }; template , bool = _KVTypes::__is_map> struct __tree_map_pointer_types {}; template struct __tree_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { typedef typename _KVTypes::__map_value_type _Mv; typedef typename __rebind_pointer<_AllocPtr, _Mv>::type __map_value_type_pointer; typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type __const_map_value_type_pointer; }; template ::element_type> struct __tree_node_types; template struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> > : public __tree_node_base_types<_VoidPtr>, __tree_key_value_types<_Tp>, __tree_map_pointer_types<_Tp, _VoidPtr> { typedef __tree_node_base_types<_VoidPtr> __base; typedef __tree_key_value_types<_Tp> __key_base; typedef __tree_map_pointer_types<_Tp, _VoidPtr> __map_pointer_base; public: typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef _NodePtr __node_pointer; typedef _Tp __node_value_type; typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type __node_value_type_pointer; typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type __const_node_value_type_pointer; #if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) typedef typename __base::__end_node_pointer __iter_pointer; #else typedef typename conditional< is_pointer<__node_pointer>::value, typename __base::__end_node_pointer, __node_pointer>::type __iter_pointer; #endif private: static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); static_assert((is_same::type, _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); }; template struct __make_tree_node_types { typedef typename __rebind_pointer<_VoidPtr, __tree_node<_ValueTp, _VoidPtr> >::type _NodePtr; typedef __tree_node_types<_NodePtr> type; }; // node template class __tree_end_node { public: typedef _Pointer pointer; pointer __left_; _LIBCPP_INLINE_VISIBILITY __tree_end_node() _NOEXCEPT : __left_() {} }; template class __tree_node_base : public __tree_node_base_types<_VoidPtr>::__end_node_type { typedef __tree_node_base_types<_VoidPtr> _NodeBaseTypes; public: typedef typename _NodeBaseTypes::__node_base_pointer pointer; typedef typename _NodeBaseTypes::__parent_pointer __parent_pointer; pointer __right_; __parent_pointer __parent_; bool __is_black_; _LIBCPP_INLINE_VISIBILITY pointer __parent_unsafe() const { return static_cast(__parent_);} _LIBCPP_INLINE_VISIBILITY void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); } private: ~__tree_node_base() _LIBCPP_EQUAL_DELETE; __tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; __tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; }; template class __tree_node : public __tree_node_base<_VoidPtr> { public: typedef _Tp __node_value_type; __node_value_type __value_; private: ~__tree_node() _LIBCPP_EQUAL_DELETE; __tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE; __tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_DELETE; }; template class __tree_node_destructor { typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; private: typedef __tree_node_types _NodeTypes; allocator_type& __na_; - __tree_node_destructor& operator=(const __tree_node_destructor&); public: bool __value_constructed; + + + __tree_node_destructor(const __tree_node_destructor &) = default; + __tree_node_destructor& operator=(const __tree_node_destructor&) = delete; _LIBCPP_INLINE_VISIBILITY explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT : __na_(__na), __value_constructed(__val) {} _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT { if (__value_constructed) __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } template friend class __map_node_destructor; }; #if _LIBCPP_STD_VER > 14 template struct __generic_container_node_destructor; template struct __generic_container_node_destructor<__tree_node<_Tp, _VoidPtr>, _Alloc> : __tree_node_destructor<_Alloc> { using __tree_node_destructor<_Alloc>::__tree_node_destructor; }; #endif template class _LIBCPP_TEMPLATE_VIS __tree_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef pointer_traits<__node_pointer> __pointer_traits; __iter_pointer __ptr_; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef _DiffType difference_type; typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __ptr_(nullptr) #endif {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_np()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__get_np()->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator++() { __ptr_ = static_cast<__iter_pointer>( __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_iterator operator++(int) {__tree_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator--() { __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( static_cast<__end_node_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_iterator operator--(int) {__tree_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) {return !(__x == __y);} private: _LIBCPP_INLINE_VISIBILITY explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template friend class __tree; template friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS __map_iterator; template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS set; template friend class _LIBCPP_TEMPLATE_VIS multiset; }; template class _LIBCPP_TEMPLATE_VIS __tree_const_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef typename _NodeTypes::__node_pointer __node_pointer; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef pointer_traits<__node_pointer> __pointer_traits; __iter_pointer __ptr_; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef _DiffType difference_type; typedef const value_type& reference; typedef typename _NodeTypes::__const_node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __ptr_(nullptr) #endif {} private: typedef __tree_iterator __non_const_iterator; public: _LIBCPP_INLINE_VISIBILITY __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_np()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__get_np()->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator++() { __ptr_ = static_cast<__iter_pointer>( __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_const_iterator operator++(int) {__tree_const_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator--() { __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( static_cast<__end_node_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_const_iterator operator--(int) {__tree_const_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {return !(__x == __y);} private: _LIBCPP_INLINE_VISIBILITY explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template friend class __tree; template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS set; template friend class _LIBCPP_TEMPLATE_VIS multiset; template friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; }; template #ifndef _LIBCPP_CXX03_LANG _LIBCPP_DIAGNOSE_WARNING(!std::__invokable<_Compare const&, _Tp const&, _Tp const&>::value, "the specified comparator type does not provide a viable const call operator") #endif int __diagnose_non_const_comparator(); template class __tree { public: typedef _Tp value_type; typedef _Compare value_compare; typedef _Allocator allocator_type; private: typedef allocator_traits __alloc_traits; typedef typename __make_tree_node_types::type _NodeTypes; typedef typename _NodeTypes::key_type key_type; public: typedef typename _NodeTypes::__node_value_type __node_value_type; typedef typename _NodeTypes::__container_value_type __container_value_type; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; public: typedef typename _NodeTypes::__void_pointer __void_pointer; typedef typename _NodeTypes::__node_type __node; typedef typename _NodeTypes::__node_pointer __node_pointer; typedef typename _NodeTypes::__node_base_type __node_base; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_type __end_node_t; typedef typename _NodeTypes::__end_node_pointer __end_node_ptr; typedef typename _NodeTypes::__parent_pointer __parent_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; private: // check for sane allocator pointer rebinding semantics. Rebinding the // allocator for a new pointer type should be exactly the same as rebinding // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); typedef typename __rebind_alloc_helper<__node_traits, __node_base>::type __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); private: __iter_pointer __begin_node_; __compressed_pair<__end_node_t, __node_allocator> __pair1_; __compressed_pair __pair3_; public: _LIBCPP_INLINE_VISIBILITY __iter_pointer __end_node() _NOEXCEPT { return static_cast<__iter_pointer>( pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()) ); } _LIBCPP_INLINE_VISIBILITY __iter_pointer __end_node() const _NOEXCEPT { return static_cast<__iter_pointer>( pointer_traits<__end_node_ptr>::pointer_to( const_cast<__end_node_t&>(__pair1_.first()) ) ); } _LIBCPP_INLINE_VISIBILITY __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();} private: _LIBCPP_INLINE_VISIBILITY const __node_allocator& __node_alloc() const _NOEXCEPT {return __pair1_.second();} _LIBCPP_INLINE_VISIBILITY __iter_pointer& __begin_node() _NOEXCEPT {return __begin_node_;} _LIBCPP_INLINE_VISIBILITY const __iter_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;} public: _LIBCPP_INLINE_VISIBILITY allocator_type __alloc() const _NOEXCEPT {return allocator_type(__node_alloc());} private: _LIBCPP_INLINE_VISIBILITY size_type& size() _NOEXCEPT {return __pair3_.first();} public: _LIBCPP_INLINE_VISIBILITY const size_type& size() const _NOEXCEPT {return __pair3_.first();} _LIBCPP_INLINE_VISIBILITY value_compare& value_comp() _NOEXCEPT {return __pair3_.second();} _LIBCPP_INLINE_VISIBILITY const value_compare& value_comp() const _NOEXCEPT {return __pair3_.second();} public: _LIBCPP_INLINE_VISIBILITY __node_pointer __root() const _NOEXCEPT {return static_cast<__node_pointer>(__end_node()->__left_);} __node_base_pointer* __root_ptr() const _NOEXCEPT { return _VSTD::addressof(__end_node()->__left_); } typedef __tree_iterator iterator; typedef __tree_const_iterator const_iterator; explicit __tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_copy_constructible::value); explicit __tree(const allocator_type& __a); __tree(const value_compare& __comp, const allocator_type& __a); __tree(const __tree& __t); __tree& operator=(const __tree& __t); template void __assign_unique(_ForwardIterator __first, _ForwardIterator __last); template void __assign_multi(_InputIterator __first, _InputIterator __last); #ifndef _LIBCPP_CXX03_LANG __tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value); __tree(__tree&& __t, const allocator_type& __a); __tree& operator=(__tree&& __t) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value); #endif // _LIBCPP_CXX03_LANG ~__tree(); _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(__begin_node());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(__end_node());} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return std::min( __node_traits::max_size(__node_alloc()), numeric_limits::max());} void clear() _NOEXCEPT; void swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ); #else _NOEXCEPT_(__is_nothrow_swappable::value); #endif #ifndef _LIBCPP_CXX03_LANG template pair __emplace_unique_key_args(_Key const&, _Args&&... __args); template iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...); template pair __emplace_unique_impl(_Args&&... __args); template iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args); template iterator __emplace_multi(_Args&&... __args); template iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Pp&& __x) { return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); } template _LIBCPP_INLINE_VISIBILITY typename enable_if< __can_extract_map_key<_First, key_type, __container_value_type>::value, pair >::type __emplace_unique(_First&& __f, _Second&& __s) { return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), _VSTD::forward<_Second>(__s)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Args&&... __args) { return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique(const_iterator __p, _Pp&& __x) { return __emplace_hint_unique_extract_key(__p, _VSTD::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); } template _LIBCPP_INLINE_VISIBILITY typename enable_if< __can_extract_map_key<_First, key_type, __container_value_type>::value, iterator >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) { return __emplace_hint_unique_key_args(__p, __f, _VSTD::forward<_First>(__f), _VSTD::forward<_Second>(__s)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) { return __emplace_hint_unique_impl(__p, _VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_fail_tag) { return __emplace_hint_unique_impl(__p, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_self_tag) { return __emplace_hint_unique_key_args(__p, __x, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_first_tag) { return __emplace_hint_unique_key_args(__p, __x.first, _VSTD::forward<_Pp>(__x)); } #else template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_key_args(_Key const&, _Args& __args); template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&); #endif _LIBCPP_INLINE_VISIBILITY pair __insert_unique(const __container_value_type& __v) { return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v); } _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, const __container_value_type& __v) { return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v); } #ifdef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const __container_value_type& __v); _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, const __container_value_type& __v); #else _LIBCPP_INLINE_VISIBILITY pair __insert_unique(__container_value_type&& __v) { return __emplace_unique_key_args(_NodeTypes::__get_key(__v), _VSTD::move(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, __container_value_type&& __v) { return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), _VSTD::move(__v)); } template ::type, __container_value_type >::value >::type> _LIBCPP_INLINE_VISIBILITY pair __insert_unique(_Vp&& __v) { return __emplace_unique(_VSTD::forward<_Vp>(__v)); } template ::type, __container_value_type >::value >::type> _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, _Vp&& __v) { return __emplace_hint_unique(__p, _VSTD::forward<_Vp>(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(__container_value_type&& __v) { return __emplace_multi(_VSTD::move(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, __container_value_type&& __v) { return __emplace_hint_multi(__p, _VSTD::move(__v)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(_Vp&& __v) { return __emplace_multi(_VSTD::forward<_Vp>(__v)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, _Vp&& __v) { return __emplace_hint_multi(__p, _VSTD::forward<_Vp>(__v)); } #endif // !_LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY pair __node_assign_unique(const __container_value_type& __v, __node_pointer __dest); _LIBCPP_INLINE_VISIBILITY iterator __node_insert_multi(__node_pointer __nd); _LIBCPP_INLINE_VISIBILITY iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); _LIBCPP_INLINE_VISIBILITY iterator __remove_node_pointer(__node_pointer) _NOEXCEPT; #if _LIBCPP_STD_VER > 14 template _LIBCPP_INLINE_VISIBILITY _InsertReturnType __node_handle_insert_unique(_NodeHandle&&); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_unique(const_iterator, _NodeHandle&&); template _LIBCPP_INLINE_VISIBILITY void __node_handle_merge_unique(_Tree& __source); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_multi(_NodeHandle&&); template _LIBCPP_INLINE_VISIBILITY iterator __node_handle_insert_multi(const_iterator, _NodeHandle&&); template _LIBCPP_INLINE_VISIBILITY void __node_handle_merge_multi(_Tree& __source); template _LIBCPP_INLINE_VISIBILITY _NodeHandle __node_handle_extract(key_type const&); template _LIBCPP_INLINE_VISIBILITY _NodeHandle __node_handle_extract(const_iterator); #endif iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); template size_type __erase_unique(const _Key& __k); template size_type __erase_multi(const _Key& __k); void __insert_node_at(__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT; template iterator find(const _Key& __v); template const_iterator find(const _Key& __v) const; template size_type __count_unique(const _Key& __k) const; template size_type __count_multi(const _Key& __k) const; template _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const _Key& __v) {return __lower_bound(__v, __root(), __end_node());} template iterator __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result); template _LIBCPP_INLINE_VISIBILITY const_iterator lower_bound(const _Key& __v) const {return __lower_bound(__v, __root(), __end_node());} template const_iterator __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const; template _LIBCPP_INLINE_VISIBILITY iterator upper_bound(const _Key& __v) {return __upper_bound(__v, __root(), __end_node());} template iterator __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result); template _LIBCPP_INLINE_VISIBILITY const_iterator upper_bound(const _Key& __v) const {return __upper_bound(__v, __root(), __end_node());} template const_iterator __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const; template pair __equal_range_unique(const _Key& __k); template pair __equal_range_unique(const _Key& __k) const; template pair __equal_range_multi(const _Key& __k); template pair __equal_range_multi(const _Key& __k) const; typedef __tree_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; __node_holder remove(const_iterator __p) _NOEXCEPT; private: __node_base_pointer& __find_leaf_low(__parent_pointer& __parent, const key_type& __v); __node_base_pointer& __find_leaf_high(__parent_pointer& __parent, const key_type& __v); __node_base_pointer& __find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v); // FIXME: Make this function const qualified. Unfortunetly doing so // breaks existing code which uses non-const callable comparators. template __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v); template _LIBCPP_INLINE_VISIBILITY __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v) const { return const_cast<__tree*>(this)->__find_equal(__parent, __v); } template __node_base_pointer& __find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v); #ifndef _LIBCPP_CXX03_LANG template __node_holder __construct_node(_Args&& ...__args); #else __node_holder __construct_node(const __container_value_type& __v); #endif void destroy(__node_pointer __nd) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree& __t) {__copy_assign_alloc(__t, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree& __t, true_type) { if (__node_alloc() != __t.__node_alloc()) clear(); __node_alloc() = __t.__node_alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree&, false_type) {} void __move_assign(__tree& __t, false_type); void __move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree& __t) _NOEXCEPT_( !__node_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable<__node_allocator>::value) {__move_assign_alloc(__t, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {__node_alloc() = _VSTD::move(__t.__node_alloc());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} struct _DetachedTreeCache { _LIBCPP_INLINE_VISIBILITY explicit _DetachedTreeCache(__tree *__t) _NOEXCEPT : __t_(__t), __cache_root_(__detach_from_tree(__t)) { __advance(); } _LIBCPP_INLINE_VISIBILITY __node_pointer __get() const _NOEXCEPT { return __cache_elem_; } _LIBCPP_INLINE_VISIBILITY void __advance() _NOEXCEPT { __cache_elem_ = __cache_root_; if (__cache_root_) { __cache_root_ = __detach_next(__cache_root_); } } _LIBCPP_INLINE_VISIBILITY ~_DetachedTreeCache() { __t_->destroy(__cache_elem_); if (__cache_root_) { while (__cache_root_->__parent_ != nullptr) __cache_root_ = static_cast<__node_pointer>(__cache_root_->__parent_); __t_->destroy(__cache_root_); } } _DetachedTreeCache(_DetachedTreeCache const&) = delete; _DetachedTreeCache& operator=(_DetachedTreeCache const&) = delete; private: _LIBCPP_INLINE_VISIBILITY static __node_pointer __detach_from_tree(__tree *__t) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static __node_pointer __detach_next(__node_pointer) _NOEXCEPT; __tree *__t_; __node_pointer __cache_root_; __node_pointer __cache_elem_; }; template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; }; template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_copy_constructible::value) : __pair3_(0, __comp) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, __comp) { __begin_node() = __end_node(); } // Precondition: size() != 0 template typename __tree<_Tp, _Compare, _Allocator>::__node_pointer __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree *__t) _NOEXCEPT { __node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node()); __t->__begin_node() = __t->__end_node(); __t->__end_node()->__left_->__parent_ = nullptr; __t->__end_node()->__left_ = nullptr; __t->size() = 0; // __cache->__left_ == nullptr if (__cache->__right_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__right_); // __cache->__left_ == nullptr // __cache->__right_ == nullptr return __cache; } // Precondition: __cache != nullptr // __cache->left_ == nullptr // __cache->right_ == nullptr // This is no longer a red-black tree template typename __tree<_Tp, _Compare, _Allocator>::__node_pointer __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_pointer __cache) _NOEXCEPT { if (__cache->__parent_ == nullptr) return nullptr; if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) { __cache->__parent_->__left_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); if (__cache->__right_ == nullptr) return __cache; return static_cast<__node_pointer>(__tree_leaf(__cache->__right_)); } // __cache is right child __cache->__parent_unsafe()->__right_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); if (__cache->__left_ == nullptr) return __cache; return static_cast<__node_pointer>(__tree_leaf(__cache->__left_)); } template __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) { if (this != &__t) { value_comp() = __t.value_comp(); __copy_assign_alloc(__t); __assign_multi(__t.begin(), __t.end()); } return *this; } template template void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) { typedef iterator_traits<_ForwardIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value), "__assign_unique may only be called with the containers value type"); static_assert(__is_forward_iterator<_ForwardIterator>::value, "__assign_unique requires a forward iterator"); if (size() != 0) { _DetachedTreeCache __cache(this); for (; __cache.__get() != nullptr && __first != __last; ++__first) { if (__node_assign_unique(*__first, __cache.__get()).second) __cache.__advance(); } } for (; __first != __last; ++__first) __insert_unique(*__first); } template template void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) { typedef iterator_traits<_InputIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value), "__assign_multi may only be called with the containers value type" " or the nodes value type"); if (size() != 0) { _DetachedTreeCache __cache(this); for (; __cache.__get() && __first != __last; ++__first) { __cache.__get()->__value_ = *__first; __node_insert_multi(__cache.__get()); __cache.__advance(); } } for (; __first != __last; ++__first) __insert_multi(_NodeTypes::__get_value(*__first)); } template __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), __pair3_(0, __t.value_comp()) { __begin_node() = __end_node(); } #ifndef _LIBCPP_CXX03_LANG template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value) : __begin_node_(_VSTD::move(__t.__begin_node_)), __pair1_(_VSTD::move(__t.__pair1_)), __pair3_(_VSTD::move(__t.__pair3_)) { if (size() == 0) __begin_node() = __end_node(); else { __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) : __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, _VSTD::move(__t.value_comp())) { if (__a == __t.__alloc()) { if (__t.size() == 0) __begin_node() = __end_node(); else { __begin_node() = __t.__begin_node(); __end_node()->__left_ = __t.__end_node()->__left_; __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); size() = __t.size(); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } else { __begin_node() = __end_node(); } } template void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value) { destroy(static_cast<__node_pointer>(__end_node()->__left_)); __begin_node_ = __t.__begin_node_; __pair1_.first() = __t.__pair1_.first(); __move_assign_alloc(__t); __pair3_ = _VSTD::move(__t.__pair3_); if (size() == 0) __begin_node() = __end_node(); else { __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } template void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) { if (__node_alloc() == __t.__node_alloc()) __move_assign(__t, true_type()); else { value_comp() = _VSTD::move(__t.value_comp()); const_iterator __e = end(); if (size() != 0) { _DetachedTreeCache __cache(this); while (__cache.__get() != nullptr && __t.size() != 0) { __cache.__get()->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); __node_insert_multi(__cache.__get()); __cache.__advance(); } } while (__t.size() != 0) __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_)); } } template __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value) { __move_assign(__t, integral_constant()); return *this; } #endif // _LIBCPP_CXX03_LANG template __tree<_Tp, _Compare, _Allocator>::~__tree() { static_assert((is_copy_constructible::value), "Comparator must be copy-constructible."); destroy(__root()); } template void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT { if (__nd != nullptr) { destroy(static_cast<__node_pointer>(__nd->__left_)); destroy(static_cast<__node_pointer>(__nd->__right_)); __node_allocator& __na = __node_alloc(); __node_traits::destroy(__na, _NodeTypes::__get_ptr(__nd->__value_)); __node_traits::deallocate(__na, __nd, 1); } } template void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ) #else _NOEXCEPT_(__is_nothrow_swappable::value) #endif { using _VSTD::swap; swap(__begin_node_, __t.__begin_node_); swap(__pair1_.first(), __t.__pair1_.first()); __swap_allocator(__node_alloc(), __t.__node_alloc()); __pair3_.swap(__t.__pair3_); if (size() == 0) __begin_node() = __end_node(); else __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); if (__t.size() == 0) __t.__begin_node() = __t.__end_node(); else __t.__end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__t.__end_node()); } template void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT { destroy(__root()); size() = 0; __begin_node() = __end_node(); __end_node()->__left_ = nullptr; } // Find lower_bound place to insert // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, const key_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__nd->__value_, __v)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } else { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find upper_bound place to insert // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent, const key_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__v, __nd->__value_)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } else { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find leaf place to insert closest to __hint // First check prior to __hint. // Next check after __hint. // Next do O(log N) search. // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v) { if (__hint == end() || !value_comp()(*__hint, __v)) // check before { // __v <= *__hint const_iterator __prior = __hint; if (__prior == begin() || !value_comp()(__v, *--__prior)) { // *prev(__hint) <= __v <= *__hint if (__hint.__ptr_->__left_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } else { __parent = static_cast<__parent_pointer>(__prior.__ptr_); return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } } // __v < *prev(__hint) return __find_leaf_high(__parent, __v); } // else __v > *__hint return __find_leaf_low(__parent, __v); } // Find place to insert if __v doesn't exist // Set __parent to parent of null leaf // Return reference to null leaf // If __v exists, set parent to node of __v and return reference to node of __v template template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, const _Key& __v) { __node_pointer __nd = __root(); __node_base_pointer* __nd_ptr = __root_ptr(); if (__nd != nullptr) { while (true) { if (value_comp()(__v, __nd->__value_)) { if (__nd->__left_ != nullptr) { __nd_ptr = _VSTD::addressof(__nd->__left_); __nd = static_cast<__node_pointer>(__nd->__left_); } else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } else if (value_comp()(__nd->__value_, __v)) { if (__nd->__right_ != nullptr) { __nd_ptr = _VSTD::addressof(__nd->__right_); __nd = static_cast<__node_pointer>(__nd->__right_); } else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } else { __parent = static_cast<__parent_pointer>(__nd); return *__nd_ptr; } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find place to insert if __v doesn't exist // First check prior to __hint. // Next check after __hint. // Next do O(log N) search. // Set __parent to parent of null leaf // Return reference to null leaf // If __v exists, set parent to node of __v and return reference to node of __v template template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v) { if (__hint == end() || value_comp()(__v, *__hint)) // check before { // __v < *__hint const_iterator __prior = __hint; if (__prior == begin() || value_comp()(*--__prior, __v)) { // *prev(__hint) < __v < *__hint if (__hint.__ptr_->__left_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } else { __parent = static_cast<__parent_pointer>(__prior.__ptr_); return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } } // __v <= *prev(__hint) return __find_equal(__parent, __v); } else if (value_comp()(*__hint, __v)) // check after { // *__hint < __v const_iterator __next = _VSTD::next(__hint); if (__next == end() || value_comp()(__v, *__next)) { // *__hint < __v < *_VSTD::next(__hint) if (__hint.__get_np()->__right_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_; } else { __parent = static_cast<__parent_pointer>(__next.__ptr_); return __parent->__left_; } } // *next(__hint) <= __v return __find_equal(__parent, __v); } // else __v == *__hint __parent = static_cast<__parent_pointer>(__hint.__ptr_); __dummy = static_cast<__node_base_pointer>(__hint.__ptr_); return __dummy; } template void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( __parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT { __new_node->__left_ = nullptr; __new_node->__right_ = nullptr; __new_node->__parent_ = __parent; // __new_node->__is_black_ is initialized in __tree_balance_after_insert __child = __new_node; if (__begin_node()->__left_ != nullptr) __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_); __tree_balance_after_insert(__end_node()->__left_, __child); ++size(); } #ifndef _LIBCPP_CXX03_LANG template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) #else template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args& __args) #endif { __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __k); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { #ifndef _LIBCPP_CXX03_LANG __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); #else __node_holder __h = __construct_node(__args); #endif __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } return pair(iterator(__r), __inserted); } #ifndef _LIBCPP_CXX03_LANG template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( const_iterator __p, _Key const& __k, _Args&&... __args) #else template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( const_iterator __p, _Key const& __k, _Args& __args) #endif { __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { #ifndef _LIBCPP_CXX03_LANG __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); #else __node_holder __h = __construct_node(__args); #endif __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); } #ifndef _LIBCPP_CXX03_LANG template template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&& ...__args) { static_assert(!__is_tree_value_type<_Args...>::value, "Cannot construct from __value_type"); __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); __h.get_deleter().__value_constructed = true; return __h; } template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __h->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } return pair(iterator(__r), __inserted); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __h->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } #else // _LIBCPP_CXX03_LANG template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::__construct_node(const __container_value_type& __v) { __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); __h.get_deleter().__value_constructed = true; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_CXX03_LANG #ifdef _LIBCPP_CXX03_LANG template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__insert_multi(const __container_value_type& __v) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__v)); __node_holder __h = __construct_node(__v); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __container_value_type& __v) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__v)); __node_holder __h = __construct_node(__v); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } #endif template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const __container_value_type& __v, __node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__v)); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __nd->__value_ = __v; __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; __inserted = true; } return pair(iterator(__r), __inserted); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, __node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT { iterator __r(__ptr); ++__r; if (__begin_node() == __ptr) __begin_node() = __r.__ptr_; --size(); __tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__ptr)); return __r; } #if _LIBCPP_STD_VER > 14 template template _LIBCPP_INLINE_VISIBILITY _InsertReturnType __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( _NodeHandle&& __nh) { if (__nh.empty()) return _InsertReturnType{end(), false, _NodeHandle()}; __node_pointer __ptr = __nh.__ptr_; __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __ptr->__value_); if (__child != nullptr) return _InsertReturnType{ iterator(static_cast<__node_pointer>(__child)), false, _VSTD::move(__nh)}; __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return _InsertReturnType{iterator(__ptr), true, _NodeHandle()}; } template template _LIBCPP_INLINE_VISIBILITY typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( const_iterator __hint, _NodeHandle&& __nh) { if (__nh.empty()) return end(); __node_pointer __ptr = __nh.__ptr_; __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__hint, __parent, __dummy, __ptr->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); __r = __ptr; __nh.__release_ptr(); } return iterator(__r); } template template _LIBCPP_INLINE_VISIBILITY _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_handle_extract(key_type const& __key) { iterator __it = find(__key); if (__it == end()) return _NodeHandle(); return __node_handle_extract<_NodeHandle>(__it); } template template _LIBCPP_INLINE_VISIBILITY _NodeHandle __tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) { __node_pointer __np = __p.__get_np(); __remove_node_pointer(__np); return _NodeHandle(__np, __alloc()); } template template _LIBCPP_INLINE_VISIBILITY void __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_unique(_Tree& __source) { static_assert(is_same::value, ""); for (typename _Tree::iterator __i = __source.begin(); __i != __source.end();) { __node_pointer __src_ptr = __i.__get_np(); __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__src_ptr->__value_)); ++__i; if (__child != nullptr) continue; __source.__remove_node_pointer(__src_ptr); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__src_ptr)); } } template template _LIBCPP_INLINE_VISIBILITY typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh) { if (__nh.empty()) return end(); __node_pointer __ptr = __nh.__ptr_; __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high( __parent, _NodeTypes::__get_key(__ptr->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return iterator(__ptr); } template template _LIBCPP_INLINE_VISIBILITY typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi( const_iterator __hint, _NodeHandle&& __nh) { if (__nh.empty()) return end(); __node_pointer __ptr = __nh.__ptr_; __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__hint, __parent, _NodeTypes::__get_key(__ptr->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); __nh.__release_ptr(); return iterator(__ptr); } template template _LIBCPP_INLINE_VISIBILITY void __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(_Tree& __source) { static_assert(is_same::value, ""); for (typename _Tree::iterator __i = __source.begin(); __i != __source.end();) { __node_pointer __src_ptr = __i.__get_np(); __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high( __parent, _NodeTypes::__get_key(__src_ptr->__value_)); ++__i; __source.__remove_node_pointer(__src_ptr); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__src_ptr)); } } #endif // _LIBCPP_STD_VER > 14 template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { __node_pointer __np = __p.__get_np(); iterator __r = __remove_node_pointer(__np); __node_allocator& __na = __node_alloc(); __node_traits::destroy(__na, _NodeTypes::__get_ptr( const_cast<__node_value_type&>(*__p))); __node_traits::deallocate(__na, __np, 1); return __r; } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) { while (__f != __l) __f = erase(__f); return iterator(__l.__ptr_); } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) { iterator __i = find(__k); if (__i == end()) return 0; erase(__i); return 1; } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) { pair __p = __equal_range_multi(__k); size_type __r = 0; for (; __p.first != __p.second; ++__r) __p.first = erase(__p.first); return __r; } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) { iterator __p = __lower_bound(__v, __root(), __end_node()); if (__p != end() && !value_comp()(__v, *__p)) return __p; return end(); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const { const_iterator __p = __lower_bound(__v, __root(), __end_node()); if (__p != end() && !value_comp()(__v, *__p)) return __p; return end(); } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const { __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return 1; } return 0; } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const { __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _VSTD::distance( __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result) ); } return 0; } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) { while (__root != nullptr) { if (!value_comp()(__root->__value_, __v)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const { while (__root != nullptr) { if (!value_comp()(__root->__value_, __v)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) { while (__root != nullptr) { if (value_comp()(__v, __root->__value_)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const { while (__root != nullptr) { if (value_comp()(__v, __root->__value_)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(iterator(__rt), iterator( __rt->__right_ != nullptr ? static_cast<__iter_pointer>(__tree_min(__rt->__right_)) : __result)); } return _Pp(iterator(__result), iterator(__result)); } template template pair::const_iterator, typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(const_iterator(__rt), const_iterator( __rt->__right_ != nullptr ? static_cast<__iter_pointer>(__tree_min(__rt->__right_)) : __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template template pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(iterator(__result), iterator(__result)); } template template pair::const_iterator, typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT { __node_pointer __np = __p.__get_np(); if (__begin_node() == __p.__ptr_) { if (__np->__right_ != nullptr) __begin_node() = static_cast<__iter_pointer>(__np->__right_); else __begin_node() = static_cast<__iter_pointer>(__np->__parent_); } --size(); __tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np)); return __node_holder(__np, _Dp(__node_alloc(), true)); } template inline _LIBCPP_INLINE_VISIBILITY void swap(__tree<_Tp, _Compare, _Allocator>& __x, __tree<_Tp, _Compare, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP___TREE Index: stable/12/contrib/llvm-project/libcxx/include/ext/hash_map =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/ext/hash_map (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/ext/hash_map (revision 356466) @@ -1,982 +1,983 @@ // -*- C++ -*- //===-------------------------- hash_map ----------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_HASH_MAP #define _LIBCPP_HASH_MAP /* hash_map synopsis namespace __gnu_cxx { template , class Pred = equal_to, class Alloc = allocator>> class hash_map { public: // types typedef Key key_type; typedef T mapped_type; typedef Hash hasher; typedef Pred key_equal; typedef Alloc allocator_type; typedef pair value_type; typedef value_type& reference; typedef const value_type& const_reference; typedef typename allocator_traits::pointer pointer; typedef typename allocator_traits::const_pointer const_pointer; typedef typename allocator_traits::size_type size_type; typedef typename allocator_traits::difference_type difference_type; typedef /unspecified/ iterator; typedef /unspecified/ const_iterator; explicit hash_map(size_type n = 193, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); template hash_map(InputIterator f, InputIterator l, size_type n = 193, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); hash_map(const hash_map&); ~hash_map(); hash_map& operator=(const hash_map&); allocator_type get_allocator() const; bool empty() const; size_type size() const; size_type max_size() const; iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; pair insert(const value_type& obj); template void insert(InputIterator first, InputIterator last); void erase(const_iterator position); size_type erase(const key_type& k); void erase(const_iterator first, const_iterator last); void clear(); void swap(hash_map&); hasher hash_funct() const; key_equal key_eq() const; iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; mapped_type& operator[](const key_type& k); size_type bucket_count() const; size_type max_bucket_count() const; size_type elems_in_bucket(size_type n) const; void resize(size_type n); }; template void swap(hash_map& x, hash_map& y); template bool operator==(const hash_map& x, const hash_map& y); template bool operator!=(const hash_map& x, const hash_map& y); template , class Pred = equal_to, class Alloc = allocator>> class hash_multimap { public: // types typedef Key key_type; typedef T mapped_type; typedef Hash hasher; typedef Pred key_equal; typedef Alloc allocator_type; typedef pair value_type; typedef value_type& reference; typedef const value_type& const_reference; typedef typename allocator_traits::pointer pointer; typedef typename allocator_traits::const_pointer const_pointer; typedef typename allocator_traits::size_type size_type; typedef typename allocator_traits::difference_type difference_type; typedef /unspecified/ iterator; typedef /unspecified/ const_iterator; explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); template hash_multimap(InputIterator f, InputIterator l, size_type n = 193, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); explicit hash_multimap(const allocator_type&); hash_multimap(const hash_multimap&); ~hash_multimap(); hash_multimap& operator=(const hash_multimap&); allocator_type get_allocator() const; bool empty() const; size_type size() const; size_type max_size() const; iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; iterator insert(const value_type& obj); template void insert(InputIterator first, InputIterator last); void erase(const_iterator position); size_type erase(const key_type& k); void erase(const_iterator first, const_iterator last); void clear(); void swap(hash_multimap&); hasher hash_funct() const; key_equal key_eq() const; iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; size_type bucket_count() const; size_type max_bucket_count() const; size_type elems_in_bucket(size_type n) const; void resize(size_type n); }; template void swap(hash_multimap& x, hash_multimap& y); template bool operator==(const hash_multimap& x, const hash_multimap& y); template bool operator!=(const hash_multimap& x, const hash_multimap& y); } // __gnu_cxx */ #include <__config> #include <__hash_table> #include #include #include #include #if __DEPRECATED #if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Use of the header is deprecated. Migrate to ") #else # warning Use of the header is deprecated. Migrate to #endif #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif namespace __gnu_cxx { template ::value && !std::__libcpp_is_final<_Hash>::value > class __hash_map_hasher : private _Hash { public: _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {} _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {} _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;} _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Tp& __x) const {return static_cast(*this)(__x.first);} _LIBCPP_INLINE_VISIBILITY size_t operator()(const typename _Tp::first_type& __x) const {return static_cast(*this)(__x);} }; template class __hash_map_hasher<_Tp, _Hash, false> { _Hash __hash_; public: _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {} _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {} _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;} _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Tp& __x) const {return __hash_(__x.first);} _LIBCPP_INLINE_VISIBILITY size_t operator()(const typename _Tp::first_type& __x) const {return __hash_(__x);} }; template ::value && !std::__libcpp_is_final<_Pred>::value > class __hash_map_equal : private _Pred { public: _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {} _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {} _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return static_cast(*this)(__x.first, __y.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const {return static_cast(*this)(__x, __y.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const {return static_cast(*this)(__x.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Tp::first_type& __x, const typename _Tp::first_type& __y) const {return static_cast(*this)(__x, __y);} }; template class __hash_map_equal<_Tp, _Pred, false> { _Pred __pred_; public: _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {} _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {} _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __pred_(__x.first, __y.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const {return __pred_(__x, __y.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const {return __pred_(__x.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Tp::first_type& __x, const typename _Tp::first_type& __y) const {return __pred_(__x, __y);} }; template class __hash_map_node_destructor { typedef _Alloc allocator_type; typedef std::allocator_traits __alloc_traits; typedef typename __alloc_traits::value_type::__node_value_type value_type; public: typedef typename __alloc_traits::pointer pointer; private: typedef typename value_type::first_type first_type; typedef typename value_type::second_type second_type; allocator_type& __na_; - __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); - public: bool __first_constructed; bool __second_constructed; + + __hash_map_node_destructor(__hash_map_node_destructor const&) = default; + __hash_map_node_destructor& operator=(const __hash_map_node_destructor&) = delete; _LIBCPP_INLINE_VISIBILITY explicit __hash_map_node_destructor(allocator_type& __na) : __na_(__na), __first_constructed(false), __second_constructed(false) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(std::__hash_node_destructor&& __x) : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) { __x.__value_constructed = false; } #else // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(const std::__hash_node_destructor& __x) : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) { const_cast(__x.__value_constructed) = false; } #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) { if (__second_constructed) __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); if (__first_constructed) __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } }; template class _LIBCPP_TEMPLATE_VIS __hash_map_iterator { _HashIterator __i_; typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: typedef std::forward_iterator_tag iterator_category; typedef std::pair value_type; typedef typename _HashIterator::difference_type difference_type; typedef value_type& reference; typedef typename std::__rebind_pointer::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __hash_map_iterator operator++(int) { __hash_map_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {return __x.__i_ == __y.__i_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {return __x.__i_ != __y.__i_;} template friend class _LIBCPP_TEMPLATE_VIS hash_map; template friend class _LIBCPP_TEMPLATE_VIS hash_multimap; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; template friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; }; template class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator { _HashIterator __i_; typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: typedef std::forward_iterator_tag iterator_category; typedef std::pair value_type; typedef typename _HashIterator::difference_type difference_type; typedef const value_type& reference; typedef typename std::__rebind_pointer::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator( __hash_map_iterator __i) : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator& operator++() {++__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator operator++(int) { __hash_map_const_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {return __x.__i_ == __y.__i_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {return __x.__i_ != __y.__i_;} template friend class _LIBCPP_TEMPLATE_VIS hash_map; template friend class _LIBCPP_TEMPLATE_VIS hash_multimap; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; }; template , class _Pred = std::equal_to<_Key>, class _Alloc = std::allocator > > class _LIBCPP_TEMPLATE_VIS hash_map { public: // types typedef _Key key_type; typedef _Tp mapped_type; typedef _Tp data_type; typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; typedef std::pair value_type; typedef value_type& reference; typedef const value_type& const_reference; private: typedef std::pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; typedef typename std::__rebind_alloc_helper< std::allocator_traits, __value_type>::type __allocator_type; typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; typedef typename __table::__node_pointer __node_pointer; typedef typename __table::__node_const_pointer __node_const_pointer; typedef typename __table::__node_traits __node_traits; typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; typedef std::unique_ptr<__node, _Dp> __node_holder; typedef std::allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef __hash_map_iterator iterator; typedef __hash_map_const_iterator const_iterator; _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);} explicit hash_map(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); hash_map(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); template hash_map(_InputIterator __first, _InputIterator __last); template hash_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); template hash_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); hash_map(const hash_map& __u); _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const {return allocator_type(__table_.__node_alloc());} _LIBCPP_INLINE_VISIBILITY bool empty() const {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const {return __table_.size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const {return __table_.max_size();} _LIBCPP_INLINE_VISIBILITY iterator begin() {return __table_.begin();} _LIBCPP_INLINE_VISIBILITY iterator end() {return __table_.end();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __table_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY std::pair insert(const value_type& __x) {return __table_.__insert_unique(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} template _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); _LIBCPP_INLINE_VISIBILITY void erase(const_iterator __p) {__table_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} _LIBCPP_INLINE_VISIBILITY void erase(const_iterator __first, const_iterator __last) {__table_.erase(__first.__i_, __last.__i_);} _LIBCPP_INLINE_VISIBILITY void clear() {__table_.clear();} _LIBCPP_INLINE_VISIBILITY void swap(hash_map& __u) {__table_.swap(__u.__table_);} _LIBCPP_INLINE_VISIBILITY hasher hash_funct() const {return __table_.hash_function().hash_function();} _LIBCPP_INLINE_VISIBILITY key_equal key_eq() const {return __table_.key_eq().key_eq();} _LIBCPP_INLINE_VISIBILITY iterator find(const key_type& __k) {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} _LIBCPP_INLINE_VISIBILITY std::pair equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY std::pair equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} mapped_type& operator[](const key_type& __k); _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const {return __table_.max_bucket_count();} _LIBCPP_INLINE_VISIBILITY size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {__table_.rehash(__n);} private: __node_holder __construct_node(const key_type& __k); }; template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { __table_.rehash(__n); } template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { __table_.rehash(__n); } template template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( _InputIterator __first, _InputIterator __last) { __table_.rehash(193); insert(__first, __last); } template template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { __table_.rehash(__n); insert(__first, __last); } template template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { __table_.rehash(__n); insert(__first, __last); } template hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( const hash_map& __u) : __table_(__u.__table_) { __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } template typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) { __node_allocator& __na = __table_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); __h.get_deleter().__first_constructed = true; __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); __h.get_deleter().__second_constructed = true; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template template inline void hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) { for (; __first != __last; ++__first) __table_.__insert_unique(*__first); } template _Tp& hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) { iterator __i = find(__k); if (__i != end()) return __i->second; __node_holder __h = __construct_node(__k); std::pair __r = __table_.__node_insert_unique(__h.get()); __h.release(); return __r.first->second; } template inline _LIBCPP_INLINE_VISIBILITY void swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { __x.swap(__y); } template bool operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { if (__x.size() != __y.size()) return false; typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator; for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); __i != __ex; ++__i) { const_iterator __j = __y.find(__i->first); if (__j == __ey || !(*__i == *__j)) return false; } return true; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { return !(__x == __y); } template , class _Pred = std::equal_to<_Key>, class _Alloc = std::allocator > > class _LIBCPP_TEMPLATE_VIS hash_multimap { public: // types typedef _Key key_type; typedef _Tp mapped_type; typedef _Tp data_type; typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; typedef std::pair value_type; typedef value_type& reference; typedef const value_type& const_reference; private: typedef std::pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; typedef typename std::__rebind_alloc_helper, __value_type>::type __allocator_type; typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; typedef typename __table::__node_traits __node_traits; typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; typedef std::unique_ptr<__node, _Dp> __node_holder; typedef std::allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef __hash_map_iterator iterator; typedef __hash_map_const_iterator const_iterator; _LIBCPP_INLINE_VISIBILITY hash_multimap() {__table_.rehash(193);} explicit hash_multimap(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); template hash_multimap(_InputIterator __first, _InputIterator __last); template hash_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); template hash_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); hash_multimap(const hash_multimap& __u); _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const {return allocator_type(__table_.__node_alloc());} _LIBCPP_INLINE_VISIBILITY bool empty() const {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const {return __table_.size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const {return __table_.max_size();} _LIBCPP_INLINE_VISIBILITY iterator begin() {return __table_.begin();} _LIBCPP_INLINE_VISIBILITY iterator end() {return __table_.end();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __table_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x);} template _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); _LIBCPP_INLINE_VISIBILITY void erase(const_iterator __p) {__table_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} _LIBCPP_INLINE_VISIBILITY void erase(const_iterator __first, const_iterator __last) {__table_.erase(__first.__i_, __last.__i_);} _LIBCPP_INLINE_VISIBILITY void clear() {__table_.clear();} _LIBCPP_INLINE_VISIBILITY void swap(hash_multimap& __u) {__table_.swap(__u.__table_);} _LIBCPP_INLINE_VISIBILITY hasher hash_funct() const {return __table_.hash_function().hash_function();} _LIBCPP_INLINE_VISIBILITY key_equal key_eq() const {return __table_.key_eq().key_eq();} _LIBCPP_INLINE_VISIBILITY iterator find(const key_type& __k) {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} _LIBCPP_INLINE_VISIBILITY std::pair equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY std::pair equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY size_type bucket_count() const {return __table_.bucket_count();} _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const {return __table_.max_bucket_count();} _LIBCPP_INLINE_VISIBILITY size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {__table_.rehash(__n);} }; template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { __table_.rehash(__n); } template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { __table_.rehash(__n); } template template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( _InputIterator __first, _InputIterator __last) { __table_.rehash(193); insert(__first, __last); } template template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { __table_.rehash(__n); insert(__first, __last); } template template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { __table_.rehash(__n); insert(__first, __last); } template hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( const hash_multimap& __u) : __table_(__u.__table_) { __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } template template inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) { for (; __first != __last; ++__first) __table_.__insert_multi(*__first); } template inline _LIBCPP_INLINE_VISIBILITY void swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { __x.swap(__y); } template bool operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { if (__x.size() != __y.size()) return false; typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator; typedef std::pair _EqRng; for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) { _EqRng __xeq = __x.equal_range(__i->first); _EqRng __yeq = __y.equal_range(__i->first); if (_VSTD::distance(__xeq.first, __xeq.second) != _VSTD::distance(__yeq.first, __yeq.second) || !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) return false; __i = __xeq.second; } return true; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) { return !(__x == __y); } } // __gnu_cxx #endif // _LIBCPP_HASH_MAP Index: stable/12/contrib/llvm-project/libcxx/include/random =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/random (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/random (revision 356466) @@ -1,6746 +1,6748 @@ // -*- C++ -*- //===--------------------------- random -----------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_RANDOM #define _LIBCPP_RANDOM /* random synopsis #include namespace std { // Engines template class linear_congruential_engine { public: // types typedef UIntType result_type; // engine characteristics static constexpr result_type multiplier = a; static constexpr result_type increment = c; static constexpr result_type modulus = m; static constexpr result_type min() { return c == 0u ? 1u: 0u;} static constexpr result_type max() { return m - 1u;} static constexpr result_type default_seed = 1u; // constructors and seeding functions explicit linear_congruential_engine(result_type s = default_seed); template explicit linear_congruential_engine(Sseq& q); void seed(result_type s = default_seed); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); }; template bool operator==(const linear_congruential_engine& x, const linear_congruential_engine& y); template bool operator!=(const linear_congruential_engine& x, const linear_congruential_engine& y); template basic_ostream& operator<<(basic_ostream& os, const linear_congruential_engine& x); template basic_istream& operator>>(basic_istream& is, linear_congruential_engine& x); template class mersenne_twister_engine { public: // types typedef UIntType result_type; // engine characteristics static constexpr size_t word_size = w; static constexpr size_t state_size = n; static constexpr size_t shift_size = m; static constexpr size_t mask_bits = r; static constexpr result_type xor_mask = a; static constexpr size_t tempering_u = u; static constexpr result_type tempering_d = d; static constexpr size_t tempering_s = s; static constexpr result_type tempering_b = b; static constexpr size_t tempering_t = t; static constexpr result_type tempering_c = c; static constexpr size_t tempering_l = l; static constexpr result_type initialization_multiplier = f; static constexpr result_type min () { return 0; } static constexpr result_type max() { return 2^w - 1; } static constexpr result_type default_seed = 5489u; // constructors and seeding functions explicit mersenne_twister_engine(result_type value = default_seed); template explicit mersenne_twister_engine(Sseq& q); void seed(result_type value = default_seed); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); }; template bool operator==( const mersenne_twister_engine& x, const mersenne_twister_engine& y); template bool operator!=( const mersenne_twister_engine& x, const mersenne_twister_engine& y); template basic_ostream& operator<<(basic_ostream& os, const mersenne_twister_engine& x); template basic_istream& operator>>(basic_istream& is, mersenne_twister_engine& x); template class subtract_with_carry_engine { public: // types typedef UIntType result_type; // engine characteristics static constexpr size_t word_size = w; static constexpr size_t short_lag = s; static constexpr size_t long_lag = r; static constexpr result_type min() { return 0; } static constexpr result_type max() { return m-1; } static constexpr result_type default_seed = 19780503u; // constructors and seeding functions explicit subtract_with_carry_engine(result_type value = default_seed); template explicit subtract_with_carry_engine(Sseq& q); void seed(result_type value = default_seed); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); }; template bool operator==( const subtract_with_carry_engine& x, const subtract_with_carry_engine& y); template bool operator!=( const subtract_with_carry_engine& x, const subtract_with_carry_engine& y); template basic_ostream& operator<<(basic_ostream& os, const subtract_with_carry_engine& x); template basic_istream& operator>>(basic_istream& is, subtract_with_carry_engine& x); template class discard_block_engine { public: // types typedef typename Engine::result_type result_type; // engine characteristics static constexpr size_t block_size = p; static constexpr size_t used_block = r; static constexpr result_type min() { return Engine::min(); } static constexpr result_type max() { return Engine::max(); } // constructors and seeding functions discard_block_engine(); explicit discard_block_engine(const Engine& e); explicit discard_block_engine(Engine&& e); explicit discard_block_engine(result_type s); template explicit discard_block_engine(Sseq& q); void seed(); void seed(result_type s); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); // property functions const Engine& base() const noexcept; }; template bool operator==( const discard_block_engine& x, const discard_block_engine& y); template bool operator!=( const discard_block_engine& x, const discard_block_engine& y); template basic_ostream& operator<<(basic_ostream& os, const discard_block_engine& x); template basic_istream& operator>>(basic_istream& is, discard_block_engine& x); template class independent_bits_engine { public: // types typedef UIntType result_type; // engine characteristics static constexpr result_type min() { return 0; } static constexpr result_type max() { return 2^w - 1; } // constructors and seeding functions independent_bits_engine(); explicit independent_bits_engine(const Engine& e); explicit independent_bits_engine(Engine&& e); explicit independent_bits_engine(result_type s); template explicit independent_bits_engine(Sseq& q); void seed(); void seed(result_type s); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); // property functions const Engine& base() const noexcept; }; template bool operator==( const independent_bits_engine& x, const independent_bits_engine& y); template bool operator!=( const independent_bits_engine& x, const independent_bits_engine& y); template basic_ostream& operator<<(basic_ostream& os, const independent_bits_engine& x); template basic_istream& operator>>(basic_istream& is, independent_bits_engine& x); template class shuffle_order_engine { public: // types typedef typename Engine::result_type result_type; // engine characteristics static constexpr size_t table_size = k; static constexpr result_type min() { return Engine::min; } static constexpr result_type max() { return Engine::max; } // constructors and seeding functions shuffle_order_engine(); explicit shuffle_order_engine(const Engine& e); explicit shuffle_order_engine(Engine&& e); explicit shuffle_order_engine(result_type s); template explicit shuffle_order_engine(Sseq& q); void seed(); void seed(result_type s); template void seed(Sseq& q); // generating functions result_type operator()(); void discard(unsigned long long z); // property functions const Engine& base() const noexcept; }; template bool operator==( const shuffle_order_engine& x, const shuffle_order_engine& y); template bool operator!=( const shuffle_order_engine& x, const shuffle_order_engine& y); template basic_ostream& operator<<(basic_ostream& os, const shuffle_order_engine& x); template basic_istream& operator>>(basic_istream& is, shuffle_order_engine& x); typedef linear_congruential_engine minstd_rand0; typedef linear_congruential_engine minstd_rand; typedef mersenne_twister_engine mt19937; typedef mersenne_twister_engine mt19937_64; typedef subtract_with_carry_engine ranlux24_base; typedef subtract_with_carry_engine ranlux48_base; typedef discard_block_engine ranlux24; typedef discard_block_engine ranlux48; typedef shuffle_order_engine knuth_b; typedef minstd_rand default_random_engine; // Generators class random_device { public: // types typedef unsigned int result_type; // generator characteristics static constexpr result_type min() { return numeric_limits::min(); } static constexpr result_type max() { return numeric_limits::max(); } // constructors explicit random_device(const string& token = "/dev/urandom"); // generating functions result_type operator()(); // property functions double entropy() const noexcept; // no copy functions random_device(const random_device& ) = delete; void operator=(const random_device& ) = delete; }; // Utilities class seed_seq { public: // types typedef uint_least32_t result_type; // constructors seed_seq(); template seed_seq(initializer_list il); template seed_seq(InputIterator begin, InputIterator end); // generating functions template void generate(RandomAccessIterator begin, RandomAccessIterator end); // property functions size_t size() const; template void param(OutputIterator dest) const; // no copy functions seed_seq(const seed_seq&) = delete; void operator=(const seed_seq& ) = delete; }; template RealType generate_canonical(URNG& g); // Distributions template class uniform_int_distribution { public: // types typedef IntType result_type; class param_type { public: typedef uniform_int_distribution distribution_type; explicit param_type(IntType a = 0, IntType b = numeric_limits::max()); result_type a() const; result_type b() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits::max()); explicit uniform_int_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type a() const; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y); friend bool operator!=(const uniform_int_distribution& x, const uniform_int_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const uniform_int_distribution& x); template friend basic_istream& operator>>(basic_istream& is, uniform_int_distribution& x); }; template class uniform_real_distribution { public: // types typedef RealType result_type; class param_type { public: typedef uniform_real_distribution distribution_type; explicit param_type(RealType a = 0, RealType b = 1); result_type a() const; result_type b() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); explicit uniform_real_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type a() const; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const uniform_real_distribution& x, const uniform_real_distribution& y); friend bool operator!=(const uniform_real_distribution& x, const uniform_real_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const uniform_real_distribution& x); template friend basic_istream& operator>>(basic_istream& is, uniform_real_distribution& x); }; class bernoulli_distribution { public: // types typedef bool result_type; class param_type { public: typedef bernoulli_distribution distribution_type; explicit param_type(double p = 0.5); double p() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit bernoulli_distribution(double p = 0.5); explicit bernoulli_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y); friend bool operator!=(const bernoulli_distribution& x, const bernoulli_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const bernoulli_distribution& x); template friend basic_istream& operator>>(basic_istream& is, bernoulli_distribution& x); }; template class binomial_distribution { public: // types typedef IntType result_type; class param_type { public: typedef binomial_distribution distribution_type; explicit param_type(IntType t = 1, double p = 0.5); IntType t() const; double p() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit binomial_distribution(IntType t = 1, double p = 0.5); explicit binomial_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions IntType t() const; double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const binomial_distribution& x, const binomial_distribution& y); friend bool operator!=(const binomial_distribution& x, const binomial_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const binomial_distribution& x); template friend basic_istream& operator>>(basic_istream& is, binomial_distribution& x); }; template class geometric_distribution { public: // types typedef IntType result_type; class param_type { public: typedef geometric_distribution distribution_type; explicit param_type(double p = 0.5); double p() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit geometric_distribution(double p = 0.5); explicit geometric_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const geometric_distribution& x, const geometric_distribution& y); friend bool operator!=(const geometric_distribution& x, const geometric_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const geometric_distribution& x); template friend basic_istream& operator>>(basic_istream& is, geometric_distribution& x); }; template class negative_binomial_distribution { public: // types typedef IntType result_type; class param_type { public: typedef negative_binomial_distribution distribution_type; explicit param_type(result_type k = 1, double p = 0.5); result_type k() const; double p() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); explicit negative_binomial_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type k() const; double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const negative_binomial_distribution& x, const negative_binomial_distribution& y); friend bool operator!=(const negative_binomial_distribution& x, const negative_binomial_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const negative_binomial_distribution& x); template friend basic_istream& operator>>(basic_istream& is, negative_binomial_distribution& x); }; template class poisson_distribution { public: // types typedef IntType result_type; class param_type { public: typedef poisson_distribution distribution_type; explicit param_type(double mean = 1.0); double mean() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit poisson_distribution(double mean = 1.0); explicit poisson_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions double mean() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const poisson_distribution& x, const poisson_distribution& y); friend bool operator!=(const poisson_distribution& x, const poisson_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const poisson_distribution& x); template friend basic_istream& operator>>(basic_istream& is, poisson_distribution& x); }; template class exponential_distribution { public: // types typedef RealType result_type; class param_type { public: typedef exponential_distribution distribution_type; explicit param_type(result_type lambda = 1.0); result_type lambda() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit exponential_distribution(result_type lambda = 1.0); explicit exponential_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type lambda() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const exponential_distribution& x, const exponential_distribution& y); friend bool operator!=(const exponential_distribution& x, const exponential_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const exponential_distribution& x); template friend basic_istream& operator>>(basic_istream& is, exponential_distribution& x); }; template class gamma_distribution { public: // types typedef RealType result_type; class param_type { public: typedef gamma_distribution distribution_type; explicit param_type(result_type alpha = 1, result_type beta = 1); result_type alpha() const; result_type beta() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); explicit gamma_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type alpha() const; result_type beta() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const gamma_distribution& x, const gamma_distribution& y); friend bool operator!=(const gamma_distribution& x, const gamma_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const gamma_distribution& x); template friend basic_istream& operator>>(basic_istream& is, gamma_distribution& x); }; template class weibull_distribution { public: // types typedef RealType result_type; class param_type { public: typedef weibull_distribution distribution_type; explicit param_type(result_type alpha = 1, result_type beta = 1); result_type a() const; result_type b() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit weibull_distribution(result_type a = 1, result_type b = 1); explicit weibull_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type a() const; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const weibull_distribution& x, const weibull_distribution& y); friend bool operator!=(const weibull_distribution& x, const weibull_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const weibull_distribution& x); template friend basic_istream& operator>>(basic_istream& is, weibull_distribution& x); }; template class extreme_value_distribution { public: // types typedef RealType result_type; class param_type { public: typedef extreme_value_distribution distribution_type; explicit param_type(result_type a = 0, result_type b = 1); result_type a() const; result_type b() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit extreme_value_distribution(result_type a = 0, result_type b = 1); explicit extreme_value_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type a() const; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const extreme_value_distribution& x, const extreme_value_distribution& y); friend bool operator!=(const extreme_value_distribution& x, const extreme_value_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const extreme_value_distribution& x); template friend basic_istream& operator>>(basic_istream& is, extreme_value_distribution& x); }; template class normal_distribution { public: // types typedef RealType result_type; class param_type { public: typedef normal_distribution distribution_type; explicit param_type(result_type mean = 0, result_type stddev = 1); result_type mean() const; result_type stddev() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions explicit normal_distribution(result_type mean = 0, result_type stddev = 1); explicit normal_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type mean() const; result_type stddev() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const normal_distribution& x, const normal_distribution& y); friend bool operator!=(const normal_distribution& x, const normal_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const normal_distribution& x); template friend basic_istream& operator>>(basic_istream& is, normal_distribution& x); }; template class lognormal_distribution { public: // types typedef RealType result_type; class param_type { public: typedef lognormal_distribution distribution_type; explicit param_type(result_type m = 0, result_type s = 1); result_type m() const; result_type s() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit lognormal_distribution(result_type m = 0, result_type s = 1); explicit lognormal_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type m() const; result_type s() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y); friend bool operator!=(const lognormal_distribution& x, const lognormal_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const lognormal_distribution& x); template friend basic_istream& operator>>(basic_istream& is, lognormal_distribution& x); }; template class chi_squared_distribution { public: // types typedef RealType result_type; class param_type { public: typedef chi_squared_distribution distribution_type; explicit param_type(result_type n = 1); result_type n() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit chi_squared_distribution(result_type n = 1); explicit chi_squared_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y); friend bool operator!=(const chi_squared_distribution& x, const chi_squared_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const chi_squared_distribution& x); template friend basic_istream& operator>>(basic_istream& is, chi_squared_distribution& x); }; template class cauchy_distribution { public: // types typedef RealType result_type; class param_type { public: typedef cauchy_distribution distribution_type; explicit param_type(result_type a = 0, result_type b = 1); result_type a() const; result_type b() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit cauchy_distribution(result_type a = 0, result_type b = 1); explicit cauchy_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type a() const; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y); friend bool operator!=(const cauchy_distribution& x, const cauchy_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const cauchy_distribution& x); template friend basic_istream& operator>>(basic_istream& is, cauchy_distribution& x); }; template class fisher_f_distribution { public: // types typedef RealType result_type; class param_type { public: typedef fisher_f_distribution distribution_type; explicit param_type(result_type m = 1, result_type n = 1); result_type m() const; result_type n() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit fisher_f_distribution(result_type m = 1, result_type n = 1); explicit fisher_f_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type m() const; result_type n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y); friend bool operator!=(const fisher_f_distribution& x, const fisher_f_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const fisher_f_distribution& x); template friend basic_istream& operator>>(basic_istream& is, fisher_f_distribution& x); }; template class student_t_distribution { public: // types typedef RealType result_type; class param_type { public: typedef student_t_distribution distribution_type; explicit param_type(result_type n = 1); result_type n() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions explicit student_t_distribution(result_type n = 1); explicit student_t_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions result_type n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const student_t_distribution& x, const student_t_distribution& y); friend bool operator!=(const student_t_distribution& x, const student_t_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const student_t_distribution& x); template friend basic_istream& operator>>(basic_istream& is, student_t_distribution& x); }; template class discrete_distribution { public: // types typedef IntType result_type; class param_type { public: typedef discrete_distribution distribution_type; param_type(); template param_type(InputIterator firstW, InputIterator lastW); param_type(initializer_list wl); template param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); vector probabilities() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions discrete_distribution(); template discrete_distribution(InputIterator firstW, InputIterator lastW); discrete_distribution(initializer_list wl); template discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw); explicit discrete_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions vector probabilities() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const discrete_distribution& x, const discrete_distribution& y); friend bool operator!=(const discrete_distribution& x, const discrete_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const discrete_distribution& x); template friend basic_istream& operator>>(basic_istream& is, discrete_distribution& x); }; template class piecewise_constant_distribution { // types typedef RealType result_type; class param_type { public: typedef piecewise_constant_distribution distribution_type; param_type(); template param_type(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template param_type(initializer_list bl, UnaryOperation fw); template param_type(size_t nw, result_type xmin, result_type xmax, UnaryOperation fw); vector intervals() const; vector densities() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions piecewise_constant_distribution(); template piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template piecewise_constant_distribution(initializer_list bl, UnaryOperation fw); template piecewise_constant_distribution(size_t nw, result_type xmin, result_type xmax, UnaryOperation fw); explicit piecewise_constant_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions vector intervals() const; vector densities() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); friend bool operator!=(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const piecewise_constant_distribution& x); template friend basic_istream& operator>>(basic_istream& is, piecewise_constant_distribution& x); }; template class piecewise_linear_distribution { // types typedef RealType result_type; class param_type { public: typedef piecewise_linear_distribution distribution_type; param_type(); template param_type(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template param_type(initializer_list bl, UnaryOperation fw); template param_type(size_t nw, result_type xmin, result_type xmax, UnaryOperation fw); vector intervals() const; vector densities() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructor and reset functions piecewise_linear_distribution(); template piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template piecewise_linear_distribution(initializer_list bl, UnaryOperation fw); template piecewise_linear_distribution(size_t nw, result_type xmin, result_type xmax, UnaryOperation fw); explicit piecewise_linear_distribution(const param_type& parm); void reset(); // generating functions template result_type operator()(URNG& g); template result_type operator()(URNG& g, const param_type& parm); // property functions vector intervals() const; vector densities() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; friend bool operator==(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); friend bool operator!=(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); template friend basic_ostream& operator<<(basic_ostream& os, const piecewise_linear_distribution& x); template friend basic_istream& operator>>(basic_istream& is, piecewise_linear_distribution& x); }; } // std */ #include <__config> #include #include #include #include #include #include #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD // __is_seed_sequence template struct __is_seed_sequence { static _LIBCPP_CONSTEXPR const bool value = !is_convertible<_Sseq, typename _Engine::result_type>::value && !is_same::type, _Engine>::value; }; // linear_congruential_engine template (_Mp-__c)/__a)> struct __lce_ta; // 64 template struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> { typedef unsigned long long result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { // Schrage's algorithm const result_type __q = __m / __a; const result_type __r = __m % __a; const result_type __t0 = __a * (__x % __q); const result_type __t1 = __r * (__x / __q); __x = __t0 + (__t0 < __t1) * __m - __t1; __x += __c - (__x >= __m - __c) * __m; return __x; } }; template struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> { typedef unsigned long long result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { // Schrage's algorithm const result_type __q = __m / __a; const result_type __r = __m % __a; const result_type __t0 = __a * (__x % __q); const result_type __t1 = __r * (__x / __q); __x = __t0 + (__t0 < __t1) * __m - __t1; return __x; } }; template struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> { typedef unsigned long long result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { return (__a * __x + __c) % __m; } }; template struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> { typedef unsigned long long result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { return __a * __x + __c; } }; // 32 template struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> { typedef unsigned result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { const result_type __a = static_cast(_Ap); const result_type __c = static_cast(_Cp); const result_type __m = static_cast(_Mp); // Schrage's algorithm const result_type __q = __m / __a; const result_type __r = __m % __a; const result_type __t0 = __a * (__x % __q); const result_type __t1 = __r * (__x / __q); __x = __t0 + (__t0 < __t1) * __m - __t1; __x += __c - (__x >= __m - __c) * __m; return __x; } }; template struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> { typedef unsigned result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { const result_type __a = static_cast(_Ap); const result_type __m = static_cast(_Mp); // Schrage's algorithm const result_type __q = __m / __a; const result_type __r = __m % __a; const result_type __t0 = __a * (__x % __q); const result_type __t1 = __r * (__x / __q); __x = __t0 + (__t0 < __t1) * __m - __t1; return __x; } }; template struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> { typedef unsigned result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { const result_type __a = static_cast(_Ap); const result_type __c = static_cast(_Cp); const result_type __m = static_cast(_Mp); return (__a * __x + __c) % __m; } }; template struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> { typedef unsigned result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { const result_type __a = static_cast(_Ap); const result_type __c = static_cast(_Cp); return __a * __x + __c; } }; // 16 template struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> { typedef unsigned short result_type; _LIBCPP_INLINE_VISIBILITY static result_type next(result_type __x) { return static_cast(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); } }; template class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; template _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); template class _LIBCPP_TEMPLATE_VIS linear_congruential_engine { public: // types typedef _UIntType result_type; private: result_type __x_; static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); public: static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); // engine characteristics static _LIBCPP_CONSTEXPR const result_type multiplier = __a; static _LIBCPP_CONSTEXPR const result_type increment = __c; static _LIBCPP_CONSTEXPR const result_type modulus = __m; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() {return _Min;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() {return _Max;} static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY explicit linear_congruential_engine(result_type __s = default_seed) {seed(__s);} template _LIBCPP_INLINE_VISIBILITY explicit linear_congruential_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) {seed(__q);} _LIBCPP_INLINE_VISIBILITY void seed(result_type __s = default_seed) {seed(integral_constant(), integral_constant(), __s);} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, linear_congruential_engine>::value, void >::type seed(_Sseq& __q) {__seed(__q, integral_constant 0x100000000ull))>());} // generating functions _LIBCPP_INLINE_VISIBILITY result_type operator()() {return __x_ = static_cast(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const linear_congruential_engine& __x, const linear_congruential_engine& __y) {return __x.__x_ == __y.__x_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const linear_congruential_engine& __x, const linear_congruential_engine& __y) {return !(__x == __y);} private: _LIBCPP_INLINE_VISIBILITY void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} _LIBCPP_INLINE_VISIBILITY void seed(true_type, false_type, result_type __s) {__x_ = __s;} _LIBCPP_INLINE_VISIBILITY void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? 1 : __s % __m;} _LIBCPP_INLINE_VISIBILITY void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} template void __seed(_Sseq& __q, integral_constant); template void __seed(_Sseq& __q, integral_constant); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); }; template _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; template _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type linear_congruential_engine<_UIntType, __a, __c, __m>::increment; template _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; template _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; template template void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 1; uint32_t __ar[__k+3]; __q.generate(__ar, __ar + __k + 3); result_type __s = static_cast(__ar[3] % __m); __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; } template template void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 2; uint32_t __ar[__k+3]; __q.generate(__ar, __ar + __k + 3); result_type __s = static_cast((__ar[3] + ((uint64_t)__ar[4] << 32)) % __m); __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; } template inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); __os.fill(__os.widen(' ')); return __os << __x.__x_; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_UIntType, __a, __c, __m>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); _UIntType __t; __is >> __t; if (!__is.fail()) __x.__x_ = __t; return __is; } typedef linear_congruential_engine minstd_rand0; typedef linear_congruential_engine minstd_rand; typedef minstd_rand default_random_engine; // mersenne_twister_engine template class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; template bool operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template _LIBCPP_INLINE_VISIBILITY bool operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine { public: // types typedef _UIntType result_type; private: result_type __x_[__n]; size_t __i_; static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits::digits; static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); public: static _LIBCPP_CONSTEXPR const result_type _Min = 0; static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1); static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); // engine characteristics static _LIBCPP_CONSTEXPR const size_t word_size = __w; static _LIBCPP_CONSTEXPR const size_t state_size = __n; static _LIBCPP_CONSTEXPR const size_t shift_size = __m; static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Min; } _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY explicit mersenne_twister_engine(result_type __sd = default_seed) {seed(__sd);} template _LIBCPP_INLINE_VISIBILITY explicit mersenne_twister_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) {seed(__q);} void seed(result_type __sd = default_seed); template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, void >::type seed(_Sseq& __q) {__seed(__q, integral_constant());} // generating functions result_type operator()(); _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} template friend bool operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template friend bool operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); private: template void __seed(_Sseq& __q, integral_constant); template void __seed(_Sseq& __q, integral_constant); template _LIBCPP_INLINE_VISIBILITY static typename enable_if < __count < __w, result_type >::type __lshift(result_type __x) {return (__x << __count) & _Max;} template _LIBCPP_INLINE_VISIBILITY static typename enable_if < (__count >= __w), result_type >::type __lshift(result_type) {return result_type(0);} template _LIBCPP_INLINE_VISIBILITY static typename enable_if < __count < _Dt, result_type >::type __rshift(result_type __x) {return __x >> __count;} template _LIBCPP_INLINE_VISIBILITY static typename enable_if < (__count >= _Dt), result_type >::type __rshift(result_type) {return result_type(0);} }; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; template _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; template _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; template void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(result_type __sd) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2 __x_[0] = __sd & _Max; for (size_t __i = 1; __i < __n; ++__i) __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; __i_ = 0; } template template void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 1; uint32_t __ar[__n * __k]; __q.generate(__ar, __ar + __n * __k); for (size_t __i = 0; __i < __n; ++__i) __x_[__i] = static_cast(__ar[__i] & _Max); const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); __i_ = 0; if ((__x_[0] & ~__mask) == 0) { for (size_t __i = 1; __i < __n; ++__i) if (__x_[__i] != 0) return; __x_[0] = result_type(1) << (__w - 1); } } template template void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 2; uint32_t __ar[__n * __k]; __q.generate(__ar, __ar + __n * __k); for (size_t __i = 0; __i < __n; ++__i) __x_[__i] = static_cast( (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); __i_ = 0; if ((__x_[0] & ~__mask) == 0) { for (size_t __i = 1; __i < __n; ++__i) if (__x_[__i] != 0) return; __x_[0] = result_type(1) << (__w - 1); } } template _UIntType mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() { const size_t __j = (__i_ + 1) % __n; const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1); const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); const size_t __k = (__i_ + __m) % __n; __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); __i_ = __j; __z ^= __lshift<__s>(__z) & __b; __z ^= __lshift<__t>(__z) & __c; return __z ^ __rshift<__l>(__z); } template bool operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) { if (__x.__i_ == __y.__i_) return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); if (__x.__i_ == 0 || __y.__i_ == 0) { size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, __y.__x_ + __y.__i_)) return false; if (__x.__i_ == 0) return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); } if (__x.__i_ < __y.__i_) { size_t __j = _Np - __y.__i_; if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), __y.__x_ + __y.__i_)) return false; if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, __y.__x_)) return false; return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, __y.__x_ + (_Np - (__x.__i_ + __j))); } size_t __j = _Np - __x.__i_; if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), __x.__x_ + __x.__i_)) return false; if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, __x.__x_)) return false; return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, __x.__x_ + (_Np - (__y.__i_ + __j))); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) { return !(__x == __y); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.__x_[__x.__i_]; for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) __os << __sp << __x.__x_[__j]; for (size_t __j = 0; __j < __x.__i_; ++__j) __os << __sp << __x.__x_[__j]; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); _UInt __t[_Np]; for (size_t __i = 0; __i < _Np; ++__i) __is >> __t[__i]; if (!__is.fail()) { for (size_t __i = 0; __i < _Np; ++__i) __x.__x_[__i] = __t[__i]; __x.__i_ = 0; } return __is; } typedef mersenne_twister_engine mt19937; typedef mersenne_twister_engine mt19937_64; // subtract_with_carry_engine template class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; template bool operator==( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template _LIBCPP_INLINE_VISIBILITY bool operator!=( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine { public: // types typedef _UIntType result_type; private: result_type __x_[__r]; result_type __c_; size_t __i_; static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits::digits; static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); public: static _LIBCPP_CONSTEXPR const result_type _Min = 0; static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1); static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); // engine characteristics static _LIBCPP_CONSTEXPR const size_t word_size = __w; static _LIBCPP_CONSTEXPR const size_t short_lag = __s; static _LIBCPP_CONSTEXPR const size_t long_lag = __r; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Min; } _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY explicit subtract_with_carry_engine(result_type __sd = default_seed) {seed(__sd);} template _LIBCPP_INLINE_VISIBILITY explicit subtract_with_carry_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) {seed(__q);} _LIBCPP_INLINE_VISIBILITY void seed(result_type __sd = default_seed) {seed(__sd, integral_constant());} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, void >::type seed(_Sseq& __q) {__seed(__q, integral_constant());} // generating functions result_type operator()(); _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} template friend bool operator==( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template friend bool operator!=( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); private: void seed(result_type __sd, integral_constant); void seed(result_type __sd, integral_constant); template void __seed(_Sseq& __q, integral_constant); template void __seed(_Sseq& __q, integral_constant); }; template _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; template _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; template _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; template _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; template void subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, integral_constant) { linear_congruential_engine __e(__sd == 0u ? default_seed : __sd); for (size_t __i = 0; __i < __r; ++__i) __x_[__i] = static_cast(__e() & _Max); __c_ = __x_[__r-1] == 0; __i_ = 0; } template void subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, integral_constant) { linear_congruential_engine __e(__sd == 0u ? default_seed : __sd); for (size_t __i = 0; __i < __r; ++__i) { result_type __e0 = __e(); __x_[__i] = static_cast( (__e0 + ((uint64_t)__e() << 32)) & _Max); } __c_ = __x_[__r-1] == 0; __i_ = 0; } template template void subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 1; uint32_t __ar[__r * __k]; __q.generate(__ar, __ar + __r * __k); for (size_t __i = 0; __i < __r; ++__i) __x_[__i] = static_cast(__ar[__i] & _Max); __c_ = __x_[__r-1] == 0; __i_ = 0; } template template void subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, integral_constant) { const unsigned __k = 2; uint32_t __ar[__r * __k]; __q.generate(__ar, __ar + __r * __k); for (size_t __i = 0; __i < __r; ++__i) __x_[__i] = static_cast( (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); __c_ = __x_[__r-1] == 0; __i_ = 0; } template _UIntType subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() { const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; result_type& __xr = __x_[__i_]; result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; __xr = (__xs - __xr - __c_) & _Max; __c_ = __new_c; __i_ = (__i_ + 1) % __r; return __xr; } template bool operator==( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) { if (__x.__c_ != __y.__c_) return false; if (__x.__i_ == __y.__i_) return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); if (__x.__i_ == 0 || __y.__i_ == 0) { size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, __y.__x_ + __y.__i_)) return false; if (__x.__i_ == 0) return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); } if (__x.__i_ < __y.__i_) { size_t __j = _Rp - __y.__i_; if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), __y.__x_ + __y.__i_)) return false; if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, __y.__x_)) return false; return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, __y.__x_ + (_Rp - (__x.__i_ + __j))); } size_t __j = _Rp - __x.__i_; if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), __x.__x_ + __x.__i_)) return false; if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, __x.__x_)) return false; return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, __x.__x_ + (_Rp - (__y.__i_ + __j))); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=( const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) { return !(__x == __y); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.__x_[__x.__i_]; for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) __os << __sp << __x.__x_[__j]; for (size_t __j = 0; __j < __x.__i_; ++__j) __os << __sp << __x.__x_[__j]; __os << __sp << __x.__c_; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); _UInt __t[_Rp+1]; for (size_t __i = 0; __i < _Rp+1; ++__i) __is >> __t[__i]; if (!__is.fail()) { for (size_t __i = 0; __i < _Rp; ++__i) __x.__x_[__i] = __t[__i]; __x.__c_ = __t[_Rp]; __x.__i_ = 0; } return __is; } typedef subtract_with_carry_engine ranlux24_base; typedef subtract_with_carry_engine ranlux48_base; // discard_block_engine template class _LIBCPP_TEMPLATE_VIS discard_block_engine { _Engine __e_; int __n_; static_assert( 0 < __r, "discard_block_engine invalid parameters"); static_assert(__r <= __p, "discard_block_engine invalid parameters"); static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); public: // types typedef typename _Engine::result_type result_type; // engine characteristics static _LIBCPP_CONSTEXPR const size_t block_size = __p; static _LIBCPP_CONSTEXPR const size_t used_block = __r; #ifdef _LIBCPP_CXX03_LANG static const result_type _Min = _Engine::_Min; static const result_type _Max = _Engine::_Max; #else static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); #endif _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY discard_block_engine() : __n_(0) {} _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(const _Engine& __e) : __e_(__e), __n_(0) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(_Engine&& __e) : __e_(_VSTD::move(__e)), __n_(0) {} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} template _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && !is_convertible<_Sseq, _Engine>::value>::type* = 0) : __e_(__q), __n_(0) {} _LIBCPP_INLINE_VISIBILITY void seed() {__e_.seed(); __n_ = 0;} _LIBCPP_INLINE_VISIBILITY void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, discard_block_engine>::value, void >::type seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} // generating functions result_type operator()(); _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} // property functions _LIBCPP_INLINE_VISIBILITY const _Engine& base() const _NOEXCEPT {return __e_;} template friend bool operator==( const discard_block_engine<_Eng, _Pp, _Rp>& __x, const discard_block_engine<_Eng, _Pp, _Rp>& __y); template friend bool operator!=( const discard_block_engine<_Eng, _Pp, _Rp>& __x, const discard_block_engine<_Eng, _Pp, _Rp>& __y); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const discard_block_engine<_Eng, _Pp, _Rp>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, discard_block_engine<_Eng, _Pp, _Rp>& __x); }; template _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; template _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; template typename discard_block_engine<_Engine, __p, __r>::result_type discard_block_engine<_Engine, __p, __r>::operator()() { if (__n_ >= static_cast(__r)) { __e_.discard(__p - __r); __n_ = 0; } ++__n_; return __e_(); } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, const discard_block_engine<_Eng, _Pp, _Rp>& __y) { return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, const discard_block_engine<_Eng, _Pp, _Rp>& __y) { return !(__x == __y); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const discard_block_engine<_Eng, _Pp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.__e_ << __sp << __x.__n_; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, discard_block_engine<_Eng, _Pp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); _Eng __e; int __n; __is >> __e >> __n; if (!__is.fail()) { __x.__e_ = __e; __x.__n_ = __n; } return __is; } typedef discard_block_engine ranlux24; typedef discard_block_engine ranlux48; // independent_bits_engine template class _LIBCPP_TEMPLATE_VIS independent_bits_engine { template class __get_n { static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; public: static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; }; public: // types typedef _UIntType result_type; private: _Engine __e_; static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits::digits; static_assert( 0 < __w, "independent_bits_engine invalid parameters"); static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); typedef typename _Engine::result_type _Engine_result_type; typedef typename conditional < sizeof(_Engine_result_type) <= sizeof(result_type), result_type, _Engine_result_type >::type _Working_result_type; #ifdef _LIBCPP_CXX03_LANG static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + _Working_result_type(1); #else static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() + _Working_result_type(1); #endif static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : (_Rp >> __w0) << __w0; static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : (_Rp >> (__w0+1)) << (__w0+1); static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? _Engine_result_type(~0) >> (_EDt - __w0) : _Engine_result_type(0); static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : _Engine_result_type(~0); public: static _LIBCPP_CONSTEXPR const result_type _Min = 0; static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1); static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); // engine characteristics _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Min; } _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Max; } // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY independent_bits_engine() {} _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(const _Engine& __e) : __e_(__e) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(_Engine&& __e) : __e_(_VSTD::move(__e)) {} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} template _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && !is_convertible<_Sseq, _Engine>::value>::type* = 0) : __e_(__q) {} _LIBCPP_INLINE_VISIBILITY void seed() {__e_.seed();} _LIBCPP_INLINE_VISIBILITY void seed(result_type __sd) {__e_.seed(__sd);} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, independent_bits_engine>::value, void >::type seed(_Sseq& __q) {__e_.seed(__q);} // generating functions _LIBCPP_INLINE_VISIBILITY result_type operator()() {return __eval(integral_constant());} _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} // property functions _LIBCPP_INLINE_VISIBILITY const _Engine& base() const _NOEXCEPT {return __e_;} template friend bool operator==( const independent_bits_engine<_Eng, _Wp, _UInt>& __x, const independent_bits_engine<_Eng, _Wp, _UInt>& __y); template friend bool operator!=( const independent_bits_engine<_Eng, _Wp, _UInt>& __x, const independent_bits_engine<_Eng, _Wp, _UInt>& __y); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const independent_bits_engine<_Eng, _Wp, _UInt>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, independent_bits_engine<_Eng, _Wp, _UInt>& __x); private: _LIBCPP_INLINE_VISIBILITY result_type __eval(false_type); result_type __eval(true_type); template _LIBCPP_INLINE_VISIBILITY static typename enable_if < __count < _Dt, result_type >::type __lshift(result_type __x) {return __x << __count;} template _LIBCPP_INLINE_VISIBILITY static typename enable_if < (__count >= _Dt), result_type >::type __lshift(result_type) {return result_type(0);} }; template inline _UIntType independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) { return static_cast(__e_() & __mask0); } template _UIntType independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) { result_type _Sp = 0; for (size_t __k = 0; __k < __n0; ++__k) { _Engine_result_type __u; do { __u = __e_() - _Engine::min(); } while (__u >= __y0); _Sp = static_cast(__lshift<__w0>(_Sp) + (__u & __mask0)); } for (size_t __k = __n0; __k < __n; ++__k) { _Engine_result_type __u; do { __u = __e_() - _Engine::min(); } while (__u >= __y1); _Sp = static_cast(__lshift<__w0+1>(_Sp) + (__u & __mask1)); } return _Sp; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==( const independent_bits_engine<_Eng, _Wp, _UInt>& __x, const independent_bits_engine<_Eng, _Wp, _UInt>& __y) { return __x.base() == __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=( const independent_bits_engine<_Eng, _Wp, _UInt>& __x, const independent_bits_engine<_Eng, _Wp, _UInt>& __y) { return !(__x == __y); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const independent_bits_engine<_Eng, _Wp, _UInt>& __x) { return __os << __x.base(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, independent_bits_engine<_Eng, _Wp, _UInt>& __x) { _Eng __e; __is >> __e; if (!__is.fail()) __x.__e_ = __e; return __is; } // shuffle_order_engine template struct __ugcd { static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; }; template struct __ugcd<_Xp, 0> { static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; }; template class __uratio { static_assert(_Dp != 0, "__uratio divide by 0"); static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; public: static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; typedef __uratio type; }; template class _LIBCPP_TEMPLATE_VIS shuffle_order_engine { static_assert(0 < __k, "shuffle_order_engine invalid parameters"); public: // types typedef typename _Engine::result_type result_type; private: _Engine __e_; result_type _V_[__k]; result_type _Y_; public: // engine characteristics static _LIBCPP_CONSTEXPR const size_t table_size = __k; #ifdef _LIBCPP_CXX03_LANG static const result_type _Min = _Engine::_Min; static const result_type _Max = _Engine::_Max; #else static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); #endif static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Min; } _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Max; } static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; // constructors and seeding functions _LIBCPP_INLINE_VISIBILITY shuffle_order_engine() {__init();} _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(const _Engine& __e) : __e_(__e) {__init();} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(_Engine&& __e) : __e_(_VSTD::move(__e)) {__init();} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} template _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(_Sseq& __q, typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && !is_convertible<_Sseq, _Engine>::value>::type* = 0) : __e_(__q) {__init();} _LIBCPP_INLINE_VISIBILITY void seed() {__e_.seed(); __init();} _LIBCPP_INLINE_VISIBILITY void seed(result_type __sd) {__e_.seed(__sd); __init();} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_seed_sequence<_Sseq, shuffle_order_engine>::value, void >::type seed(_Sseq& __q) {__e_.seed(__q); __init();} // generating functions _LIBCPP_INLINE_VISIBILITY result_type operator()() {return __eval(integral_constant());} _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} // property functions _LIBCPP_INLINE_VISIBILITY const _Engine& base() const _NOEXCEPT {return __e_;} private: template friend bool operator==( const shuffle_order_engine<_Eng, _Kp>& __x, const shuffle_order_engine<_Eng, _Kp>& __y); template friend bool operator!=( const shuffle_order_engine<_Eng, _Kp>& __x, const shuffle_order_engine<_Eng, _Kp>& __y); template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const shuffle_order_engine<_Eng, _Kp>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, shuffle_order_engine<_Eng, _Kp>& __x); _LIBCPP_INLINE_VISIBILITY void __init() { for (size_t __i = 0; __i < __k; ++__i) _V_[__i] = __e_(); _Y_ = __e_(); } _LIBCPP_INLINE_VISIBILITY result_type __eval(false_type) {return __eval2(integral_constant());} _LIBCPP_INLINE_VISIBILITY result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} _LIBCPP_INLINE_VISIBILITY result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} _LIBCPP_INLINE_VISIBILITY result_type __eval2(true_type) {return __evalf<__k, 0>();} template _LIBCPP_INLINE_VISIBILITY typename enable_if < (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), result_type >::type __eval(__uratio<_Np, _Dp>) {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} template _LIBCPP_INLINE_VISIBILITY typename enable_if < __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), result_type >::type __eval(__uratio<_Np, _Dp>) { const size_t __j = static_cast(__uratio<_Np, _Dp>::num * (_Y_ - _Min) / __uratio<_Np, _Dp>::den); _Y_ = _V_[__j]; _V_[__j] = __e_(); return _Y_; } template _LIBCPP_INLINE_VISIBILITY result_type __evalf() { const double _Fp = __d == 0 ? __n / (2. * 0x8000000000000000ull) : __n / (double)__d; const size_t __j = static_cast(_Fp * (_Y_ - _Min)); _Y_ = _V_[__j]; _V_[__j] = __e_(); return _Y_; } }; template _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; template bool operator==( const shuffle_order_engine<_Eng, _Kp>& __x, const shuffle_order_engine<_Eng, _Kp>& __y) { return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && __x.__e_ == __y.__e_; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=( const shuffle_order_engine<_Eng, _Kp>& __x, const shuffle_order_engine<_Eng, _Kp>& __y) { return !(__x == __y); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const shuffle_order_engine<_Eng, _Kp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.__e_ << __sp << __x._V_[0]; for (size_t __i = 1; __i < _Kp; ++__i) __os << __sp << __x._V_[__i]; return __os << __sp << __x._Y_; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, shuffle_order_engine<_Eng, _Kp>& __x) { typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); _Eng __e; result_type _Vp[_Kp+1]; __is >> __e; for (size_t __i = 0; __i < _Kp+1; ++__i) __is >> _Vp[__i]; if (!__is.fail()) { __x.__e_ = __e; for (size_t __i = 0; __i < _Kp; ++__i) __x._V_[__i] = _Vp[__i]; __x._Y_ = _Vp[_Kp]; } return __is; } typedef shuffle_order_engine knuth_b; // random_device class _LIBCPP_TYPE_VIS random_device { #ifdef _LIBCPP_USING_DEV_RANDOM int __f_; #endif // defined(_LIBCPP_USING_DEV_RANDOM) public: // types typedef unsigned result_type; // generator characteristics static _LIBCPP_CONSTEXPR const result_type _Min = 0; static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type min() { return _Min;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR result_type max() { return _Max;} // constructors explicit random_device(const string& __token = "/dev/urandom"); ~random_device(); // generating functions result_type operator()(); // property functions double entropy() const _NOEXCEPT; private: // no copy functions random_device(const random_device&); // = delete; random_device& operator=(const random_device&); // = delete; }; // seed_seq class _LIBCPP_TEMPLATE_VIS seed_seq { public: // types typedef uint32_t result_type; private: vector __v_; template void init(_InputIterator __first, _InputIterator __last); public: // constructors _LIBCPP_INLINE_VISIBILITY seed_seq() _NOEXCEPT {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY seed_seq(_InputIterator __first, _InputIterator __last) {init(__first, __last);} // generating functions template void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); // property functions _LIBCPP_INLINE_VISIBILITY size_t size() const _NOEXCEPT {return __v_.size();} template _LIBCPP_INLINE_VISIBILITY void param(_OutputIterator __dest) const {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} private: // no copy functions seed_seq(const seed_seq&); // = delete; void operator=(const seed_seq&); // = delete; _LIBCPP_INLINE_VISIBILITY static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} }; template void seed_seq::init(_InputIterator __first, _InputIterator __last) { for (_InputIterator __s = __first; __s != __last; ++__s) __v_.push_back(*__s & 0xFFFFFFFF); } template void seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) { if (__first != __last) { _VSTD::fill(__first, __last, 0x8b8b8b8b); const size_t __n = static_cast(__last - __first); const size_t __s = __v_.size(); const size_t __t = (__n >= 623) ? 11 : (__n >= 68) ? 7 : (__n >= 39) ? 5 : (__n >= 7) ? 3 : (__n - 1) / 2; const size_t __p = (__n - __t) / 2; const size_t __q = __p + __t; const size_t __m = _VSTD::max(__s + 1, __n); // __k = 0; { result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] ^ __first[__n - 1]); __first[__p] += __r; __r += __s; __first[__q] += __r; __first[0] = __r; } for (size_t __k = 1; __k <= __s; ++__k) { const size_t __kmodn = __k % __n; const size_t __kpmodn = (__k + __p) % __n; result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[(__k - 1) % __n]); __first[__kpmodn] += __r; __r += __kmodn + __v_[__k-1]; __first[(__k + __q) % __n] += __r; __first[__kmodn] = __r; } for (size_t __k = __s + 1; __k < __m; ++__k) { const size_t __kmodn = __k % __n; const size_t __kpmodn = (__k + __p) % __n; result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] ^ __first[(__k - 1) % __n]); __first[__kpmodn] += __r; __r += __kmodn; __first[(__k + __q) % __n] += __r; __first[__kmodn] = __r; } for (size_t __k = __m; __k < __m + __n; ++__k) { const size_t __kmodn = __k % __n; const size_t __kpmodn = (__k + __p) % __n; result_type __r = 1566083941 * _Tp(__first[__kmodn] + __first[__kpmodn] + __first[(__k - 1) % __n]); __first[__kpmodn] ^= __r; __r -= __kmodn; __first[(__k + __q) % __n] ^= __r; __first[__kmodn] = __r; } } } // generate_canonical template _RealType generate_canonical(_URNG& __g) { const size_t _Dt = numeric_limits<_RealType>::digits; const size_t __b = _Dt < __bits ? _Dt : __bits; #ifdef _LIBCPP_CXX03_LANG const size_t __logR = __log2::value; #else const size_t __logR = __log2::value; #endif const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); _RealType __base = _Rp; _RealType _Sp = __g() - _URNG::min(); for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) _Sp += (__g() - _URNG::min()) * __base; return _Sp / __base; } // uniform_int_distribution // in template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const uniform_int_distribution<_IT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.a() << __sp << __x.b(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, uniform_int_distribution<_IT>& __x) { typedef uniform_int_distribution<_IT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __a; result_type __b; __is >> __a >> __b; if (!__is.fail()) __x.param(param_type(__a, __b)); return __is; } // uniform_real_distribution template class _LIBCPP_TEMPLATE_VIS uniform_real_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; public: typedef uniform_real_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} _LIBCPP_INLINE_VISIBILITY result_type a() const {return __a_;} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) : __p_(param_type(__a, __b)) {} _LIBCPP_INLINE_VISIBILITY explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type a() const {return __p_.a();} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __p_.b();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return a();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return b();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const uniform_real_distribution& __x, const uniform_real_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const uniform_real_distribution& __x, const uniform_real_distribution& __y) {return !(__x == __y);} }; template template inline typename uniform_real_distribution<_RealType>::result_type uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { return (__p.b() - __p.a()) * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) + __p.a(); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const uniform_real_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.a() << __sp << __x.b(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, uniform_real_distribution<_RT>& __x) { typedef uniform_real_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __a; result_type __b; __is >> __a >> __b; if (!__is.fail()) __x.param(param_type(__a, __b)); return __is; } // bernoulli_distribution class _LIBCPP_TEMPLATE_VIS bernoulli_distribution { public: // types typedef bool result_type; class _LIBCPP_TEMPLATE_VIS param_type { double __p_; public: typedef bernoulli_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(double __p = 0.5) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {} _LIBCPP_INLINE_VISIBILITY explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY double p() const {return __p_.p();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return false;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return true;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const bernoulli_distribution& __x, const bernoulli_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const bernoulli_distribution& __x, const bernoulli_distribution& __y) {return !(__x == __y);} }; template inline bernoulli_distribution::result_type bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) { uniform_real_distribution __gen; return __gen(__g) < __p.p(); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.p(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) { typedef bernoulli_distribution _Eng; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); double __p; __is >> __p; if (!__is.fail()) __x.param(param_type(__p)); return __is; } // binomial_distribution template class _LIBCPP_TEMPLATE_VIS binomial_distribution { public: // types typedef _IntType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __t_; double __p_; double __pr_; double __odds_ratio_; result_type __r0_; public: typedef binomial_distribution distribution_type; explicit param_type(result_type __t = 1, double __p = 0.5); _LIBCPP_INLINE_VISIBILITY result_type t() const {return __t_;} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} friend class binomial_distribution; }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit binomial_distribution(result_type __t = 1, double __p = 0.5) : __p_(param_type(__t, __p)) {} _LIBCPP_INLINE_VISIBILITY explicit binomial_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type t() const {return __p_.t();} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_.p();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return t();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const binomial_distribution& __x, const binomial_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const binomial_distribution& __x, const binomial_distribution& __y) {return !(__x == __y);} }; #ifndef _LIBCPP_MSVCRT extern "C" double lgamma_r(double, int *); #endif inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { #if defined(_LIBCPP_MSVCRT) return lgamma(__d); #else int __sign; return lgamma_r(__d, &__sign); #endif } template binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) : __t_(__t), __p_(__p) { if (0 < __p_ && __p_ < 1) { __r0_ = static_cast((__t_ + 1) * __p_); __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - __libcpp_lgamma(__r0_ + 1.) - __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + (__t_ - __r0_) * _VSTD::log(1 - __p_)); __odds_ratio_ = __p_ / (1 - __p_); } } // Reference: Kemp, C.D. (1986). `A modal method for generating binomial // variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. template template _IntType binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) { if (__pr.__t_ == 0 || __pr.__p_ == 0) return 0; if (__pr.__p_ == 1) return __pr.__t_; uniform_real_distribution __gen; double __u = __gen(__g) - __pr.__pr_; if (__u < 0) return __pr.__r0_; double __pu = __pr.__pr_; double __pd = __pu; result_type __ru = __pr.__r0_; result_type __rd = __ru; while (true) { if (__rd >= 1) { __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); __u -= __pd; if (__u < 0) return __rd - 1; } if ( __rd != 0 ) --__rd; ++__ru; if (__ru <= __pr.__t_) { __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; __u -= __pu; if (__u < 0) return __ru; } } } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const binomial_distribution<_IntType>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.t() << __sp << __x.p(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, binomial_distribution<_IntType>& __x) { typedef binomial_distribution<_IntType> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __t; double __p; __is >> __t >> __p; if (!__is.fail()) __x.param(param_type(__t, __p)); return __is; } // exponential_distribution template class _LIBCPP_TEMPLATE_VIS exponential_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __lambda_; public: typedef exponential_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} _LIBCPP_INLINE_VISIBILITY result_type lambda() const {return __lambda_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__lambda_ == __y.__lambda_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit exponential_distribution(result_type __lambda = 1) : __p_(param_type(__lambda)) {} _LIBCPP_INLINE_VISIBILITY explicit exponential_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type lambda() const {return __p_.lambda();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const exponential_distribution& __x, const exponential_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const exponential_distribution& __x, const exponential_distribution& __y) {return !(__x == __y);} }; template template _RealType exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { return -_VSTD::log ( result_type(1) - _VSTD::generate_canonical::digits>(__g) ) / __p.lambda(); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const exponential_distribution<_RealType>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); return __os << __x.lambda(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, exponential_distribution<_RealType>& __x) { typedef exponential_distribution<_RealType> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __lambda; __is >> __lambda; if (!__is.fail()) __x.param(param_type(__lambda)); return __is; } // normal_distribution template class _LIBCPP_TEMPLATE_VIS normal_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __mean_; result_type __stddev_; public: typedef normal_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __mean = 0, result_type __stddev = 1) : __mean_(__mean), __stddev_(__stddev) {} _LIBCPP_INLINE_VISIBILITY result_type mean() const {return __mean_;} _LIBCPP_INLINE_VISIBILITY result_type stddev() const {return __stddev_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; result_type _V_; bool _V_hot_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} _LIBCPP_INLINE_VISIBILITY explicit normal_distribution(const param_type& __p) : __p_(__p), _V_hot_(false) {} _LIBCPP_INLINE_VISIBILITY void reset() {_V_hot_ = false;} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type mean() const {return __p_.mean();} _LIBCPP_INLINE_VISIBILITY result_type stddev() const {return __p_.stddev();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return -numeric_limits::infinity();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const normal_distribution& __x, const normal_distribution& __y) {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && (!__x._V_hot_ || __x._V_ == __y._V_);} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const normal_distribution& __x, const normal_distribution& __y) {return !(__x == __y);} template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const normal_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, normal_distribution<_RT>& __x); }; template template _RealType normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { result_type _Up; if (_V_hot_) { _V_hot_ = false; _Up = _V_; } else { uniform_real_distribution _Uni(-1, 1); result_type __u; result_type __v; result_type __s; do { __u = _Uni(__g); __v = _Uni(__g); __s = __u * __u + __v * __v; } while (__s > 1 || __s == 0); result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); _V_ = __v * _Fp; _V_hot_ = true; _Up = __u * _Fp; } return _Up * __p.stddev() + __p.mean(); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const normal_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; if (__x._V_hot_) __os << __sp << __x._V_; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, normal_distribution<_RT>& __x) { typedef normal_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __mean; result_type __stddev; result_type _Vp = 0; bool _V_hot = false; __is >> __mean >> __stddev >> _V_hot; if (_V_hot) __is >> _Vp; if (!__is.fail()) { __x.param(param_type(__mean, __stddev)); __x._V_hot_ = _V_hot; __x._V_ = _Vp; } return __is; } // lognormal_distribution template class _LIBCPP_TEMPLATE_VIS lognormal_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { normal_distribution __nd_; public: typedef lognormal_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __m = 0, result_type __s = 1) : __nd_(__m, __s) {} _LIBCPP_INLINE_VISIBILITY result_type m() const {return __nd_.mean();} _LIBCPP_INLINE_VISIBILITY result_type s() const {return __nd_.stddev();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__nd_ == __y.__nd_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} friend class lognormal_distribution; template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x); }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) : __p_(param_type(__m, __s)) {} _LIBCPP_INLINE_VISIBILITY explicit lognormal_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {__p_.__nd_.reset();} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p) {return _VSTD::exp(const_cast&>(__p.__nd_)(__g));} // property functions _LIBCPP_INLINE_VISIBILITY result_type m() const {return __p_.m();} _LIBCPP_INLINE_VISIBILITY result_type s() const {return __p_.s();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const lognormal_distribution& __x, const lognormal_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const lognormal_distribution& __x, const lognormal_distribution& __y) {return !(__x == __y);} template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x); }; template inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x) { return __os << __x.__p_.__nd_; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x) { return __is >> __x.__p_.__nd_; } // poisson_distribution template class _LIBCPP_TEMPLATE_VIS poisson_distribution { public: // types typedef _IntType result_type; class _LIBCPP_TEMPLATE_VIS param_type { double __mean_; double __s_; double __d_; double __l_; double __omega_; double __c0_; double __c1_; double __c2_; double __c3_; double __c_; public: typedef poisson_distribution distribution_type; explicit param_type(double __mean = 1.0); _LIBCPP_INLINE_VISIBILITY double mean() const {return __mean_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__mean_ == __y.__mean_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} friend class poisson_distribution; }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} _LIBCPP_INLINE_VISIBILITY explicit poisson_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY double mean() const {return __p_.mean();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::max();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const poisson_distribution& __x, const poisson_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const poisson_distribution& __x, const poisson_distribution& __y) {return !(__x == __y);} }; template poisson_distribution<_IntType>::param_type::param_type(double __mean) // According to the standard `inf` is a valid input, but it causes the // distribution to hang, so we replace it with the maximum representable // mean. : __mean_(isinf(__mean) ? numeric_limits::max() : __mean) { if (__mean_ < 10) { __s_ = 0; __d_ = 0; __l_ = _VSTD::exp(-__mean_); __omega_ = 0; __c3_ = 0; __c2_ = 0; __c1_ = 0; __c0_ = 0; __c_ = 0; } else { __s_ = _VSTD::sqrt(__mean_); __d_ = 6 * __mean_ * __mean_; __l_ = std::trunc(__mean_ - 1.1484); __omega_ = .3989423 / __s_; double __b1_ = .4166667E-1 / __mean_; double __b2_ = .3 * __b1_ * __b1_; __c3_ = .1428571 * __b1_ * __b2_; __c2_ = __b2_ - 15. * __c3_; __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; __c_ = .1069 / __mean_; } } template template _IntType poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) { double __tx; uniform_real_distribution __urd; if (__pr.__mean_ < 10) { __tx = 0; for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) __p *= __urd(__urng); } else { double __difmuk; double __g = __pr.__mean_ + __pr.__s_ * normal_distribution()(__urng); double __u; if (__g > 0) { __tx = std::trunc(__g); if (__tx >= __pr.__l_) return std::__clamp_to_integral(__tx); __difmuk = __pr.__mean_ - __tx; __u = __urd(__urng); if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) return std::__clamp_to_integral(__tx); } exponential_distribution __edist; for (bool __using_exp_dist = false; true; __using_exp_dist = true) { double __e; if (__using_exp_dist || __g <= 0) { double __t; do { __e = __edist(__urng); __u = __urd(__urng); __u += __u - 1; __t = 1.8 + (__u < 0 ? -__e : __e); } while (__t <= -.6744); __tx = std::trunc(__pr.__mean_ + __pr.__s_ * __t); __difmuk = __pr.__mean_ - __tx; __using_exp_dist = true; } double __px; double __py; if (__tx < 10 && __tx >= 0) { const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880}; __px = -__pr.__mean_; __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast(__tx)]; } else { double __del = .8333333E-1 / __tx; __del -= 4.8 * __del * __del * __del; double __v = __difmuk / __tx; if (_VSTD::abs(__v) > 0.25) __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; else __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * __v + .1421878) * __v + -.1661269) * __v + .2000118) * __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; __py = .3989423 / _VSTD::sqrt(__tx); } double __r = (0.5 - __difmuk) / __pr.__s_; double __r2 = __r * __r; double __fx = -0.5 * __r2; double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * __r2 + __pr.__c1_) * __r2 + __pr.__c0_); if (__using_exp_dist) { if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - __fy * _VSTD::exp(__fx + __e)) break; } else { if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) break; } } } return std::__clamp_to_integral(__tx); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const poisson_distribution<_IntType>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); return __os << __x.mean(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, poisson_distribution<_IntType>& __x) { typedef poisson_distribution<_IntType> _Eng; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); double __mean; __is >> __mean; if (!__is.fail()) __x.param(param_type(__mean)); return __is; } // weibull_distribution template class _LIBCPP_TEMPLATE_VIS weibull_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; public: typedef weibull_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __a = 1, result_type __b = 1) : __a_(__a), __b_(__b) {} _LIBCPP_INLINE_VISIBILITY result_type a() const {return __a_;} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit weibull_distribution(result_type __a = 1, result_type __b = 1) : __p_(param_type(__a, __b)) {} _LIBCPP_INLINE_VISIBILITY explicit weibull_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p) {return __p.b() * _VSTD::pow(exponential_distribution()(__g), 1/__p.a());} // property functions _LIBCPP_INLINE_VISIBILITY result_type a() const {return __p_.a();} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __p_.b();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const weibull_distribution& __x, const weibull_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const weibull_distribution& __x, const weibull_distribution& __y) {return !(__x == __y);} }; template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const weibull_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.a() << __sp << __x.b(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, weibull_distribution<_RT>& __x) { typedef weibull_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __a; result_type __b; __is >> __a >> __b; if (!__is.fail()) __x.param(param_type(__a, __b)); return __is; } template class _LIBCPP_TEMPLATE_VIS extreme_value_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; public: typedef extreme_value_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} _LIBCPP_INLINE_VISIBILITY result_type a() const {return __a_;} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) : __p_(param_type(__a, __b)) {} _LIBCPP_INLINE_VISIBILITY explicit extreme_value_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type a() const {return __p_.a();} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __p_.b();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return -numeric_limits::infinity();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const extreme_value_distribution& __x, const extreme_value_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const extreme_value_distribution& __x, const extreme_value_distribution& __y) {return !(__x == __y);} }; template template _RealType extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { return __p.a() - __p.b() * _VSTD::log(-_VSTD::log(1-uniform_real_distribution()(__g))); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const extreme_value_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.a() << __sp << __x.b(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, extreme_value_distribution<_RT>& __x) { typedef extreme_value_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __a; result_type __b; __is >> __a >> __b; if (!__is.fail()) __x.param(param_type(__a, __b)); return __is; } // gamma_distribution template class _LIBCPP_TEMPLATE_VIS gamma_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __alpha_; result_type __beta_; public: typedef gamma_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __alpha = 1, result_type __beta = 1) : __alpha_(__alpha), __beta_(__beta) {} _LIBCPP_INLINE_VISIBILITY result_type alpha() const {return __alpha_;} _LIBCPP_INLINE_VISIBILITY result_type beta() const {return __beta_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) : __p_(param_type(__alpha, __beta)) {} _LIBCPP_INLINE_VISIBILITY explicit gamma_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type alpha() const {return __p_.alpha();} _LIBCPP_INLINE_VISIBILITY result_type beta() const {return __p_.beta();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const gamma_distribution& __x, const gamma_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const gamma_distribution& __x, const gamma_distribution& __y) {return !(__x == __y);} }; template template _RealType gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { result_type __a = __p.alpha(); uniform_real_distribution __gen(0, 1); exponential_distribution __egen; result_type __x; if (__a == 1) __x = __egen(__g); else if (__a > 1) { const result_type __b = __a - 1; const result_type __c = 3 * __a - result_type(0.75); while (true) { const result_type __u = __gen(__g); const result_type __v = __gen(__g); const result_type __w = __u * (1 - __u); if (__w != 0) { const result_type __y = _VSTD::sqrt(__c / __w) * (__u - result_type(0.5)); __x = __b + __y; if (__x >= 0) { const result_type __z = 64 * __w * __w * __w * __v * __v; if (__z <= 1 - 2 * __y * __y / __x) break; if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) break; } } } } else // __a < 1 { while (true) { const result_type __u = __gen(__g); const result_type __es = __egen(__g); if (__u <= 1 - __a) { __x = _VSTD::pow(__u, 1 / __a); if (__x <= __es) break; } else { const result_type __e = -_VSTD::log((1-__u)/__a); __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); if (__x <= __e + __es) break; } } } return __x * __p.beta(); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const gamma_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.alpha() << __sp << __x.beta(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, gamma_distribution<_RT>& __x) { typedef gamma_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __alpha; result_type __beta; __is >> __alpha >> __beta; if (!__is.fail()) __x.param(param_type(__alpha, __beta)); return __is; } // negative_binomial_distribution template class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution { public: // types typedef _IntType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __k_; double __p_; public: typedef negative_binomial_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __k = 1, double __p = 0.5) : __k_(__k), __p_(__p) {} _LIBCPP_INLINE_VISIBILITY result_type k() const {return __k_;} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) : __p_(__k, __p) {} _LIBCPP_INLINE_VISIBILITY explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type k() const {return __p_.k();} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_.p();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::max();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const negative_binomial_distribution& __x, const negative_binomial_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const negative_binomial_distribution& __x, const negative_binomial_distribution& __y) {return !(__x == __y);} }; template template _IntType negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) { result_type __k = __pr.k(); double __p = __pr.p(); if (__k <= 21 * __p) { bernoulli_distribution __gen(__p); result_type __f = 0; result_type __s = 0; while (__s < __k) { if (__gen(__urng)) ++__s; else ++__f; } return __f; } return poisson_distribution(gamma_distribution (__k, (1-__p)/__p)(__urng))(__urng); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const negative_binomial_distribution<_IntType>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); return __os << __x.k() << __sp << __x.p(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, negative_binomial_distribution<_IntType>& __x) { typedef negative_binomial_distribution<_IntType> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __k; double __p; __is >> __k >> __p; if (!__is.fail()) __x.param(param_type(__k, __p)); return __is; } // geometric_distribution template class _LIBCPP_TEMPLATE_VIS geometric_distribution { public: // types typedef _IntType result_type; class _LIBCPP_TEMPLATE_VIS param_type { double __p_; public: typedef geometric_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(double __p = 0.5) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY double p() const {return __p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions _LIBCPP_INLINE_VISIBILITY explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY explicit geometric_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p) {return negative_binomial_distribution(1, __p.p())(__g);} // property functions _LIBCPP_INLINE_VISIBILITY double p() const {return __p_.p();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::max();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const geometric_distribution& __x, const geometric_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const geometric_distribution& __x, const geometric_distribution& __y) {return !(__x == __y);} }; template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const geometric_distribution<_IntType>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); return __os << __x.p(); } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, geometric_distribution<_IntType>& __x) { typedef geometric_distribution<_IntType> _Eng; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); double __p; __is >> __p; if (!__is.fail()) __x.param(param_type(__p)); return __is; } // chi_squared_distribution template class _LIBCPP_TEMPLATE_VIS chi_squared_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __n_; public: typedef chi_squared_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __n = 1) : __n_(__n) {} _LIBCPP_INLINE_VISIBILITY result_type n() const {return __n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__n_ == __y.__n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit chi_squared_distribution(result_type __n = 1) : __p_(param_type(__n)) {} _LIBCPP_INLINE_VISIBILITY explicit chi_squared_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p) {return gamma_distribution(__p.n() / 2, 2)(__g);} // property functions _LIBCPP_INLINE_VISIBILITY result_type n() const {return __p_.n();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const chi_squared_distribution& __x, const chi_squared_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const chi_squared_distribution& __x, const chi_squared_distribution& __y) {return !(__x == __y);} }; template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const chi_squared_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); __os << __x.n(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, chi_squared_distribution<_RT>& __x) { typedef chi_squared_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __n; __is >> __n; if (!__is.fail()) __x.param(param_type(__n)); return __is; } // cauchy_distribution template class _LIBCPP_TEMPLATE_VIS cauchy_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; public: typedef cauchy_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __a = 0, result_type __b = 1) : __a_(__a), __b_(__b) {} _LIBCPP_INLINE_VISIBILITY result_type a() const {return __a_;} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) : __p_(param_type(__a, __b)) {} _LIBCPP_INLINE_VISIBILITY explicit cauchy_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type a() const {return __p_.a();} _LIBCPP_INLINE_VISIBILITY result_type b() const {return __p_.b();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return -numeric_limits::infinity();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const cauchy_distribution& __x, const cauchy_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const cauchy_distribution& __x, const cauchy_distribution& __y) {return !(__x == __y);} }; template template inline _RealType cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { uniform_real_distribution __gen; // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const cauchy_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.a() << __sp << __x.b(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, cauchy_distribution<_RT>& __x) { typedef cauchy_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __a; result_type __b; __is >> __a >> __b; if (!__is.fail()) __x.param(param_type(__a, __b)); return __is; } // fisher_f_distribution template class _LIBCPP_TEMPLATE_VIS fisher_f_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __m_; result_type __n_; public: typedef fisher_f_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __m = 1, result_type __n = 1) : __m_(__m), __n_(__n) {} _LIBCPP_INLINE_VISIBILITY result_type m() const {return __m_;} _LIBCPP_INLINE_VISIBILITY result_type n() const {return __n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) : __p_(param_type(__m, __n)) {} _LIBCPP_INLINE_VISIBILITY explicit fisher_f_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type m() const {return __p_.m();} _LIBCPP_INLINE_VISIBILITY result_type n() const {return __p_.n();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const fisher_f_distribution& __x, const fisher_f_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const fisher_f_distribution& __x, const fisher_f_distribution& __y) {return !(__x == __y);} }; template template _RealType fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { gamma_distribution __gdm(__p.m() * result_type(.5)); gamma_distribution __gdn(__p.n() * result_type(.5)); return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const fisher_f_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); __os << __x.m() << __sp << __x.n(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, fisher_f_distribution<_RT>& __x) { typedef fisher_f_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __m; result_type __n; __is >> __m >> __n; if (!__is.fail()) __x.param(param_type(__m, __n)); return __is; } // student_t_distribution template class _LIBCPP_TEMPLATE_VIS student_t_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { result_type __n_; public: typedef student_t_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY explicit param_type(result_type __n = 1) : __n_(__n) {} _LIBCPP_INLINE_VISIBILITY result_type n() const {return __n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__n_ == __y.__n_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; normal_distribution __nd_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY explicit student_t_distribution(result_type __n = 1) : __p_(param_type(__n)) {} _LIBCPP_INLINE_VISIBILITY explicit student_t_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {__nd_.reset();} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY result_type n() const {return __p_.n();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return -numeric_limits::infinity();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return numeric_limits::infinity();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const student_t_distribution& __x, const student_t_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const student_t_distribution& __x, const student_t_distribution& __y) {return !(__x == __y);} }; template template _RealType student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { gamma_distribution __gd(__p.n() * .5, 2); return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const student_t_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); __os << __x.n(); return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, student_t_distribution<_RT>& __x) { typedef student_t_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; typedef typename _Eng::param_type param_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); result_type __n; __is >> __n; if (!__is.fail()) __x.param(param_type(__n)); return __is; } // discrete_distribution template class _LIBCPP_TEMPLATE_VIS discrete_distribution { public: // types typedef _IntType result_type; class _LIBCPP_TEMPLATE_VIS param_type { vector __p_; public: typedef discrete_distribution distribution_type; _LIBCPP_INLINE_VISIBILITY param_type() {} template _LIBCPP_INLINE_VISIBILITY param_type(_InputIterator __f, _InputIterator __l) : __p_(__f, __l) {__init();} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY param_type(initializer_list __wl) : __p_(__wl.begin(), __wl.end()) {__init();} #endif // _LIBCPP_CXX03_LANG template param_type(size_t __nw, double __xmin, double __xmax, _UnaryOperation __fw); vector probabilities() const; friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} private: void __init(); friend class discrete_distribution; template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const discrete_distribution<_IT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, discrete_distribution<_IT>& __x); }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY discrete_distribution() {} template _LIBCPP_INLINE_VISIBILITY discrete_distribution(_InputIterator __f, _InputIterator __l) : __p_(__f, __l) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY discrete_distribution(initializer_list __wl) : __p_(__wl) {} #endif // _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY discrete_distribution(size_t __nw, double __xmin, double __xmax, _UnaryOperation __fw) : __p_(__nw, __xmin, __xmax, __fw) {} _LIBCPP_INLINE_VISIBILITY explicit discrete_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY vector probabilities() const {return __p_.probabilities();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return 0;} _LIBCPP_INLINE_VISIBILITY result_type max() const {return __p_.__p_.size();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const discrete_distribution& __x, const discrete_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const discrete_distribution& __x, const discrete_distribution& __y) {return !(__x == __y);} template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const discrete_distribution<_IT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, discrete_distribution<_IT>& __x); }; template template discrete_distribution<_IntType>::param_type::param_type(size_t __nw, double __xmin, double __xmax, _UnaryOperation __fw) { if (__nw > 1) { __p_.reserve(__nw - 1); double __d = (__xmax - __xmin) / __nw; double __d2 = __d / 2; for (size_t __k = 0; __k < __nw; ++__k) __p_.push_back(__fw(__xmin + __k * __d + __d2)); __init(); } } template void discrete_distribution<_IntType>::param_type::__init() { if (!__p_.empty()) { if (__p_.size() > 1) { double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); for (_VSTD::vector::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i) *__i /= __s; vector __t(__p_.size() - 1); _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); swap(__p_, __t); } else { __p_.clear(); __p_.shrink_to_fit(); } } } template vector discrete_distribution<_IntType>::param_type::probabilities() const { size_t __n = __p_.size(); _VSTD::vector __p(__n+1); _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); if (__n > 0) __p[__n] = 1 - __p_[__n-1]; else __p[0] = 1; return __p; } template template _IntType discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) { uniform_real_distribution __gen; return static_cast<_IntType>( _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - __p.__p_.begin()); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const discrete_distribution<_IT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); size_t __n = __x.__p_.__p_.size(); __os << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__p_[__i]; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, discrete_distribution<_IT>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); size_t __n; __is >> __n; vector __p(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __p[__i]; if (!__is.fail()) swap(__x.__p_.__p_, __p); return __is; } // piecewise_constant_distribution template class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { vector __b_; vector __densities_; vector __areas_; public: typedef piecewise_constant_distribution distribution_type; param_type(); template param_type(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW); #ifndef _LIBCPP_CXX03_LANG template param_type(initializer_list __bl, _UnaryOperation __fw); #endif // _LIBCPP_CXX03_LANG template param_type(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw); + param_type(param_type const&) = default; param_type & operator=(const param_type& __rhs); _LIBCPP_INLINE_VISIBILITY vector intervals() const {return __b_;} _LIBCPP_INLINE_VISIBILITY vector densities() const {return __densities_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} private: void __init(); friend class piecewise_constant_distribution; template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_constant_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_constant_distribution<_RT>& __x); }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY piecewise_constant_distribution() {} template _LIBCPP_INLINE_VISIBILITY piecewise_constant_distribution(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) : __p_(__fB, __lB, __fW) {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY piecewise_constant_distribution(initializer_list __bl, _UnaryOperation __fw) : __p_(__bl, __fw) {} #endif // _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY piecewise_constant_distribution(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) : __p_(__nw, __xmin, __xmax, __fw) {} _LIBCPP_INLINE_VISIBILITY explicit piecewise_constant_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY vector intervals() const {return __p_.intervals();} _LIBCPP_INLINE_VISIBILITY vector densities() const {return __p_.densities();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return __p_.__b_.front();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return __p_.__b_.back();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const piecewise_constant_distribution& __x, const piecewise_constant_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const piecewise_constant_distribution& __x, const piecewise_constant_distribution& __y) {return !(__x == __y);} template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_constant_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_constant_distribution<_RT>& __x); }; template typename piecewise_constant_distribution<_RealType>::param_type & piecewise_constant_distribution<_RealType>::param_type::operator= (const param_type& __rhs) { // These can throw __b_.reserve (__rhs.__b_.size ()); __densities_.reserve(__rhs.__densities_.size()); __areas_.reserve (__rhs.__areas_.size()); // These can not throw __b_ = __rhs.__b_; __densities_ = __rhs.__densities_; __areas_ = __rhs.__areas_; return *this; } template void piecewise_constant_distribution<_RealType>::param_type::__init() { // __densities_ contains non-normalized areas result_type __total_area = _VSTD::accumulate(__densities_.begin(), __densities_.end(), result_type()); for (size_t __i = 0; __i < __densities_.size(); ++__i) __densities_[__i] /= __total_area; // __densities_ contains normalized areas __areas_.assign(__densities_.size(), result_type()); _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, __areas_.begin() + 1); // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] __densities_.back() = 1 - __areas_.back(); // correct round off error for (size_t __i = 0; __i < __densities_.size(); ++__i) __densities_[__i] /= (__b_[__i+1] - __b_[__i]); // __densities_ now contains __densities_ } template piecewise_constant_distribution<_RealType>::param_type::param_type() : __b_(2), __densities_(1, 1.0), __areas_(1, 0.0) { __b_[1] = 1; } template template piecewise_constant_distribution<_RealType>::param_type::param_type( _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) : __b_(__fB, __lB) { if (__b_.size() < 2) { __b_.resize(2); __b_[0] = 0; __b_[1] = 1; __densities_.assign(1, 1.0); __areas_.assign(1, 0.0); } else { __densities_.reserve(__b_.size() - 1); for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) __densities_.push_back(*__fW); __init(); } } #ifndef _LIBCPP_CXX03_LANG template template piecewise_constant_distribution<_RealType>::param_type::param_type( initializer_list __bl, _UnaryOperation __fw) : __b_(__bl.begin(), __bl.end()) { if (__b_.size() < 2) { __b_.resize(2); __b_[0] = 0; __b_[1] = 1; __densities_.assign(1, 1.0); __areas_.assign(1, 0.0); } else { __densities_.reserve(__b_.size() - 1); for (size_t __i = 0; __i < __b_.size() - 1; ++__i) __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); __init(); } } #endif // _LIBCPP_CXX03_LANG template template piecewise_constant_distribution<_RealType>::param_type::param_type( size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) : __b_(__nw == 0 ? 2 : __nw + 1) { size_t __n = __b_.size() - 1; result_type __d = (__xmax - __xmin) / __n; __densities_.reserve(__n); for (size_t __i = 0; __i < __n; ++__i) { __b_[__i] = __xmin + __i * __d; __densities_.push_back(__fw(__b_[__i] + __d*.5)); } __b_[__n] = __xmax; __init(); } template template _RealType piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { typedef uniform_real_distribution _Gen; result_type __u = _Gen()(__g); ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), __u) - __p.__areas_.begin() - 1; return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_constant_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); size_t __n = __x.__p_.__b_.size(); __os << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__b_[__i]; __n = __x.__p_.__densities_.size(); __os << __sp << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__densities_[__i]; __n = __x.__p_.__areas_.size(); __os << __sp << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__areas_[__i]; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_constant_distribution<_RT>& __x) { typedef piecewise_constant_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); size_t __n; __is >> __n; vector __b(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __b[__i]; __is >> __n; vector __densities(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __densities[__i]; __is >> __n; vector __areas(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __areas[__i]; if (!__is.fail()) { swap(__x.__p_.__b_, __b); swap(__x.__p_.__densities_, __densities); swap(__x.__p_.__areas_, __areas); } return __is; } // piecewise_linear_distribution template class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution { public: // types typedef _RealType result_type; class _LIBCPP_TEMPLATE_VIS param_type { vector __b_; vector __densities_; vector __areas_; public: typedef piecewise_linear_distribution distribution_type; param_type(); template param_type(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW); #ifndef _LIBCPP_CXX03_LANG template param_type(initializer_list __bl, _UnaryOperation __fw); #endif // _LIBCPP_CXX03_LANG template param_type(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw); + param_type(param_type const&) = default; param_type & operator=(const param_type& __rhs); _LIBCPP_INLINE_VISIBILITY vector intervals() const {return __b_;} _LIBCPP_INLINE_VISIBILITY vector densities() const {return __densities_;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const param_type& __x, const param_type& __y) {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} private: void __init(); friend class piecewise_linear_distribution; template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_linear_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_linear_distribution<_RT>& __x); }; private: param_type __p_; public: // constructor and reset functions _LIBCPP_INLINE_VISIBILITY piecewise_linear_distribution() {} template _LIBCPP_INLINE_VISIBILITY piecewise_linear_distribution(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) : __p_(__fB, __lB, __fW) {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY piecewise_linear_distribution(initializer_list __bl, _UnaryOperation __fw) : __p_(__bl, __fw) {} #endif // _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY piecewise_linear_distribution(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) : __p_(__nw, __xmin, __xmax, __fw) {} _LIBCPP_INLINE_VISIBILITY explicit piecewise_linear_distribution(const param_type& __p) : __p_(__p) {} _LIBCPP_INLINE_VISIBILITY void reset() {} // generating functions template _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions _LIBCPP_INLINE_VISIBILITY vector intervals() const {return __p_.intervals();} _LIBCPP_INLINE_VISIBILITY vector densities() const {return __p_.densities();} _LIBCPP_INLINE_VISIBILITY param_type param() const {return __p_;} _LIBCPP_INLINE_VISIBILITY void param(const param_type& __p) {__p_ = __p;} _LIBCPP_INLINE_VISIBILITY result_type min() const {return __p_.__b_.front();} _LIBCPP_INLINE_VISIBILITY result_type max() const {return __p_.__b_.back();} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const piecewise_linear_distribution& __x, const piecewise_linear_distribution& __y) {return __x.__p_ == __y.__p_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const piecewise_linear_distribution& __x, const piecewise_linear_distribution& __y) {return !(__x == __y);} template friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_linear_distribution<_RT>& __x); template friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_linear_distribution<_RT>& __x); }; template typename piecewise_linear_distribution<_RealType>::param_type & piecewise_linear_distribution<_RealType>::param_type::operator= (const param_type& __rhs) { // These can throw __b_.reserve (__rhs.__b_.size ()); __densities_.reserve(__rhs.__densities_.size()); __areas_.reserve (__rhs.__areas_.size()); // These can not throw __b_ = __rhs.__b_; __densities_ = __rhs.__densities_; __areas_ = __rhs.__areas_; return *this; } template void piecewise_linear_distribution<_RealType>::param_type::__init() { __areas_.assign(__densities_.size() - 1, result_type()); result_type _Sp = 0; for (size_t __i = 0; __i < __areas_.size(); ++__i) { __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * (__b_[__i+1] - __b_[__i]) * .5; _Sp += __areas_[__i]; } for (size_t __i = __areas_.size(); __i > 1;) { --__i; __areas_[__i] = __areas_[__i-1] / _Sp; } __areas_[0] = 0; for (size_t __i = 1; __i < __areas_.size(); ++__i) __areas_[__i] += __areas_[__i-1]; for (size_t __i = 0; __i < __densities_.size(); ++__i) __densities_[__i] /= _Sp; } template piecewise_linear_distribution<_RealType>::param_type::param_type() : __b_(2), __densities_(2, 1.0), __areas_(1, 0.0) { __b_[1] = 1; } template template piecewise_linear_distribution<_RealType>::param_type::param_type( _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) : __b_(__fB, __lB) { if (__b_.size() < 2) { __b_.resize(2); __b_[0] = 0; __b_[1] = 1; __densities_.assign(2, 1.0); __areas_.assign(1, 0.0); } else { __densities_.reserve(__b_.size()); for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) __densities_.push_back(*__fW); __init(); } } #ifndef _LIBCPP_CXX03_LANG template template piecewise_linear_distribution<_RealType>::param_type::param_type( initializer_list __bl, _UnaryOperation __fw) : __b_(__bl.begin(), __bl.end()) { if (__b_.size() < 2) { __b_.resize(2); __b_[0] = 0; __b_[1] = 1; __densities_.assign(2, 1.0); __areas_.assign(1, 0.0); } else { __densities_.reserve(__b_.size()); for (size_t __i = 0; __i < __b_.size(); ++__i) __densities_.push_back(__fw(__b_[__i])); __init(); } } #endif // _LIBCPP_CXX03_LANG template template piecewise_linear_distribution<_RealType>::param_type::param_type( size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) : __b_(__nw == 0 ? 2 : __nw + 1) { size_t __n = __b_.size() - 1; result_type __d = (__xmax - __xmin) / __n; __densities_.reserve(__b_.size()); for (size_t __i = 0; __i < __n; ++__i) { __b_[__i] = __xmin + __i * __d; __densities_.push_back(__fw(__b_[__i])); } __b_[__n] = __xmax; __densities_.push_back(__fw(__b_[__n])); __init(); } template template _RealType piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) { typedef uniform_real_distribution _Gen; result_type __u = _Gen()(__g); ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), __u) - __p.__areas_.begin() - 1; __u -= __p.__areas_[__k]; const result_type __dk = __p.__densities_[__k]; const result_type __dk1 = __p.__densities_[__k+1]; const result_type __deltad = __dk1 - __dk; const result_type __bk = __p.__b_[__k]; if (__deltad == 0) return __u / __dk + __bk; const result_type __bk1 = __p.__b_[__k+1]; const result_type __deltab = __bk1 - __bk; return (__bk * __dk1 - __bk1 * __dk + _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / __deltad; } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const piecewise_linear_distribution<_RT>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | ios_base::scientific); _CharT __sp = __os.widen(' '); __os.fill(__sp); size_t __n = __x.__p_.__b_.size(); __os << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__b_[__i]; __n = __x.__p_.__densities_.size(); __os << __sp << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__densities_[__i]; __n = __x.__p_.__areas_.size(); __os << __sp << __n; for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__areas_[__i]; return __os; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, piecewise_linear_distribution<_RT>& __x) { typedef piecewise_linear_distribution<_RT> _Eng; typedef typename _Eng::result_type result_type; __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); size_t __n; __is >> __n; vector __b(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __b[__i]; __is >> __n; vector __densities(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __densities[__i]; __is >> __n; vector __areas(__n); for (size_t __i = 0; __i < __n; ++__i) __is >> __areas[__i]; if (!__is.fail()) { swap(__x.__p_.__b_, __b); swap(__x.__p_.__densities_, __densities); swap(__x.__p_.__areas_, __areas); } return __is; } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_RANDOM Index: stable/12/contrib/llvm-project/libcxx/include/valarray =================================================================== --- stable/12/contrib/llvm-project/libcxx/include/valarray (revision 356465) +++ stable/12/contrib/llvm-project/libcxx/include/valarray (revision 356466) @@ -1,4942 +1,4930 @@ // -*- C++ -*- //===-------------------------- valarray ----------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_VALARRAY #define _LIBCPP_VALARRAY /* valarray synopsis namespace std { template class valarray { public: typedef T value_type; // construct/destroy: valarray(); explicit valarray(size_t n); valarray(const value_type& x, size_t n); valarray(const value_type* px, size_t n); valarray(const valarray& v); valarray(valarray&& v) noexcept; valarray(const slice_array& sa); valarray(const gslice_array& ga); valarray(const mask_array& ma); valarray(const indirect_array& ia); valarray(initializer_list il); ~valarray(); // assignment: valarray& operator=(const valarray& v); valarray& operator=(valarray&& v) noexcept; valarray& operator=(initializer_list il); valarray& operator=(const value_type& x); valarray& operator=(const slice_array& sa); valarray& operator=(const gslice_array& ga); valarray& operator=(const mask_array& ma); valarray& operator=(const indirect_array& ia); // element access: const value_type& operator[](size_t i) const; value_type& operator[](size_t i); // subset operations: valarray operator[](slice s) const; slice_array operator[](slice s); valarray operator[](const gslice& gs) const; gslice_array operator[](const gslice& gs); valarray operator[](const valarray& vb) const; mask_array operator[](const valarray& vb); valarray operator[](const valarray& vs) const; indirect_array operator[](const valarray& vs); // unary operators: valarray operator+() const; valarray operator-() const; valarray operator~() const; valarray operator!() const; // computed assignment: valarray& operator*= (const value_type& x); valarray& operator/= (const value_type& x); valarray& operator%= (const value_type& x); valarray& operator+= (const value_type& x); valarray& operator-= (const value_type& x); valarray& operator^= (const value_type& x); valarray& operator&= (const value_type& x); valarray& operator|= (const value_type& x); valarray& operator<<=(const value_type& x); valarray& operator>>=(const value_type& x); valarray& operator*= (const valarray& v); valarray& operator/= (const valarray& v); valarray& operator%= (const valarray& v); valarray& operator+= (const valarray& v); valarray& operator-= (const valarray& v); valarray& operator^= (const valarray& v); valarray& operator|= (const valarray& v); valarray& operator&= (const valarray& v); valarray& operator<<=(const valarray& v); valarray& operator>>=(const valarray& v); // member functions: void swap(valarray& v) noexcept; size_t size() const; value_type sum() const; value_type min() const; value_type max() const; valarray shift (int i) const; valarray cshift(int i) const; valarray apply(value_type f(value_type)) const; valarray apply(value_type f(const value_type&)) const; void resize(size_t n, value_type x = value_type()); }; class slice { public: slice(); slice(size_t start, size_t size, size_t stride); size_t start() const; size_t size() const; size_t stride() const; }; template class slice_array { public: typedef T value_type; const slice_array& operator=(const slice_array& sa) const; void operator= (const valarray& v) const; void operator*= (const valarray& v) const; void operator/= (const valarray& v) const; void operator%= (const valarray& v) const; void operator+= (const valarray& v) const; void operator-= (const valarray& v) const; void operator^= (const valarray& v) const; void operator&= (const valarray& v) const; void operator|= (const valarray& v) const; void operator<<=(const valarray& v) const; void operator>>=(const valarray& v) const; void operator=(const value_type& x) const; slice_array() = delete; }; class gslice { public: gslice(); gslice(size_t start, const valarray& size, const valarray& stride); size_t start() const; valarray size() const; valarray stride() const; }; template class gslice_array { public: typedef T value_type; void operator= (const valarray& v) const; void operator*= (const valarray& v) const; void operator/= (const valarray& v) const; void operator%= (const valarray& v) const; void operator+= (const valarray& v) const; void operator-= (const valarray& v) const; void operator^= (const valarray& v) const; void operator&= (const valarray& v) const; void operator|= (const valarray& v) const; void operator<<=(const valarray& v) const; void operator>>=(const valarray& v) const; gslice_array(const gslice_array& ga); ~gslice_array(); const gslice_array& operator=(const gslice_array& ga) const; void operator=(const value_type& x) const; gslice_array() = delete; }; template class mask_array { public: typedef T value_type; void operator= (const valarray& v) const; void operator*= (const valarray& v) const; void operator/= (const valarray& v) const; void operator%= (const valarray& v) const; void operator+= (const valarray& v) const; void operator-= (const valarray& v) const; void operator^= (const valarray& v) const; void operator&= (const valarray& v) const; void operator|= (const valarray& v) const; void operator<<=(const valarray& v) const; void operator>>=(const valarray& v) const; mask_array(const mask_array& ma); ~mask_array(); const mask_array& operator=(const mask_array& ma) const; void operator=(const value_type& x) const; mask_array() = delete; }; template class indirect_array { public: typedef T value_type; void operator= (const valarray& v) const; void operator*= (const valarray& v) const; void operator/= (const valarray& v) const; void operator%= (const valarray& v) const; void operator+= (const valarray& v) const; void operator-= (const valarray& v) const; void operator^= (const valarray& v) const; void operator&= (const valarray& v) const; void operator|= (const valarray& v) const; void operator<<=(const valarray& v) const; void operator>>=(const valarray& v) const; indirect_array(const indirect_array& ia); ~indirect_array(); const indirect_array& operator=(const indirect_array& ia) const; void operator=(const value_type& x) const; indirect_array() = delete; }; template void swap(valarray& x, valarray& y) noexcept; template valarray operator* (const valarray& x, const valarray& y); template valarray operator* (const valarray& x, const T& y); template valarray operator* (const T& x, const valarray& y); template valarray operator/ (const valarray& x, const valarray& y); template valarray operator/ (const valarray& x, const T& y); template valarray operator/ (const T& x, const valarray& y); template valarray operator% (const valarray& x, const valarray& y); template valarray operator% (const valarray& x, const T& y); template valarray operator% (const T& x, const valarray& y); template valarray operator+ (const valarray& x, const valarray& y); template valarray operator+ (const valarray& x, const T& y); template valarray operator+ (const T& x, const valarray& y); template valarray operator- (const valarray& x, const valarray& y); template valarray operator- (const valarray& x, const T& y); template valarray operator- (const T& x, const valarray& y); template valarray operator^ (const valarray& x, const valarray& y); template valarray operator^ (const valarray& x, const T& y); template valarray operator^ (const T& x, const valarray& y); template valarray operator& (const valarray& x, const valarray& y); template valarray operator& (const valarray& x, const T& y); template valarray operator& (const T& x, const valarray& y); template valarray operator| (const valarray& x, const valarray& y); template valarray operator| (const valarray& x, const T& y); template valarray operator| (const T& x, const valarray& y); template valarray operator<<(const valarray& x, const valarray& y); template valarray operator<<(const valarray& x, const T& y); template valarray operator<<(const T& x, const valarray& y); template valarray operator>>(const valarray& x, const valarray& y); template valarray operator>>(const valarray& x, const T& y); template valarray operator>>(const T& x, const valarray& y); template valarray operator&&(const valarray& x, const valarray& y); template valarray operator&&(const valarray& x, const T& y); template valarray operator&&(const T& x, const valarray& y); template valarray operator||(const valarray& x, const valarray& y); template valarray operator||(const valarray& x, const T& y); template valarray operator||(const T& x, const valarray& y); template valarray operator==(const valarray& x, const valarray& y); template valarray operator==(const valarray& x, const T& y); template valarray operator==(const T& x, const valarray& y); template valarray operator!=(const valarray& x, const valarray& y); template valarray operator!=(const valarray& x, const T& y); template valarray operator!=(const T& x, const valarray& y); template valarray operator< (const valarray& x, const valarray& y); template valarray operator< (const valarray& x, const T& y); template valarray operator< (const T& x, const valarray& y); template valarray operator> (const valarray& x, const valarray& y); template valarray operator> (const valarray& x, const T& y); template valarray operator> (const T& x, const valarray& y); template valarray operator<=(const valarray& x, const valarray& y); template valarray operator<=(const valarray& x, const T& y); template valarray operator<=(const T& x, const valarray& y); template valarray operator>=(const valarray& x, const valarray& y); template valarray operator>=(const valarray& x, const T& y); template valarray operator>=(const T& x, const valarray& y); template valarray abs (const valarray& x); template valarray acos (const valarray& x); template valarray asin (const valarray& x); template valarray atan (const valarray& x); template valarray atan2(const valarray& x, const valarray& y); template valarray atan2(const valarray& x, const T& y); template valarray atan2(const T& x, const valarray& y); template valarray cos (const valarray& x); template valarray cosh (const valarray& x); template valarray exp (const valarray& x); template valarray log (const valarray& x); template valarray log10(const valarray& x); template valarray pow(const valarray& x, const valarray& y); template valarray pow(const valarray& x, const T& y); template valarray pow(const T& x, const valarray& y); template valarray sin (const valarray& x); template valarray sinh (const valarray& x); template valarray sqrt (const valarray& x); template valarray tan (const valarray& x); template valarray tanh (const valarray& x); template unspecified1 begin(valarray& v); template unspecified2 begin(const valarray& v); template unspecified1 end(valarray& v); template unspecified2 end(const valarray& v); } // std */ #include <__config> #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD template class _LIBCPP_TEMPLATE_VIS valarray; class _LIBCPP_TEMPLATE_VIS slice { size_t __start_; size_t __size_; size_t __stride_; public: _LIBCPP_INLINE_VISIBILITY slice() : __start_(0), __size_(0), __stride_(0) {} _LIBCPP_INLINE_VISIBILITY slice(size_t __start, size_t __size, size_t __stride) : __start_(__start), __size_(__size), __stride_(__stride) {} _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;} }; template class _LIBCPP_TEMPLATE_VIS slice_array; class _LIBCPP_TYPE_VIS gslice; template class _LIBCPP_TEMPLATE_VIS gslice_array; template class _LIBCPP_TEMPLATE_VIS mask_array; template class _LIBCPP_TEMPLATE_VIS indirect_array; template _LIBCPP_INLINE_VISIBILITY _Tp* begin(valarray<_Tp>& __v); template _LIBCPP_INLINE_VISIBILITY const _Tp* begin(const valarray<_Tp>& __v); template _LIBCPP_INLINE_VISIBILITY _Tp* end(valarray<_Tp>& __v); template _LIBCPP_INLINE_VISIBILITY const _Tp* end(const valarray<_Tp>& __v); template struct _UnaryOp { typedef typename _Op::result_type result_type; typedef typename _A0::value_type value_type; _Op __op_; _A0 __a0_; _LIBCPP_INLINE_VISIBILITY _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {} _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; template struct _BinaryOp { typedef typename _Op::result_type result_type; typedef typename _A0::value_type value_type; _Op __op_; _A0 __a0_; _A1 __a1_; _LIBCPP_INLINE_VISIBILITY _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1) : __op_(__op), __a0_(__a0), __a1_(__a1) {} _LIBCPP_INLINE_VISIBILITY value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; template class __scalar_expr { public: typedef _Tp value_type; typedef const _Tp& result_type; private: const value_type& __t_; size_t __s_; public: _LIBCPP_INLINE_VISIBILITY explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {} _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t) const {return __t_;} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __s_;} }; template struct __unary_plus : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return +__x;} }; template struct __bit_not : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return ~__x;} }; template struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x << __y;} }; template struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x >> __y;} }; template struct __apply_expr : unary_function<_Tp, _Tp> { private: _Fp __f_; public: _LIBCPP_INLINE_VISIBILITY explicit __apply_expr(_Fp __f) : __f_(__f) {} _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return __f_(__x);} }; template struct __abs_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return abs(__x);} }; template struct __acos_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return acos(__x);} }; template struct __asin_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return asin(__x);} }; template struct __atan_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return atan(__x);} }; template struct __atan2_expr : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return atan2(__x, __y);} }; template struct __cos_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return cos(__x);} }; template struct __cosh_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return cosh(__x);} }; template struct __exp_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return exp(__x);} }; template struct __log_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return log(__x);} }; template struct __log10_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return log10(__x);} }; template struct __pow_expr : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return pow(__x, __y);} }; template struct __sin_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return sin(__x);} }; template struct __sinh_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return sinh(__x);} }; template struct __sqrt_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return sqrt(__x);} }; template struct __tan_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return tan(__x);} }; template struct __tanh_expr : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return tanh(__x);} }; template class __slice_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; public: typedef typename _RmExpr::value_type value_type; typedef value_type result_type; private: _ValExpr __expr_; size_t __start_; size_t __size_; size_t __stride_; _LIBCPP_INLINE_VISIBILITY __slice_expr(const slice& __sl, const _RmExpr& __e) : __expr_(__e), __start_(__sl.start()), __size_(__sl.size()), __stride_(__sl.stride()) {} public: _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __expr_[__start_ + __i * __stride_];} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} template friend class __val_expr; template friend class _LIBCPP_TEMPLATE_VIS valarray; }; template class __mask_expr; template class __indirect_expr; template class __shift_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; public: typedef typename _RmExpr::value_type value_type; typedef value_type result_type; private: _ValExpr __expr_; size_t __size_; ptrdiff_t __ul_; ptrdiff_t __sn_; ptrdiff_t __n_; static const ptrdiff_t _Np = static_cast( sizeof(ptrdiff_t) * __CHAR_BIT__ - 1); _LIBCPP_INLINE_VISIBILITY __shift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()), __n_(__n) { ptrdiff_t __neg_n = static_cast(__n_ >> _Np); __sn_ = __neg_n | static_cast(static_cast(-__n_) >> _Np); __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n); } public: _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __j) const { ptrdiff_t __i = static_cast(__j); ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np; return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m); } _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} template friend class __val_expr; }; template class __cshift_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; public: typedef typename _RmExpr::value_type value_type; typedef value_type result_type; private: _ValExpr __expr_; size_t __size_; size_t __m_; size_t __o1_; size_t __o2_; _LIBCPP_INLINE_VISIBILITY __cshift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()) { __n %= static_cast(__size_); if (__n >= 0) { __m_ = __size_ - __n; __o1_ = __n; __o2_ = __n - __size_; } else { __m_ = -__n; __o1_ = __n + __size_; __o2_ = __n; } } public: _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const { if (__i < __m_) return __expr_[__i + __o1_]; return __expr_[__i + __o2_]; } _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} template friend class __val_expr; }; template class __val_expr; template struct __is_val_expr : false_type {}; template struct __is_val_expr<__val_expr<_ValExpr> > : true_type {}; template struct __is_val_expr > : true_type {}; template class _LIBCPP_TEMPLATE_VIS valarray { public: typedef _Tp value_type; typedef _Tp result_type; private: value_type* __begin_; value_type* __end_; public: // construct/destroy: _LIBCPP_INLINE_VISIBILITY valarray() : __begin_(0), __end_(0) {} inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit valarray(size_t __n); _LIBCPP_INLINE_VISIBILITY valarray(const value_type& __x, size_t __n); valarray(const value_type* __p, size_t __n); valarray(const valarray& __v); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray(valarray&& __v) _NOEXCEPT; valarray(initializer_list __il); #endif // _LIBCPP_CXX03_LANG valarray(const slice_array& __sa); valarray(const gslice_array& __ga); valarray(const mask_array& __ma); valarray(const indirect_array& __ia); inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 ~valarray(); // assignment: valarray& operator=(const valarray& __v); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray& operator=(valarray&& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY valarray& operator=(initializer_list); #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray& operator=(const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator=(const slice_array& __sa); _LIBCPP_INLINE_VISIBILITY valarray& operator=(const gslice_array& __ga); _LIBCPP_INLINE_VISIBILITY valarray& operator=(const mask_array& __ma); _LIBCPP_INLINE_VISIBILITY valarray& operator=(const indirect_array& __ia); template _LIBCPP_INLINE_VISIBILITY valarray& operator=(const __val_expr<_ValExpr>& __v); // element access: _LIBCPP_INLINE_VISIBILITY const value_type& operator[](size_t __i) const {return __begin_[__i];} _LIBCPP_INLINE_VISIBILITY value_type& operator[](size_t __i) {return __begin_[__i];} // subset operations: _LIBCPP_INLINE_VISIBILITY __val_expr<__slice_expr > operator[](slice __s) const; _LIBCPP_INLINE_VISIBILITY slice_array operator[](slice __s); _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr > operator[](const gslice& __gs) const; _LIBCPP_INLINE_VISIBILITY gslice_array operator[](const gslice& __gs); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr > operator[](gslice&& __gs) const; _LIBCPP_INLINE_VISIBILITY gslice_array operator[](gslice&& __gs); #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr > operator[](const valarray& __vb) const; _LIBCPP_INLINE_VISIBILITY mask_array operator[](const valarray& __vb); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr > operator[](valarray&& __vb) const; _LIBCPP_INLINE_VISIBILITY mask_array operator[](valarray&& __vb); #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr > operator[](const valarray& __vs) const; _LIBCPP_INLINE_VISIBILITY indirect_array operator[](const valarray& __vs); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr > operator[](valarray&& __vs) const; _LIBCPP_INLINE_VISIBILITY indirect_array operator[](valarray&& __vs); #endif // _LIBCPP_CXX03_LANG // unary operators: valarray operator+() const; valarray operator-() const; valarray operator~() const; valarray operator!() const; // computed assignment: _LIBCPP_INLINE_VISIBILITY valarray& operator*= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator/= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator%= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator+= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator-= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator^= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator&= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator|= (const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator<<=(const value_type& __x); _LIBCPP_INLINE_VISIBILITY valarray& operator>>=(const value_type& __x); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator*= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator/= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator%= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator+= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator-= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator^= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator|= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator&= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator<<= (const _Expr& __v); template typename enable_if < __is_val_expr<_Expr>::value, valarray& >::type _LIBCPP_INLINE_VISIBILITY operator>>= (const _Expr& __v); // member functions: _LIBCPP_INLINE_VISIBILITY void swap(valarray& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_t size() const {return static_cast(__end_ - __begin_);} _LIBCPP_INLINE_VISIBILITY value_type sum() const; _LIBCPP_INLINE_VISIBILITY value_type min() const; _LIBCPP_INLINE_VISIBILITY value_type max() const; valarray shift (int __i) const; valarray cshift(int __i) const; valarray apply(value_type __f(value_type)) const; valarray apply(value_type __f(const value_type&)) const; void resize(size_t __n, value_type __x = value_type()); private: template friend class _LIBCPP_TEMPLATE_VIS valarray; template friend class _LIBCPP_TEMPLATE_VIS slice_array; template friend class _LIBCPP_TEMPLATE_VIS gslice_array; template friend class _LIBCPP_TEMPLATE_VIS mask_array; template friend class __mask_expr; template friend class _LIBCPP_TEMPLATE_VIS indirect_array; template friend class __indirect_expr; template friend class __val_expr; template friend _Up* begin(valarray<_Up>& __v); template friend const _Up* begin(const valarray<_Up>& __v); template friend _Up* end(valarray<_Up>& __v); template friend const _Up* end(const valarray<_Up>& __v); _LIBCPP_INLINE_VISIBILITY void __clear(size_t __capacity); valarray& __assign_range(const value_type* __f, const value_type* __l); }; _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray::resize(size_t, size_t)) template struct _UnaryOp<_Op, valarray<_Tp> > { typedef typename _Op::result_type result_type; typedef _Tp value_type; _Op __op_; const valarray<_Tp>& __a0_; _LIBCPP_INLINE_VISIBILITY _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {} _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; template struct _BinaryOp<_Op, valarray<_Tp>, _A1> { typedef typename _Op::result_type result_type; typedef _Tp value_type; _Op __op_; const valarray<_Tp>& __a0_; _A1 __a1_; _LIBCPP_INLINE_VISIBILITY _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1) : __op_(__op), __a0_(__a0), __a1_(__a1) {} _LIBCPP_INLINE_VISIBILITY value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; template struct _BinaryOp<_Op, _A0, valarray<_Tp> > { typedef typename _Op::result_type result_type; typedef _Tp value_type; _Op __op_; _A0 __a0_; const valarray<_Tp>& __a1_; _LIBCPP_INLINE_VISIBILITY _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1) : __op_(__op), __a0_(__a0), __a1_(__a1) {} _LIBCPP_INLINE_VISIBILITY value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; template struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > { typedef typename _Op::result_type result_type; typedef _Tp value_type; _Op __op_; const valarray<_Tp>& __a0_; const valarray<_Tp>& __a1_; _LIBCPP_INLINE_VISIBILITY _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1) : __op_(__op), __a0_(__a0), __a1_(__a1) {} _LIBCPP_INLINE_VISIBILITY value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __a0_.size();} }; // slice_array template class _LIBCPP_TEMPLATE_VIS slice_array { public: typedef _Tp value_type; private: value_type* __vp_; size_t __size_; size_t __stride_; public: template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator*=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator/=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator%=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator+=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator-=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator^=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator&=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator|=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator<<=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator>>=(const _Expr& __v) const; + slice_array(slice_array const&) = default; + _LIBCPP_INLINE_VISIBILITY const slice_array& operator=(const slice_array& __sa) const; _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; private: _LIBCPP_INLINE_VISIBILITY slice_array(const slice& __sl, const valarray& __v) : __vp_(const_cast(__v.__begin_ + __sl.start())), __size_(__sl.size()), __stride_(__sl.stride()) {} template friend class valarray; template friend class sliceExpr; }; template inline const slice_array<_Tp>& slice_array<_Tp>::operator=(const slice_array& __sa) const { value_type* __t = __vp_; const value_type* __s = __sa.__vp_; for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_) *__t = *__s; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t = __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator*=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t *= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator/=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t /= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator%=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t %= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator+=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t += __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator-=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t -= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator^=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t ^= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator&=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t &= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator|=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t |= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator<<=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t <<= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type slice_array<_Tp>::operator>>=(const _Expr& __v) const { value_type* __t = __vp_; for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) *__t >>= __v[__i]; } template inline void slice_array<_Tp>::operator=(const value_type& __x) const { value_type* __t = __vp_; for (size_t __n = __size_; __n; --__n, __t += __stride_) *__t = __x; } // gslice class _LIBCPP_TYPE_VIS gslice { valarray __size_; valarray __stride_; valarray __1d_; public: _LIBCPP_INLINE_VISIBILITY gslice() {} _LIBCPP_INLINE_VISIBILITY gslice(size_t __start, const valarray& __size, const valarray& __stride) : __size_(__size), __stride_(__stride) {__init(__start);} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY gslice(size_t __start, const valarray& __size, valarray&& __stride) : __size_(__size), __stride_(move(__stride)) {__init(__start);} _LIBCPP_INLINE_VISIBILITY gslice(size_t __start, valarray&& __size, const valarray& __stride) : __size_(move(__size)), __stride_(__stride) {__init(__start);} _LIBCPP_INLINE_VISIBILITY gslice(size_t __start, valarray&& __size, valarray&& __stride) : __size_(move(__size)), __stride_(move(__stride)) {__init(__start);} #endif // _LIBCPP_CXX03_LANG -// gslice(const gslice&) = default; -// gslice(gslice&&) = default; -// gslice& operator=(const gslice&) = default; -// gslice& operator=(gslice&&) = default; - _LIBCPP_INLINE_VISIBILITY size_t start() const {return __1d_.size() ? __1d_[0] : 0;} _LIBCPP_INLINE_VISIBILITY valarray size() const {return __size_;} _LIBCPP_INLINE_VISIBILITY valarray stride() const {return __stride_;} private: void __init(size_t __start); template friend class gslice_array; template friend class valarray; template friend class __val_expr; }; // gslice_array template class _LIBCPP_TEMPLATE_VIS gslice_array { public: typedef _Tp value_type; private: value_type* __vp_; valarray __1d_; public: template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator*=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator/=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator%=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator+=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator-=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator^=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator&=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator|=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator<<=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator>>=(const _Expr& __v) const; _LIBCPP_INLINE_VISIBILITY const gslice_array& operator=(const gslice_array& __ga) const; _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; -// gslice_array(const gslice_array&) = default; -// gslice_array(gslice_array&&) = default; -// gslice_array& operator=(const gslice_array&) = default; -// gslice_array& operator=(gslice_array&&) = default; + gslice_array(const gslice_array&) = default; private: gslice_array(const gslice& __gs, const valarray& __v) : __vp_(const_cast(__v.__begin_)), __1d_(__gs.__1d_) {} #ifndef _LIBCPP_CXX03_LANG gslice_array(gslice&& __gs, const valarray& __v) : __vp_(const_cast(__v.__begin_)), __1d_(move(__gs.__1d_)) {} #endif // _LIBCPP_CXX03_LANG template friend class valarray; }; template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] = __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator*=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] *= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator/=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] /= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator%=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] %= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator+=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] += __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator-=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] -= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator^=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] ^= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator&=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] &= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator|=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] |= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator<<=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] <<= __v[__j]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type gslice_array<_Tp>::operator>>=(const _Expr& __v) const { typedef const size_t* _Ip; size_t __j = 0; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) __vp_[*__i] >>= __v[__j]; } template inline const gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array& __ga) const { typedef const size_t* _Ip; const value_type* __s = __ga.__vp_; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; __i != __e; ++__i, ++__j) __vp_[*__i] = __s[*__j]; return *this; } template inline void gslice_array<_Tp>::operator=(const value_type& __x) const { typedef const size_t* _Ip; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) __vp_[*__i] = __x; } // mask_array template class _LIBCPP_TEMPLATE_VIS mask_array { public: typedef _Tp value_type; private: value_type* __vp_; valarray __1d_; public: template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator*=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator/=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator%=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator+=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator-=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator^=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator&=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator|=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator<<=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator>>=(const _Expr& __v) const; + mask_array(const mask_array&) = default; + _LIBCPP_INLINE_VISIBILITY const mask_array& operator=(const mask_array& __ma) const; _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; -// mask_array(const mask_array&) = default; -// mask_array(mask_array&&) = default; -// mask_array& operator=(const mask_array&) = default; -// mask_array& operator=(mask_array&&) = default; - private: _LIBCPP_INLINE_VISIBILITY mask_array(const valarray& __vb, const valarray& __v) : __vp_(const_cast(__v.__begin_)), __1d_(static_cast(count(__vb.__begin_, __vb.__end_, true))) { size_t __j = 0; for (size_t __i = 0; __i < __vb.size(); ++__i) if (__vb[__i]) __1d_[__j++] = __i; } template friend class valarray; }; template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] = __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator*=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] *= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator/=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] /= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator%=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] %= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator+=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] += __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator-=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] -= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator^=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] ^= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator&=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] &= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator|=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] |= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator<<=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] <<= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type mask_array<_Tp>::operator>>=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] >>= __v[__i]; } template inline const mask_array<_Tp>& mask_array<_Tp>::operator=(const mask_array& __ma) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; return *this; } template inline void mask_array<_Tp>::operator=(const value_type& __x) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] = __x; } template class __mask_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; public: typedef typename _RmExpr::value_type value_type; typedef value_type result_type; private: _ValExpr __expr_; valarray __1d_; _LIBCPP_INLINE_VISIBILITY __mask_expr(const valarray& __vb, const _RmExpr& __e) : __expr_(__e), __1d_(static_cast(count(__vb.__begin_, __vb.__end_, true))) { size_t __j = 0; for (size_t __i = 0; __i < __vb.size(); ++__i) if (__vb[__i]) __1d_[__j++] = __i; } public: _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __expr_[__1d_[__i]];} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __1d_.size();} template friend class __val_expr; template friend class valarray; }; // indirect_array template class _LIBCPP_TEMPLATE_VIS indirect_array { public: typedef _Tp value_type; private: value_type* __vp_; valarray __1d_; public: template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator*=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator/=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator%=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator+=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator-=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator^=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator&=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator|=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator<<=(const _Expr& __v) const; template typename enable_if < __is_val_expr<_Expr>::value, void >::type _LIBCPP_INLINE_VISIBILITY operator>>=(const _Expr& __v) const; + indirect_array(const indirect_array&) = default; + _LIBCPP_INLINE_VISIBILITY const indirect_array& operator=(const indirect_array& __ia) const; _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; - -// indirect_array(const indirect_array&) = default; -// indirect_array(indirect_array&&) = default; -// indirect_array& operator=(const indirect_array&) = default; -// indirect_array& operator=(indirect_array&&) = default; private: _LIBCPP_INLINE_VISIBILITY indirect_array(const valarray& __ia, const valarray& __v) : __vp_(const_cast(__v.__begin_)), __1d_(__ia) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY indirect_array(valarray&& __ia, const valarray& __v) : __vp_(const_cast(__v.__begin_)), __1d_(move(__ia)) {} #endif // _LIBCPP_CXX03_LANG template friend class valarray; }; template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] = __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator*=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] *= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator/=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] /= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator%=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] %= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator+=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] += __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator-=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] -= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator^=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] ^= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator&=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] &= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator|=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] |= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator<<=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] <<= __v[__i]; } template template inline typename enable_if < __is_val_expr<_Expr>::value, void >::type indirect_array<_Tp>::operator>>=(const _Expr& __v) const { size_t __n = __1d_.size(); for (size_t __i = 0; __i < __n; ++__i) __vp_[__1d_[__i]] >>= __v[__i]; } template inline const indirect_array<_Tp>& indirect_array<_Tp>::operator=(const indirect_array& __ia) const { typedef const size_t* _Ip; const value_type* __s = __ia.__vp_; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; __i != __e; ++__i, ++__j) __vp_[*__i] = __s[*__j]; return *this; } template inline void indirect_array<_Tp>::operator=(const value_type& __x) const { typedef const size_t* _Ip; for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) __vp_[*__i] = __x; } template class __indirect_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; public: typedef typename _RmExpr::value_type value_type; typedef value_type result_type; private: _ValExpr __expr_; valarray __1d_; _LIBCPP_INLINE_VISIBILITY __indirect_expr(const valarray& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __indirect_expr(valarray&& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(move(__ia)) {} #endif // _LIBCPP_CXX03_LANG public: _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __expr_[__1d_[__i]];} _LIBCPP_INLINE_VISIBILITY size_t size() const {return __1d_.size();} template friend class __val_expr; template friend class _LIBCPP_TEMPLATE_VIS valarray; }; template class __val_expr { typedef typename remove_reference<_ValExpr>::type _RmExpr; _ValExpr __expr_; public: typedef typename _RmExpr::value_type value_type; typedef typename _RmExpr::result_type result_type; _LIBCPP_INLINE_VISIBILITY explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {} _LIBCPP_INLINE_VISIBILITY result_type operator[](size_t __i) const {return __expr_[__i];} _LIBCPP_INLINE_VISIBILITY __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const { typedef __slice_expr<_ValExpr> _NewExpr; return __val_expr< _NewExpr >(_NewExpr(__s, __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const { typedef __indirect_expr<_ValExpr> _NewExpr; return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr<_ValExpr> > operator[](const valarray& __vb) const { typedef __mask_expr<_ValExpr> _NewExpr; return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray& __vs) const { typedef __indirect_expr<_ValExpr> _NewExpr; return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp<__unary_plus, _ValExpr> > operator+() const { typedef _UnaryOp<__unary_plus, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(__unary_plus(), __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp, _ValExpr> > operator-() const { typedef _UnaryOp, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(negate(), __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp<__bit_not, _ValExpr> > operator~() const { typedef _UnaryOp<__bit_not, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(__bit_not(), __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp, _ValExpr> > operator!() const { typedef _UnaryOp, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(logical_not(), __expr_)); } operator valarray() const; _LIBCPP_INLINE_VISIBILITY size_t size() const {return __expr_.size();} _LIBCPP_INLINE_VISIBILITY result_type sum() const { size_t __n = __expr_.size(); result_type __r = __n ? __expr_[0] : result_type(); for (size_t __i = 1; __i < __n; ++__i) __r += __expr_[__i]; return __r; } _LIBCPP_INLINE_VISIBILITY result_type min() const { size_t __n = size(); result_type __r = __n ? (*this)[0] : result_type(); for (size_t __i = 1; __i < __n; ++__i) { result_type __x = __expr_[__i]; if (__x < __r) __r = __x; } return __r; } _LIBCPP_INLINE_VISIBILITY result_type max() const { size_t __n = size(); result_type __r = __n ? (*this)[0] : result_type(); for (size_t __i = 1; __i < __n; ++__i) { result_type __x = __expr_[__i]; if (__r < __x) __r = __x; } return __r; } _LIBCPP_INLINE_VISIBILITY __val_expr<__shift_expr<_ValExpr> > shift (int __i) const {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));} _LIBCPP_INLINE_VISIBILITY __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));} _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp<__apply_expr, _ValExpr> > apply(value_type __f(value_type)) const { typedef __apply_expr _Op; typedef _UnaryOp<_Op, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp<__apply_expr, _ValExpr> > apply(value_type __f(const value_type&)) const { typedef __apply_expr _Op; typedef _UnaryOp<_Op, _ValExpr> _NewExpr; return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); } }; template __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const { valarray __r; size_t __n = __expr_.size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type))); for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) ::new (__r.__end_) result_type(__expr_[__i]); } return __r; } // valarray template inline valarray<_Tp>::valarray(size_t __n) : __begin_(0), __end_(0) { if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) ::new (__end_) value_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template inline valarray<_Tp>::valarray(const value_type& __x, size_t __n) : __begin_(0), __end_(0) { resize(__n, __x); } template valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(0), __end_(0) { if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) ::new (__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template valarray<_Tp>::valarray(const valarray& __v) : __begin_(0), __end_(0) { if (__v.size()) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) ::new (__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__v.size()); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } #ifndef _LIBCPP_CXX03_LANG template inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) { __v.__begin_ = __v.__end_ = nullptr; } template valarray<_Tp>::valarray(initializer_list __il) : __begin_(0), __end_(0) { const size_t __n = __il.size(); if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS size_t __n_left = __n; for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) ::new (__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } #endif // _LIBCPP_CXX03_LANG template valarray<_Tp>::valarray(const slice_array& __sa) : __begin_(0), __end_(0) { const size_t __n = __sa.__size_; if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS size_t __n_left = __n; for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) ::new (__end_) value_type(*__p); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template valarray<_Tp>::valarray(const gslice_array& __ga) : __begin_(0), __end_(0) { const size_t __n = __ga.__1d_.size(); if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typedef const size_t* _Ip; const value_type* __s = __ga.__vp_; for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_) ::new (__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template valarray<_Tp>::valarray(const mask_array& __ma) : __begin_(0), __end_(0) { const size_t __n = __ma.__1d_.size(); if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typedef const size_t* _Ip; const value_type* __s = __ma.__vp_; for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_) ::new (__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template valarray<_Tp>::valarray(const indirect_array& __ia) : __begin_(0), __end_(0) { const size_t __n = __ia.__1d_.size(); if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typedef const size_t* _Ip; const value_type* __s = __ia.__vp_; for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_) ::new (__end_) value_type(__s[*__i]); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template inline valarray<_Tp>::~valarray() { __clear(size()); } template valarray<_Tp>& valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) { size_t __n = __l - __f; if (size() != __n) { __clear(size()); __begin_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); __end_ = __begin_ + __n; _VSTD::uninitialized_copy(__f, __l, __begin_); } else { _VSTD::copy(__f, __l, __begin_); } return *this; } template valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) { if (this != &__v) return __assign_range(__v.__begin_, __v.__end_); return *this; } #ifndef _LIBCPP_CXX03_LANG template inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT { __clear(size()); __begin_ = __v.__begin_; __end_ = __v.__end_; __v.__begin_ = nullptr; __v.__end_ = nullptr; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list __il) { return __assign_range(__il.begin(), __il.end()); } #endif // _LIBCPP_CXX03_LANG template inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) { _VSTD::fill(__begin_, __end_, __x); return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator=(const slice_array& __sa) { value_type* __t = __begin_; const value_type* __s = __sa.__vp_; for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) *__t = *__s; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array& __ga) { typedef const size_t* _Ip; value_type* __t = __begin_; const value_type* __s = __ga.__vp_; for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__t) *__t = __s[*__i]; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array& __ma) { typedef const size_t* _Ip; value_type* __t = __begin_; const value_type* __s = __ma.__vp_; for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__t) *__t = __s[*__i]; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array& __ia) { typedef const size_t* _Ip; value_type* __t = __begin_; const value_type* __s = __ia.__vp_; for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__t) *__t = __s[*__i]; return *this; } template template inline valarray<_Tp>& valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) { size_t __n = __v.size(); if (size() != __n) resize(__n); value_type* __t = __begin_; for (size_t __i = 0; __i != __n; ++__t, ++__i) *__t = result_type(__v[__i]); return *this; } template inline __val_expr<__slice_expr&> > valarray<_Tp>::operator[](slice __s) const { return __val_expr<__slice_expr >(__slice_expr(__s, *this)); } template inline slice_array<_Tp> valarray<_Tp>::operator[](slice __s) { return slice_array(__s, *this); } template inline __val_expr<__indirect_expr&> > valarray<_Tp>::operator[](const gslice& __gs) const { return __val_expr<__indirect_expr >(__indirect_expr(__gs.__1d_, *this)); } template inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) { return gslice_array(__gs, *this); } #ifndef _LIBCPP_CXX03_LANG template inline __val_expr<__indirect_expr&> > valarray<_Tp>::operator[](gslice&& __gs) const { return __val_expr<__indirect_expr >(__indirect_expr(move(__gs.__1d_), *this)); } template inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) { return gslice_array(move(__gs), *this); } #endif // _LIBCPP_CXX03_LANG template inline __val_expr<__mask_expr&> > valarray<_Tp>::operator[](const valarray& __vb) const { return __val_expr<__mask_expr >(__mask_expr(__vb, *this)); } template inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray& __vb) { return mask_array(__vb, *this); } #ifndef _LIBCPP_CXX03_LANG template inline __val_expr<__mask_expr&> > valarray<_Tp>::operator[](valarray&& __vb) const { return __val_expr<__mask_expr >(__mask_expr(move(__vb), *this)); } template inline mask_array<_Tp> valarray<_Tp>::operator[](valarray&& __vb) { return mask_array(move(__vb), *this); } #endif // _LIBCPP_CXX03_LANG template inline __val_expr<__indirect_expr&> > valarray<_Tp>::operator[](const valarray& __vs) const { return __val_expr<__indirect_expr >(__indirect_expr(__vs, *this)); } template inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray& __vs) { return indirect_array(__vs, *this); } #ifndef _LIBCPP_CXX03_LANG template inline __val_expr<__indirect_expr&> > valarray<_Tp>::operator[](valarray&& __vs) const { return __val_expr<__indirect_expr >(__indirect_expr(move(__vs), *this)); } template inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray&& __vs) { return indirect_array(move(__vs), *this); } #endif // _LIBCPP_CXX03_LANG template valarray<_Tp> valarray<_Tp>::operator+() const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) value_type(+*__p); } return __r; } template valarray<_Tp> valarray<_Tp>::operator-() const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) value_type(-*__p); } return __r; } template valarray<_Tp> valarray<_Tp>::operator~() const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) value_type(~*__p); } return __r; } template valarray valarray<_Tp>::operator!() const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) bool(!*__p); } return __r; } template inline valarray<_Tp>& valarray<_Tp>::operator*=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p *= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator/=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p /= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator%=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p %= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator+=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p += __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator-=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p -= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator^=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p ^= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator&=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p &= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator|=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p |= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator<<=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p <<= __x; return *this; } template inline valarray<_Tp>& valarray<_Tp>::operator>>=(const value_type& __x) { for (value_type* __p = __begin_; __p != __end_; ++__p) *__p >>= __x; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator*=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t *= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator/=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t /= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator%=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t %= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator+=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t += __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator-=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t -= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator^=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t ^= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator|=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t |= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator&=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t &= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator<<=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t <<= __v[__i]; return *this; } template template inline typename enable_if < __is_val_expr<_Expr>::value, valarray<_Tp>& >::type valarray<_Tp>::operator>>=(const _Expr& __v) { size_t __i = 0; for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) *__t >>= __v[__i]; return *this; } template inline void valarray<_Tp>::swap(valarray& __v) _NOEXCEPT { _VSTD::swap(__begin_, __v.__begin_); _VSTD::swap(__end_, __v.__end_); } template inline _Tp valarray<_Tp>::sum() const { if (__begin_ == __end_) return value_type(); const value_type* __p = __begin_; _Tp __r = *__p; for (++__p; __p != __end_; ++__p) __r += *__p; return __r; } template inline _Tp valarray<_Tp>::min() const { if (__begin_ == __end_) return value_type(); return *_VSTD::min_element(__begin_, __end_); } template inline _Tp valarray<_Tp>::max() const { if (__begin_ == __end_) return value_type(); return *_VSTD::max_element(__begin_, __end_); } template valarray<_Tp> valarray<_Tp>::shift(int __i) const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); const value_type* __sb; value_type* __tb; value_type* __te; if (__i >= 0) { __i = _VSTD::min(__i, static_cast(__n)); __sb = __begin_ + __i; __tb = __r.__begin_; __te = __r.__begin_ + (__n - __i); } else { __i = _VSTD::min(-__i, static_cast(__n)); __sb = __begin_; __tb = __r.__begin_ + __i; __te = __r.__begin_ + __n; } for (; __r.__end_ != __tb; ++__r.__end_) ::new (__r.__end_) value_type(); for (; __r.__end_ != __te; ++__r.__end_, ++__sb) ::new (__r.__end_) value_type(*__sb); for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) ::new (__r.__end_) value_type(); } return __r; } template valarray<_Tp> valarray<_Tp>::cshift(int __i) const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); __i %= static_cast(__n); const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) ::new (__r.__end_) value_type(*__s); for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) ::new (__r.__end_) value_type(*__s); } return __r; } template valarray<_Tp> valarray<_Tp>::apply(value_type __f(value_type)) const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) value_type(__f(*__p)); } return __r; } template valarray<_Tp> valarray<_Tp>::apply(value_type __f(const value_type&)) const { valarray __r; size_t __n = size(); if (__n) { __r.__begin_ = __r.__end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) ::new (__r.__end_) value_type(__f(*__p)); } return __r; } template inline void valarray<_Tp>::__clear(size_t __capacity) { if (__begin_ != nullptr) { while (__end_ != __begin_) (--__end_)->~value_type(); _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)); __begin_ = __end_ = nullptr; } } template void valarray<_Tp>::resize(size_t __n, value_type __x) { __clear(size()); if (__n) { __begin_ = __end_ = static_cast( _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type))); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) ::new (__end_) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __clear(__n); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } } template inline _LIBCPP_INLINE_VISIBILITY void swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT { __x.swap(__y); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator*(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(multiplies(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator*(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(multiplies(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator*(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(multiplies(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator/(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(divides(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator/(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(divides(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator/(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(divides(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator%(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(modulus(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator%(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(modulus(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator%(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(modulus(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator+(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(plus(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator+(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(plus(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator+(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(plus(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator-(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(minus(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator-(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(minus(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator-(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(minus(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator^(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(bit_xor(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator^(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(bit_xor(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator^(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(bit_xor(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator&(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(bit_and(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator&(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(bit_and(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator&(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(bit_and(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator|(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(bit_or(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator|(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(bit_or(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator|(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(bit_or(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp<__bit_shift_left, _Expr1, _Expr2> > >::type operator<<(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp<__bit_shift_left, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(__bit_shift_left(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__bit_shift_left, _Expr, __scalar_expr > > >::type operator<<(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__bit_shift_left, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(__bit_shift_left(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__bit_shift_left, __scalar_expr, _Expr> > >::type operator<<(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__bit_shift_left, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__bit_shift_left(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp<__bit_shift_right, _Expr1, _Expr2> > >::type operator>>(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp<__bit_shift_right, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(__bit_shift_right(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__bit_shift_right, _Expr, __scalar_expr > > >::type operator>>(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__bit_shift_right, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(__bit_shift_right(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__bit_shift_right, __scalar_expr, _Expr> > >::type operator>>(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__bit_shift_right, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__bit_shift_right(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator&&(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(logical_and(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator&&(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(logical_and(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator&&(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(logical_and(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator||(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(logical_or(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator||(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(logical_or(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator||(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(logical_or(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator==(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(equal_to(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator==(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(equal_to(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator==(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(equal_to(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator!=(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(not_equal_to(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator!=(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(not_equal_to(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator!=(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(not_equal_to(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator<(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(less(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator<(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(less(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator<(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(less(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator>(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(greater(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator>(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(greater(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator>(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(greater(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator<=(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(less_equal(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator<=(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(less_equal(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator<=(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(less_equal(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp, _Expr1, _Expr2> > >::type operator>=(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(greater_equal(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, _Expr, __scalar_expr > > >::type operator>=(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(greater_equal(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp, __scalar_expr, _Expr> > >::type operator>=(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(greater_equal(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__abs_expr, _Expr> > >::type abs(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__abs_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__abs_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__acos_expr, _Expr> > >::type acos(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__acos_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__acos_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__asin_expr, _Expr> > >::type asin(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__asin_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__asin_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__atan_expr, _Expr> > >::type atan(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__atan_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__atan_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp<__atan2_expr, _Expr1, _Expr2> > >::type atan2(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp<__atan2_expr, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(__atan2_expr(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__atan2_expr, _Expr, __scalar_expr > > >::type atan2(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__atan2_expr, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(__atan2_expr(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__atan2_expr, __scalar_expr, _Expr> > >::type atan2(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__atan2_expr, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__atan2_expr(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__cos_expr, _Expr> > >::type cos(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__cos_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__cos_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__cosh_expr, _Expr> > >::type cosh(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__cosh_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__cosh_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__exp_expr, _Expr> > >::type exp(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__exp_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__exp_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__log_expr, _Expr> > >::type log(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__log_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__log_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__log10_expr, _Expr> > >::type log10(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__log10_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__log10_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, __val_expr<_BinaryOp<__pow_expr, _Expr1, _Expr2> > >::type pow(const _Expr1& __x, const _Expr2& __y) { typedef typename _Expr1::value_type value_type; typedef _BinaryOp<__pow_expr, _Expr1, _Expr2> _Op; return __val_expr<_Op>(_Op(__pow_expr(), __x, __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__pow_expr, _Expr, __scalar_expr > > >::type pow(const _Expr& __x, const typename _Expr::value_type& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__pow_expr, _Expr, __scalar_expr > _Op; return __val_expr<_Op>(_Op(__pow_expr(), __x, __scalar_expr(__y, __x.size()))); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_BinaryOp<__pow_expr, __scalar_expr, _Expr> > >::type pow(const typename _Expr::value_type& __x, const _Expr& __y) { typedef typename _Expr::value_type value_type; typedef _BinaryOp<__pow_expr, __scalar_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__pow_expr(), __scalar_expr(__x, __y.size()), __y)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__sin_expr, _Expr> > >::type sin(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__sin_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__sin_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__sinh_expr, _Expr> > >::type sinh(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__sinh_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__sinh_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__sqrt_expr, _Expr> > >::type sqrt(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__sqrt_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__sqrt_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__tan_expr, _Expr> > >::type tan(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__tan_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__tan_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_val_expr<_Expr>::value, __val_expr<_UnaryOp<__tanh_expr, _Expr> > >::type tanh(const _Expr& __x) { typedef typename _Expr::value_type value_type; typedef _UnaryOp<__tanh_expr, _Expr> _Op; return __val_expr<_Op>(_Op(__tanh_expr(), __x)); } template inline _LIBCPP_INLINE_VISIBILITY _Tp* begin(valarray<_Tp>& __v) { return __v.__begin_; } template inline _LIBCPP_INLINE_VISIBILITY const _Tp* begin(const valarray<_Tp>& __v) { return __v.__begin_; } template inline _LIBCPP_INLINE_VISIBILITY _Tp* end(valarray<_Tp>& __v) { return __v.__end_; } template inline _LIBCPP_INLINE_VISIBILITY const _Tp* end(const valarray<_Tp>& __v) { return __v.__end_; } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_VALARRAY Index: stable/12/contrib/llvm-project/libcxx =================================================================== --- stable/12/contrib/llvm-project/libcxx (revision 356465) +++ stable/12/contrib/llvm-project/libcxx (revision 356466) Property changes on: stable/12/contrib/llvm-project/libcxx ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/contrib/llvm-project/libcxx:r356005 Index: stable/12 =================================================================== --- stable/12 (revision 356465) +++ stable/12 (revision 356466) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r356005