brintos

brintos / llvm-project-archived public Read only

0
0
Text · 25.7 KiB · 2392568 Raw
830 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H10#define _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H11 12#include <__cxx03/__algorithm/equal.h>13#include <__cxx03/__algorithm/min.h>14#include <__cxx03/__config>15#include <__cxx03/__random/is_seed_sequence.h>16#include <__cxx03/cstddef>17#include <__cxx03/cstdint>18#include <__cxx03/iosfwd>19#include <__cxx03/limits>20 21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22#  pragma GCC system_header23#endif24 25_LIBCPP_PUSH_MACROS26#include <__cxx03/__undef_macros>27 28_LIBCPP_BEGIN_NAMESPACE_STD29 30template <class _UIntType,31          size_t __w,32          size_t __n,33          size_t __m,34          size_t __r,35          _UIntType __a,36          size_t __u,37          _UIntType __d,38          size_t __s,39          _UIntType __b,40          size_t __t,41          _UIntType __c,42          size_t __l,43          _UIntType __f>44class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;45 46template <class _UInt,47          size_t _Wp,48          size_t _Np,49          size_t _Mp,50          size_t _Rp,51          _UInt _Ap,52          size_t _Up,53          _UInt _Dp,54          size_t _Sp,55          _UInt _Bp,56          size_t _Tp,57          _UInt _Cp,58          size_t _Lp,59          _UInt _Fp>60_LIBCPP_HIDE_FROM_ABI bool61operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,62           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);63 64template <class _UInt,65          size_t _Wp,66          size_t _Np,67          size_t _Mp,68          size_t _Rp,69          _UInt _Ap,70          size_t _Up,71          _UInt _Dp,72          size_t _Sp,73          _UInt _Bp,74          size_t _Tp,75          _UInt _Cp,76          size_t _Lp,77          _UInt _Fp>78_LIBCPP_HIDE_FROM_ABI bool79operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,80           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);81 82template <class _CharT,83          class _Traits,84          class _UInt,85          size_t _Wp,86          size_t _Np,87          size_t _Mp,88          size_t _Rp,89          _UInt _Ap,90          size_t _Up,91          _UInt _Dp,92          size_t _Sp,93          _UInt _Bp,94          size_t _Tp,95          _UInt _Cp,96          size_t _Lp,97          _UInt _Fp>98_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&99operator<<(basic_ostream<_CharT, _Traits>& __os,100           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);101 102template <class _CharT,103          class _Traits,104          class _UInt,105          size_t _Wp,106          size_t _Np,107          size_t _Mp,108          size_t _Rp,109          _UInt _Ap,110          size_t _Up,111          _UInt _Dp,112          size_t _Sp,113          _UInt _Bp,114          size_t _Tp,115          _UInt _Cp,116          size_t _Lp,117          _UInt _Fp>118_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&119operator>>(basic_istream<_CharT, _Traits>& __is,120           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);121 122template <class _UIntType,123          size_t __w,124          size_t __n,125          size_t __m,126          size_t __r,127          _UIntType __a,128          size_t __u,129          _UIntType __d,130          size_t __s,131          _UIntType __b,132          size_t __t,133          _UIntType __c,134          size_t __l,135          _UIntType __f>136class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine {137public:138  // types139  typedef _UIntType result_type;140 141private:142  result_type __x_[__n];143  size_t __i_;144 145  static_assert(0 < __m, "mersenne_twister_engine invalid parameters");146  static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");147  static const result_type _Dt = numeric_limits<result_type>::digits;148  static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");149  static_assert(2 <= __w, "mersenne_twister_engine invalid parameters");150  static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");151  static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");152  static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");153  static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");154  static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");155 156public:157  static const result_type _Min = 0;158  static const result_type _Max = __w == _Dt ? result_type(~0) : (result_type(1) << __w) - result_type(1);159  static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");160  static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");161  static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");162  static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");163  static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");164  static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");165 166  // engine characteristics167  static const size_t word_size                      = __w;168  static const size_t state_size                     = __n;169  static const size_t shift_size                     = __m;170  static const size_t mask_bits                      = __r;171  static const result_type xor_mask                  = __a;172  static const size_t tempering_u                    = __u;173  static const result_type tempering_d               = __d;174  static const size_t tempering_s                    = __s;175  static const result_type tempering_b               = __b;176  static const size_t tempering_t                    = __t;177  static const result_type tempering_c               = __c;178  static const size_t tempering_l                    = __l;179  static const result_type initialization_multiplier = __f;180  _LIBCPP_HIDE_FROM_ABI static result_type min() { return _Min; }181  _LIBCPP_HIDE_FROM_ABI static result_type max() { return _Max; }182  static const result_type default_seed = 5489u;183 184  // constructors and seeding functions185  _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(result_type __sd = default_seed) { seed(__sd); }186  template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>187  _LIBCPP_HIDE_FROM_ABI explicit mersenne_twister_engine(_Sseq& __q) {188    seed(__q);189  }190  _LIBCPP_HIDE_FROM_ABI void seed(result_type __sd = default_seed);191  template <class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>192  _LIBCPP_HIDE_FROM_ABI void seed(_Sseq& __q) {193    __seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());194  }195 196  // generating functions197  _LIBCPP_HIDE_FROM_ABI result_type operator()();198  _LIBCPP_HIDE_FROM_ABI void discard(unsigned long long __z) {199    for (; __z; --__z)200      operator()();201  }202 203  template <class _UInt,204            size_t _Wp,205            size_t _Np,206            size_t _Mp,207            size_t _Rp,208            _UInt _Ap,209            size_t _Up,210            _UInt _Dp,211            size_t _Sp,212            _UInt _Bp,213            size_t _Tp,214            _UInt _Cp,215            size_t _Lp,216            _UInt _Fp>217  friend bool operator==(218      const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,219      const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);220 221  template <class _UInt,222            size_t _Wp,223            size_t _Np,224            size_t _Mp,225            size_t _Rp,226            _UInt _Ap,227            size_t _Up,228            _UInt _Dp,229            size_t _Sp,230            _UInt _Bp,231            size_t _Tp,232            _UInt _Cp,233            size_t _Lp,234            _UInt _Fp>235  friend bool operator!=(236      const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,237      const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y);238 239  template <class _CharT,240            class _Traits,241            class _UInt,242            size_t _Wp,243            size_t _Np,244            size_t _Mp,245            size_t _Rp,246            _UInt _Ap,247            size_t _Up,248            _UInt _Dp,249            size_t _Sp,250            _UInt _Bp,251            size_t _Tp,252            _UInt _Cp,253            size_t _Lp,254            _UInt _Fp>255  friend basic_ostream<_CharT, _Traits>& operator<<(256      basic_ostream<_CharT, _Traits>& __os,257      const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);258 259  template <class _CharT,260            class _Traits,261            class _UInt,262            size_t _Wp,263            size_t _Np,264            size_t _Mp,265            size_t _Rp,266            _UInt _Ap,267            size_t _Up,268            _UInt _Dp,269            size_t _Sp,270            _UInt _Bp,271            size_t _Tp,272            _UInt _Cp,273            size_t _Lp,274            _UInt _Fp>275  friend basic_istream<_CharT, _Traits>&276  operator>>(basic_istream<_CharT, _Traits>& __is,277             mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x);278 279private:280  template <class _Sseq>281  _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 1>);282  template <class _Sseq>283  _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 2>);284 285  template <size_t __count,286            __enable_if_t<__count< __w, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type __x) {287    return (__x << __count) & _Max;288  }289 290  template <size_t __count, __enable_if_t<(__count >= __w), int> = 0>291  _LIBCPP_HIDE_FROM_ABI static result_type __lshift(result_type) {292    return result_type(0);293  }294 295  template <size_t __count,296            __enable_if_t<__count< _Dt, int> = 0> _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type __x) {297    return __x >> __count;298  }299 300  template <size_t __count, __enable_if_t<(__count >= _Dt), int> = 0>301  _LIBCPP_HIDE_FROM_ABI static result_type __rshift(result_type) {302    return result_type(0);303  }304};305 306template <class _UIntType,307          size_t __w,308          size_t __n,309          size_t __m,310          size_t __r,311          _UIntType __a,312          size_t __u,313          _UIntType __d,314          size_t __s,315          _UIntType __b,316          size_t __t,317          _UIntType __c,318          size_t __l,319          _UIntType __f>320const size_t321    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;322 323template <class _UIntType,324          size_t __w,325          size_t __n,326          size_t __m,327          size_t __r,328          _UIntType __a,329          size_t __u,330          _UIntType __d,331          size_t __s,332          _UIntType __b,333          size_t __t,334          _UIntType __c,335          size_t __l,336          _UIntType __f>337const size_t338    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;339 340template <class _UIntType,341          size_t __w,342          size_t __n,343          size_t __m,344          size_t __r,345          _UIntType __a,346          size_t __u,347          _UIntType __d,348          size_t __s,349          _UIntType __b,350          size_t __t,351          _UIntType __c,352          size_t __l,353          _UIntType __f>354const size_t355    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;356 357template <class _UIntType,358          size_t __w,359          size_t __n,360          size_t __m,361          size_t __r,362          _UIntType __a,363          size_t __u,364          _UIntType __d,365          size_t __s,366          _UIntType __b,367          size_t __t,368          _UIntType __c,369          size_t __l,370          _UIntType __f>371const size_t372    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;373 374template <class _UIntType,375          size_t __w,376          size_t __n,377          size_t __m,378          size_t __r,379          _UIntType __a,380          size_t __u,381          _UIntType __d,382          size_t __s,383          _UIntType __b,384          size_t __t,385          _UIntType __c,386          size_t __l,387          _UIntType __f>388const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::389    result_type390        mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;391 392template <class _UIntType,393          size_t __w,394          size_t __n,395          size_t __m,396          size_t __r,397          _UIntType __a,398          size_t __u,399          _UIntType __d,400          size_t __s,401          _UIntType __b,402          size_t __t,403          _UIntType __c,404          size_t __l,405          _UIntType __f>406const size_t407    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;408 409template <class _UIntType,410          size_t __w,411          size_t __n,412          size_t __m,413          size_t __r,414          _UIntType __a,415          size_t __u,416          _UIntType __d,417          size_t __s,418          _UIntType __b,419          size_t __t,420          _UIntType __c,421          size_t __l,422          _UIntType __f>423const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::424    result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::425        tempering_d;426 427template <class _UIntType,428          size_t __w,429          size_t __n,430          size_t __m,431          size_t __r,432          _UIntType __a,433          size_t __u,434          _UIntType __d,435          size_t __s,436          _UIntType __b,437          size_t __t,438          _UIntType __c,439          size_t __l,440          _UIntType __f>441const size_t442    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;443 444template <class _UIntType,445          size_t __w,446          size_t __n,447          size_t __m,448          size_t __r,449          _UIntType __a,450          size_t __u,451          _UIntType __d,452          size_t __s,453          _UIntType __b,454          size_t __t,455          _UIntType __c,456          size_t __l,457          _UIntType __f>458const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::459    result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::460        tempering_b;461 462template <class _UIntType,463          size_t __w,464          size_t __n,465          size_t __m,466          size_t __r,467          _UIntType __a,468          size_t __u,469          _UIntType __d,470          size_t __s,471          _UIntType __b,472          size_t __t,473          _UIntType __c,474          size_t __l,475          _UIntType __f>476const size_t477    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;478 479template <class _UIntType,480          size_t __w,481          size_t __n,482          size_t __m,483          size_t __r,484          _UIntType __a,485          size_t __u,486          _UIntType __d,487          size_t __s,488          _UIntType __b,489          size_t __t,490          _UIntType __c,491          size_t __l,492          _UIntType __f>493const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::494    result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::495        tempering_c;496 497template <class _UIntType,498          size_t __w,499          size_t __n,500          size_t __m,501          size_t __r,502          _UIntType __a,503          size_t __u,504          _UIntType __d,505          size_t __s,506          _UIntType __b,507          size_t __t,508          _UIntType __c,509          size_t __l,510          _UIntType __f>511const size_t512    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;513 514template <class _UIntType,515          size_t __w,516          size_t __n,517          size_t __m,518          size_t __r,519          _UIntType __a,520          size_t __u,521          _UIntType __d,522          size_t __s,523          _UIntType __b,524          size_t __t,525          _UIntType __c,526          size_t __l,527          _UIntType __f>528const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::529    result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::530        initialization_multiplier;531 532template <class _UIntType,533          size_t __w,534          size_t __n,535          size_t __m,536          size_t __r,537          _UIntType __a,538          size_t __u,539          _UIntType __d,540          size_t __s,541          _UIntType __b,542          size_t __t,543          _UIntType __c,544          size_t __l,545          _UIntType __f>546const typename mersenne_twister_engine< _UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::547    result_type mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::548        default_seed;549 550template <class _UIntType,551          size_t __w,552          size_t __n,553          size_t __m,554          size_t __r,555          _UIntType __a,556          size_t __u,557          _UIntType __d,558          size_t __s,559          _UIntType __b,560          size_t __t,561          _UIntType __c,562          size_t __l,563          _UIntType __f>564void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(565    result_type __sd) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2566  __x_[0] = __sd & _Max;567  for (size_t __i = 1; __i < __n; ++__i)568    __x_[__i] = (__f * (__x_[__i - 1] ^ __rshift<__w - 2>(__x_[__i - 1])) + __i) & _Max;569  __i_ = 0;570}571 572template <class _UIntType,573          size_t __w,574          size_t __n,575          size_t __m,576          size_t __r,577          _UIntType __a,578          size_t __u,579          _UIntType __d,580          size_t __s,581          _UIntType __b,582          size_t __t,583          _UIntType __c,584          size_t __l,585          _UIntType __f>586template <class _Sseq>587void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(588    _Sseq& __q, integral_constant<unsigned, 1>) {589  const unsigned __k = 1;590  uint32_t __ar[__n * __k];591  __q.generate(__ar, __ar + __n * __k);592  for (size_t __i = 0; __i < __n; ++__i)593    __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);594  const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);595  __i_                     = 0;596  if ((__x_[0] & ~__mask) == 0) {597    for (size_t __i = 1; __i < __n; ++__i)598      if (__x_[__i] != 0)599        return;600    __x_[0] = result_type(1) << (__w - 1);601  }602}603 604template <class _UIntType,605          size_t __w,606          size_t __n,607          size_t __m,608          size_t __r,609          _UIntType __a,610          size_t __u,611          _UIntType __d,612          size_t __s,613          _UIntType __b,614          size_t __t,615          _UIntType __c,616          size_t __l,617          _UIntType __f>618template <class _Sseq>619void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::__seed(620    _Sseq& __q, integral_constant<unsigned, 2>) {621  const unsigned __k = 2;622  uint32_t __ar[__n * __k];623  __q.generate(__ar, __ar + __n * __k);624  for (size_t __i = 0; __i < __n; ++__i)625    __x_[__i] = static_cast<result_type>((__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);626  const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);627  __i_                     = 0;628  if ((__x_[0] & ~__mask) == 0) {629    for (size_t __i = 1; __i < __n; ++__i)630      if (__x_[__i] != 0)631        return;632    __x_[0] = result_type(1) << (__w - 1);633  }634}635 636template <class _UIntType,637          size_t __w,638          size_t __n,639          size_t __m,640          size_t __r,641          _UIntType __a,642          size_t __u,643          _UIntType __d,644          size_t __s,645          _UIntType __b,646          size_t __t,647          _UIntType __c,648          size_t __l,649          _UIntType __f>650_UIntType651mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() {652  const size_t __j         = (__i_ + 1) % __n;653  const result_type __mask = __r == _Dt ? result_type(~0) : (result_type(1) << __r) - result_type(1);654  const result_type __yp   = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);655  const size_t __k         = (__i_ + __m) % __n;656  __x_[__i_]               = __x_[__k] ^ __rshift<1>(__yp) ^ (__a * (__yp & 1));657  result_type __z          = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);658  __i_                     = __j;659  __z ^= __lshift<__s>(__z) & __b;660  __z ^= __lshift<__t>(__z) & __c;661  return __z ^ __rshift<__l>(__z);662}663 664template <class _UInt,665          size_t _Wp,666          size_t _Np,667          size_t _Mp,668          size_t _Rp,669          _UInt _Ap,670          size_t _Up,671          _UInt _Dp,672          size_t _Sp,673          _UInt _Bp,674          size_t _Tp,675          _UInt _Cp,676          size_t _Lp,677          _UInt _Fp>678_LIBCPP_HIDE_FROM_ABI bool679operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,680           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {681  if (__x.__i_ == __y.__i_)682    return std::equal(__x.__x_, __x.__x_ + _Np, __y.__x_);683  if (__x.__i_ == 0 || __y.__i_ == 0) {684    size_t __j = std::min(_Np - __x.__i_, _Np - __y.__i_);685    if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, __y.__x_ + __y.__i_))686      return false;687    if (__x.__i_ == 0)688      return std::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_);689    return std::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j);690  }691  if (__x.__i_ < __y.__i_) {692    size_t __j = _Np - __y.__i_;693    if (!std::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), __y.__x_ + __y.__i_))694      return false;695    if (!std::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, __y.__x_))696      return false;697    return std::equal(__x.__x_, __x.__x_ + __x.__i_, __y.__x_ + (_Np - (__x.__i_ + __j)));698  }699  size_t __j = _Np - __x.__i_;700  if (!std::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), __x.__x_ + __x.__i_))701    return false;702  if (!std::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, __x.__x_))703    return false;704  return std::equal(__y.__x_, __y.__x_ + __y.__i_, __x.__x_ + (_Np - (__y.__i_ + __j)));705}706 707template <class _UInt,708          size_t _Wp,709          size_t _Np,710          size_t _Mp,711          size_t _Rp,712          _UInt _Ap,713          size_t _Up,714          _UInt _Dp,715          size_t _Sp,716          _UInt _Bp,717          size_t _Tp,718          _UInt _Cp,719          size_t _Lp,720          _UInt _Fp>721inline _LIBCPP_HIDE_FROM_ABI bool722operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x,723           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) {724  return !(__x == __y);725}726 727template <class _CharT,728          class _Traits,729          class _UInt,730          size_t _Wp,731          size_t _Np,732          size_t _Mp,733          size_t _Rp,734          _UInt _Ap,735          size_t _Up,736          _UInt _Dp,737          size_t _Sp,738          _UInt _Bp,739          size_t _Tp,740          _UInt _Cp,741          size_t _Lp,742          _UInt _Fp>743_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&744operator<<(basic_ostream<_CharT, _Traits>& __os,745           const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {746  __save_flags<_CharT, _Traits> __lx(__os);747  typedef basic_ostream<_CharT, _Traits> _Ostream;748  __os.flags(_Ostream::dec | _Ostream::left);749  _CharT __sp = __os.widen(' ');750  __os.fill(__sp);751  __os << __x.__x_[__x.__i_];752  for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j)753    __os << __sp << __x.__x_[__j];754  for (size_t __j = 0; __j < __x.__i_; ++__j)755    __os << __sp << __x.__x_[__j];756  return __os;757}758 759template <class _CharT,760          class _Traits,761          class _UInt,762          size_t _Wp,763          size_t _Np,764          size_t _Mp,765          size_t _Rp,766          _UInt _Ap,767          size_t _Up,768          _UInt _Dp,769          size_t _Sp,770          _UInt _Bp,771          size_t _Tp,772          _UInt _Cp,773          size_t _Lp,774          _UInt _Fp>775_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&776operator>>(basic_istream<_CharT, _Traits>& __is,777           mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) {778  __save_flags<_CharT, _Traits> __lx(__is);779  typedef basic_istream<_CharT, _Traits> _Istream;780  __is.flags(_Istream::dec | _Istream::skipws);781  _UInt __t[_Np];782  for (size_t __i = 0; __i < _Np; ++__i)783    __is >> __t[__i];784  if (!__is.fail()) {785    for (size_t __i = 0; __i < _Np; ++__i)786      __x.__x_[__i] = __t[__i];787    __x.__i_ = 0;788  }789  return __is;790}791 792typedef mersenne_twister_engine<793    uint_fast32_t,794    32,795    624,796    397,797    31,798    0x9908b0df,799    11,800    0xffffffff,801    7,802    0x9d2c5680,803    15,804    0xefc60000,805    18,806    1812433253>807    mt19937;808typedef mersenne_twister_engine<809    uint_fast64_t,810    64,811    312,812    156,813    31,814    0xb5026f5aa96619e9ULL,815    29,816    0x5555555555555555ULL,817    17,818    0x71d67fffeda60000ULL,819    37,820    0xfff7eee000000000ULL,821    43,822    6364136223846793005ULL>823    mt19937_64;824 825_LIBCPP_END_NAMESPACE_STD826 827_LIBCPP_POP_MACROS828 829#endif // _LIBCPP___CXX03___RANDOM_MERSENNE_TWISTER_ENGINE_H830