| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
 | 2 | //===--------------------------- random -----------------------------------===// | 
 | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
 | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // | 
 | 9 | //===----------------------------------------------------------------------===// | 
 | 10 |  | 
 | 11 | #ifndef _LIBCPP_RANDOM | 
 | 12 | #define _LIBCPP_RANDOM | 
 | 13 |  | 
 | 14 | /* | 
 | 15 |     random synopsis | 
 | 16 |  | 
 | 17 | #include <initializer_list> | 
 | 18 |  | 
 | 19 | namespace std | 
 | 20 | { | 
 | 21 |  | 
 | 22 | // Engines | 
 | 23 |  | 
 | 24 | template <class UIntType, UIntType a, UIntType c, UIntType m> | 
 | 25 | class linear_congruential_engine | 
 | 26 | { | 
 | 27 | public: | 
 | 28 |     // types | 
 | 29 |     typedef UIntType result_type; | 
 | 30 |  | 
 | 31 |     // engine characteristics | 
 | 32 |     static constexpr result_type multiplier = a; | 
 | 33 |     static constexpr result_type increment = c; | 
 | 34 |     static constexpr result_type modulus = m; | 
 | 35 |     static constexpr result_type min() { return c == 0u ? 1u: 0u;} | 
 | 36 |     static constexpr result_type max() { return m - 1u;} | 
 | 37 |     static constexpr result_type default_seed = 1u; | 
 | 38 |  | 
 | 39 |     // constructors and seeding functions | 
 | 40 |     explicit linear_congruential_engine(result_type s = default_seed); | 
 | 41 |     template<class Sseq> explicit linear_congruential_engine(Sseq& q); | 
 | 42 |     void seed(result_type s = default_seed); | 
 | 43 |     template<class Sseq> void seed(Sseq& q); | 
 | 44 |  | 
 | 45 |     // generating functions | 
 | 46 |     result_type operator()(); | 
 | 47 |     void discard(unsigned long long z); | 
 | 48 | }; | 
 | 49 |  | 
 | 50 | template <class UIntType, UIntType a, UIntType c, UIntType m> | 
 | 51 | bool | 
 | 52 | operator==(const linear_congruential_engine<UIntType, a, c, m>& x, | 
 | 53 |            const linear_congruential_engine<UIntType, a, c, m>& y); | 
 | 54 |  | 
 | 55 | template <class UIntType, UIntType a, UIntType c, UIntType m> | 
 | 56 | bool | 
 | 57 | operator!=(const linear_congruential_engine<UIntType, a, c, m>& x, | 
 | 58 |            const linear_congruential_engine<UIntType, a, c, m>& y); | 
 | 59 |  | 
 | 60 | template <class charT, class traits, | 
 | 61 |           class UIntType, UIntType a, UIntType c, UIntType m> | 
 | 62 | basic_ostream<charT, traits>& | 
 | 63 | operator<<(basic_ostream<charT, traits>& os, | 
 | 64 |            const linear_congruential_engine<UIntType, a, c, m>& x); | 
 | 65 |  | 
 | 66 | template <class charT, class traits, | 
 | 67 |           class UIntType, UIntType a, UIntType c, UIntType m> | 
 | 68 | basic_istream<charT, traits>& | 
 | 69 | operator>>(basic_istream<charT, traits>& is, | 
 | 70 |            linear_congruential_engine<UIntType, a, c, m>& x); | 
 | 71 |  | 
 | 72 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, | 
 | 73 |           UIntType a, size_t u, UIntType d, size_t s, | 
 | 74 |           UIntType b, size_t t, UIntType c, size_t l, UIntType f> | 
 | 75 | class mersenne_twister_engine | 
 | 76 | { | 
 | 77 | public: | 
 | 78 |     // types | 
 | 79 |     typedef UIntType result_type; | 
 | 80 |  | 
 | 81 |     // engine characteristics | 
 | 82 |     static constexpr size_t word_size = w; | 
 | 83 |     static constexpr size_t state_size = n; | 
 | 84 |     static constexpr size_t shift_size = m; | 
 | 85 |     static constexpr size_t mask_bits = r; | 
 | 86 |     static constexpr result_type xor_mask = a; | 
 | 87 |     static constexpr size_t tempering_u = u; | 
 | 88 |     static constexpr result_type tempering_d = d; | 
 | 89 |     static constexpr size_t tempering_s = s; | 
 | 90 |     static constexpr result_type tempering_b = b; | 
 | 91 |     static constexpr size_t tempering_t = t; | 
 | 92 |     static constexpr result_type tempering_c = c; | 
 | 93 |     static constexpr size_t tempering_l = l; | 
 | 94 |     static constexpr result_type initialization_multiplier = f; | 
 | 95 |     static constexpr result_type min () { return 0; } | 
 | 96 |     static constexpr result_type max() { return 2^w - 1; } | 
 | 97 |     static constexpr result_type default_seed = 5489u; | 
 | 98 |  | 
 | 99 |     // constructors and seeding functions | 
 | 100 |     explicit mersenne_twister_engine(result_type value = default_seed); | 
 | 101 |     template<class Sseq> explicit mersenne_twister_engine(Sseq& q); | 
 | 102 |     void seed(result_type value = default_seed); | 
 | 103 |     template<class Sseq> void seed(Sseq& q); | 
 | 104 |  | 
 | 105 |     // generating functions | 
 | 106 |     result_type operator()(); | 
 | 107 |     void discard(unsigned long long z); | 
 | 108 | }; | 
 | 109 |  | 
 | 110 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, | 
 | 111 |           UIntType a, size_t u, UIntType d, size_t s, | 
 | 112 |           UIntType b, size_t t, UIntType c, size_t l, UIntType f> | 
 | 113 | bool | 
 | 114 | operator==( | 
 | 115 |     const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, | 
 | 116 |     const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); | 
 | 117 |  | 
 | 118 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, | 
 | 119 |           UIntType a, size_t u, UIntType d, size_t s, | 
 | 120 |           UIntType b, size_t t, UIntType c, size_t l, UIntType f> | 
 | 121 | bool | 
 | 122 | operator!=( | 
 | 123 |     const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, | 
 | 124 |     const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); | 
 | 125 |  | 
 | 126 | template <class charT, class traits, | 
 | 127 |           class UIntType, size_t w, size_t n, size_t m, size_t r, | 
 | 128 |           UIntType a, size_t u, UIntType d, size_t s, | 
 | 129 |           UIntType b, size_t t, UIntType c, size_t l, UIntType f> | 
 | 130 | basic_ostream<charT, traits>& | 
 | 131 | operator<<(basic_ostream<charT, traits>& os, | 
 | 132 |            const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); | 
 | 133 |  | 
 | 134 | template <class charT, class traits, | 
 | 135 |           class UIntType, size_t w, size_t n, size_t m, size_t r, | 
 | 136 |           UIntType a, size_t u, UIntType d, size_t s, | 
 | 137 |           UIntType b, size_t t, UIntType c, size_t l, UIntType f> | 
 | 138 | basic_istream<charT, traits>& | 
 | 139 | operator>>(basic_istream<charT, traits>& is, | 
 | 140 |            mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); | 
 | 141 |  | 
 | 142 | template<class UIntType, size_t w, size_t s, size_t r> | 
 | 143 | class subtract_with_carry_engine | 
 | 144 | { | 
 | 145 | public: | 
 | 146 |     // types | 
 | 147 |     typedef UIntType result_type; | 
 | 148 |  | 
 | 149 |     // engine characteristics | 
 | 150 |     static constexpr size_t word_size = w; | 
 | 151 |     static constexpr size_t short_lag = s; | 
 | 152 |     static constexpr size_t long_lag = r; | 
 | 153 |     static constexpr result_type min() { return 0; } | 
 | 154 |     static constexpr result_type max() { return m-1; } | 
 | 155 |     static constexpr result_type default_seed = 19780503u; | 
 | 156 |  | 
 | 157 |     // constructors and seeding functions | 
 | 158 |     explicit subtract_with_carry_engine(result_type value = default_seed); | 
 | 159 |     template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); | 
 | 160 |     void seed(result_type value = default_seed); | 
 | 161 |     template<class Sseq> void seed(Sseq& q); | 
 | 162 |  | 
 | 163 |     // generating functions | 
 | 164 |     result_type operator()(); | 
 | 165 |     void discard(unsigned long long z); | 
 | 166 | }; | 
 | 167 |  | 
 | 168 | template<class UIntType, size_t w, size_t s, size_t r> | 
 | 169 | bool | 
 | 170 | operator==( | 
 | 171 |     const subtract_with_carry_engine<UIntType, w, s, r>& x, | 
 | 172 |     const subtract_with_carry_engine<UIntType, w, s, r>& y); | 
 | 173 |  | 
 | 174 | template<class UIntType, size_t w, size_t s, size_t r> | 
 | 175 | bool | 
 | 176 | operator!=( | 
 | 177 |     const subtract_with_carry_engine<UIntType, w, s, r>& x, | 
 | 178 |     const subtract_with_carry_engine<UIntType, w, s, r>& y); | 
 | 179 |  | 
 | 180 | template <class charT, class traits, | 
 | 181 |           class UIntType, size_t w, size_t s, size_t r> | 
 | 182 | basic_ostream<charT, traits>& | 
 | 183 | operator<<(basic_ostream<charT, traits>& os, | 
 | 184 |            const subtract_with_carry_engine<UIntType, w, s, r>& x); | 
 | 185 |  | 
 | 186 | template <class charT, class traits, | 
 | 187 |           class UIntType, size_t w, size_t s, size_t r> | 
 | 188 | basic_istream<charT, traits>& | 
 | 189 | operator>>(basic_istream<charT, traits>& is, | 
 | 190 |            subtract_with_carry_engine<UIntType, w, s, r>& x); | 
 | 191 |  | 
 | 192 | template<class Engine, size_t p, size_t r> | 
 | 193 | class discard_block_engine | 
 | 194 | { | 
 | 195 | public: | 
 | 196 |     // types | 
 | 197 |     typedef typename Engine::result_type result_type; | 
 | 198 |  | 
 | 199 |     // engine characteristics | 
 | 200 |     static constexpr size_t block_size = p; | 
 | 201 |     static constexpr size_t used_block = r; | 
 | 202 |     static constexpr result_type min() { return Engine::min(); } | 
 | 203 |     static constexpr result_type max() { return Engine::max(); } | 
 | 204 |  | 
 | 205 |     // constructors and seeding functions | 
 | 206 |     discard_block_engine(); | 
 | 207 |     explicit discard_block_engine(const Engine& e); | 
 | 208 |     explicit discard_block_engine(Engine&& e); | 
 | 209 |     explicit discard_block_engine(result_type s); | 
 | 210 |     template<class Sseq> explicit discard_block_engine(Sseq& q); | 
 | 211 |     void seed(); | 
 | 212 |     void seed(result_type s); | 
 | 213 |     template<class Sseq> void seed(Sseq& q); | 
 | 214 |  | 
 | 215 |     // generating functions | 
 | 216 |     result_type operator()(); | 
 | 217 |     void discard(unsigned long long z); | 
 | 218 |  | 
 | 219 |     // property functions | 
 | 220 |     const Engine& base() const; | 
 | 221 | }; | 
 | 222 |  | 
 | 223 | template<class Engine, size_t p, size_t r> | 
 | 224 | bool | 
 | 225 | operator==( | 
 | 226 |     const discard_block_engine<Engine, p, r>& x, | 
 | 227 |     const discard_block_engine<Engine, p, r>& y); | 
 | 228 |  | 
 | 229 | template<class Engine, size_t p, size_t r> | 
 | 230 | bool | 
 | 231 | operator!=( | 
 | 232 |     const discard_block_engine<Engine, p, r>& x, | 
 | 233 |     const discard_block_engine<Engine, p, r>& y); | 
 | 234 |  | 
 | 235 | template <class charT, class traits, | 
 | 236 |           class Engine, size_t p, size_t r> | 
 | 237 | basic_ostream<charT, traits>& | 
 | 238 | operator<<(basic_ostream<charT, traits>& os, | 
 | 239 |            const discard_block_engine<Engine, p, r>& x); | 
 | 240 |  | 
 | 241 | template <class charT, class traits, | 
 | 242 |           class Engine, size_t p, size_t r> | 
 | 243 | basic_istream<charT, traits>& | 
 | 244 | operator>>(basic_istream<charT, traits>& is, | 
 | 245 |            discard_block_engine<Engine, p, r>& x); | 
 | 246 |  | 
 | 247 | template<class Engine, size_t w, class UIntType> | 
 | 248 | class independent_bits_engine | 
 | 249 | { | 
 | 250 | public: | 
 | 251 |     // types | 
 | 252 |     typedef UIntType result_type; | 
 | 253 |  | 
 | 254 |     // engine characteristics | 
 | 255 |     static constexpr result_type min() { return 0; } | 
 | 256 |     static constexpr result_type max() { return 2^w - 1; } | 
 | 257 |  | 
 | 258 |     // constructors and seeding functions | 
 | 259 |     independent_bits_engine(); | 
 | 260 |     explicit independent_bits_engine(const Engine& e); | 
 | 261 |     explicit independent_bits_engine(Engine&& e); | 
 | 262 |     explicit independent_bits_engine(result_type s); | 
 | 263 |     template<class Sseq> explicit independent_bits_engine(Sseq& q); | 
 | 264 |     void seed(); | 
 | 265 |     void seed(result_type s); | 
 | 266 |     template<class Sseq> void seed(Sseq& q); | 
 | 267 |  | 
 | 268 |     // generating functions | 
 | 269 |     result_type operator()(); void discard(unsigned long long z); | 
 | 270 |  | 
 | 271 |     // property functions | 
 | 272 |     const Engine& base() const; | 
 | 273 | }; | 
 | 274 |  | 
 | 275 | template<class Engine, size_t w, class UIntType> | 
 | 276 | bool | 
 | 277 | operator==( | 
 | 278 |     const independent_bits_engine<Engine, w, UIntType>& x, | 
 | 279 |     const independent_bits_engine<Engine, w, UIntType>& y); | 
 | 280 |  | 
 | 281 | template<class Engine, size_t w, class UIntType> | 
 | 282 | bool | 
 | 283 | operator!=( | 
 | 284 |     const independent_bits_engine<Engine, w, UIntType>& x, | 
 | 285 |     const independent_bits_engine<Engine, w, UIntType>& y); | 
 | 286 |  | 
 | 287 | template <class charT, class traits, | 
 | 288 |           class Engine, size_t w, class UIntType> | 
 | 289 | basic_ostream<charT, traits>& | 
 | 290 | operator<<(basic_ostream<charT, traits>& os, | 
 | 291 |            const independent_bits_engine<Engine, w, UIntType>& x); | 
 | 292 |  | 
 | 293 | template <class charT, class traits, | 
 | 294 |           class Engine, size_t w, class UIntType> | 
 | 295 | basic_istream<charT, traits>& | 
 | 296 | operator>>(basic_istream<charT, traits>& is, | 
 | 297 |            independent_bits_engine<Engine, w, UIntType>& x); | 
 | 298 |  | 
 | 299 | template<class Engine, size_t k> | 
 | 300 | class shuffle_order_engine | 
 | 301 | { | 
 | 302 | public: | 
 | 303 |     // types | 
 | 304 |     typedef typename Engine::result_type result_type; | 
 | 305 |  | 
 | 306 |     // engine characteristics | 
 | 307 |     static constexpr size_t table_size = k; | 
 | 308 |     static constexpr result_type min() { return Engine::min; } | 
 | 309 |     static constexpr result_type max() { return Engine::max; } | 
 | 310 |  | 
 | 311 |     // constructors and seeding functions | 
 | 312 |     shuffle_order_engine(); | 
 | 313 |     explicit shuffle_order_engine(const Engine& e); | 
 | 314 |     explicit shuffle_order_engine(Engine&& e); | 
 | 315 |     explicit shuffle_order_engine(result_type s); | 
 | 316 |     template<class Sseq> explicit shuffle_order_engine(Sseq& q); | 
 | 317 |     void seed(); | 
 | 318 |     void seed(result_type s); | 
 | 319 |     template<class Sseq> void seed(Sseq& q); | 
 | 320 |  | 
 | 321 |     // generating functions | 
 | 322 |     result_type operator()(); | 
 | 323 |     void discard(unsigned long long z); | 
 | 324 |  | 
 | 325 |     // property functions | 
 | 326 |     const Engine& base() const; | 
 | 327 | }; | 
 | 328 |  | 
 | 329 | template<class Engine, size_t k> | 
 | 330 | bool | 
 | 331 | operator==( | 
 | 332 |     const shuffle_order_engine<Engine, k>& x, | 
 | 333 |     const shuffle_order_engine<Engine, k>& y); | 
 | 334 |  | 
 | 335 | template<class Engine, size_t k> | 
 | 336 | bool | 
 | 337 | operator!=( | 
 | 338 |     const shuffle_order_engine<Engine, k>& x, | 
 | 339 |     const shuffle_order_engine<Engine, k>& y); | 
 | 340 |  | 
 | 341 | template <class charT, class traits, | 
 | 342 |           class Engine, size_t k> | 
 | 343 | basic_ostream<charT, traits>& | 
 | 344 | operator<<(basic_ostream<charT, traits>& os, | 
 | 345 |            const shuffle_order_engine<Engine, k>& x); | 
 | 346 |  | 
 | 347 | template <class charT, class traits, | 
 | 348 |           class Engine, size_t k> | 
 | 349 | basic_istream<charT, traits>& | 
 | 350 | operator>>(basic_istream<charT, traits>& is, | 
 | 351 |            shuffle_order_engine<Engine, k>& x); | 
 | 352 |  | 
 | 353 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> | 
 | 354 |                                                                    minstd_rand0; | 
 | 355 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> | 
 | 356 |                                                                     minstd_rand; | 
 | 357 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, | 
 | 358 |                                 0x9908b0df, | 
 | 359 |                                 11, 0xffffffff, | 
 | 360 |                                 7,  0x9d2c5680, | 
 | 361 |                                 15, 0xefc60000, | 
 | 362 |                                 18, 1812433253>                         mt19937; | 
 | 363 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, | 
 | 364 |                                 0xb5026f5aa96619e9, | 
 | 365 |                                 29, 0x5555555555555555, | 
 | 366 |                                 17, 0x71d67fffeda60000, | 
 | 367 |                                 37, 0xfff7eee000000000, | 
 | 368 |                                 43, 6364136223846793005>             mt19937_64; | 
 | 369 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base; | 
 | 370 | typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base; | 
 | 371 | typedef discard_block_engine<ranlux24_base, 223, 23>                   ranlux24; | 
 | 372 | typedef discard_block_engine<ranlux48_base, 389, 11>                   ranlux48; | 
 | 373 | typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 374 | typedef minstd_rand                                       default_random_engine; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 |  | 
 | 376 | // Generators | 
 | 377 |  | 
 | 378 | class random_device | 
 | 379 | { | 
 | 380 | public: | 
 | 381 |     // types | 
 | 382 |     typedef unsigned int result_type; | 
 | 383 |  | 
 | 384 |     // generator characteristics | 
 | 385 |     static constexpr result_type min() { return numeric_limits<result_type>::min(); } | 
 | 386 |     static constexpr result_type max() { return numeric_limits<result_type>::max(); } | 
 | 387 |  | 
 | 388 |     // constructors | 
 | 389 |     explicit random_device(const string& token = "/dev/urandom"); | 
 | 390 |  | 
 | 391 |     // generating functions | 
 | 392 |     result_type operator()(); | 
 | 393 |  | 
 | 394 |     // property functions | 
 | 395 |     double entropy() const; | 
 | 396 |  | 
 | 397 |     // no copy functions | 
 | 398 |     random_device(const random_device& ) = delete; | 
 | 399 |     void operator=(const random_device& ) = delete; | 
 | 400 | }; | 
 | 401 |  | 
 | 402 | // Utilities | 
 | 403 |  | 
 | 404 | class seed_seq | 
 | 405 | { | 
 | 406 | public: | 
 | 407 |     // types | 
 | 408 |     typedef uint_least32_t result_type; | 
 | 409 |  | 
 | 410 |     // constructors | 
 | 411 |     seed_seq(); | 
 | 412 |     template<class T> | 
 | 413 |         seed_seq(initializer_list<T> il); | 
 | 414 |     template<class InputIterator> | 
 | 415 |         seed_seq(InputIterator begin, InputIterator end); | 
 | 416 |  | 
 | 417 |     // generating functions | 
 | 418 |     template<class RandomAccessIterator> | 
 | 419 |         void generate(RandomAccessIterator begin, RandomAccessIterator end); | 
 | 420 |  | 
 | 421 |     // property functions | 
 | 422 |     size_t size() const; | 
 | 423 |     template<class OutputIterator> | 
 | 424 |         void param(OutputIterator dest) const; | 
 | 425 |  | 
 | 426 |     // no copy functions | 
 | 427 |     seed_seq(const seed_seq&) = delete; | 
 | 428 |     void operator=(const seed_seq& ) = delete; | 
 | 429 | }; | 
 | 430 |  | 
 | 431 | template<class RealType, size_t bits, class URNG> | 
 | 432 |     RealType generate_canonical(URNG& g); | 
 | 433 |  | 
 | 434 | // Distributions | 
 | 435 |  | 
 | 436 | template<class IntType = int> | 
 | 437 | class uniform_int_distribution | 
 | 438 | { | 
 | 439 | public: | 
 | 440 |     // types | 
 | 441 |     typedef IntType result_type; | 
 | 442 |  | 
 | 443 |     class param_type | 
 | 444 |     { | 
 | 445 |     public: | 
 | 446 |         typedef uniform_int_distribution distribution_type; | 
 | 447 |  | 
 | 448 |         explicit param_type(IntType a = 0, | 
 | 449 |                                     IntType b = numeric_limits<IntType>::max()); | 
 | 450 |  | 
 | 451 |         result_type a() const; | 
 | 452 |         result_type b() const; | 
 | 453 |  | 
 | 454 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 455 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 456 |     }; | 
 | 457 |  | 
 | 458 |     // constructors and reset functions | 
 | 459 |     explicit uniform_int_distribution(IntType a = 0, | 
 | 460 |                                     IntType b = numeric_limits<IntType>::max()); | 
 | 461 |     explicit uniform_int_distribution(const param_type& parm); | 
 | 462 |     void reset(); | 
 | 463 |  | 
 | 464 |     // generating functions | 
 | 465 |     template<class URNG> result_type operator()(URNG& g); | 
 | 466 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 467 |  | 
 | 468 |     // property functions | 
 | 469 |     result_type a() const; | 
 | 470 |     result_type b() const; | 
 | 471 |  | 
 | 472 |     param_type param() const; | 
 | 473 |     void param(const param_type& parm); | 
 | 474 |  | 
 | 475 |     result_type min() const; | 
 | 476 |     result_type max() const; | 
 | 477 |  | 
 | 478 |     friend bool operator==(const uniform_int_distribution& x, | 
 | 479 |                            const uniform_int_distribution& y); | 
 | 480 |     friend bool operator!=(const uniform_int_distribution& x, | 
 | 481 |                            const uniform_int_distribution& y); | 
 | 482 |  | 
 | 483 |     template <class charT, class traits> | 
 | 484 |     friend | 
 | 485 |     basic_ostream<charT, traits>& | 
 | 486 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 487 |                const uniform_int_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 488 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 |     template <class charT, class traits> | 
 | 490 |     friend | 
 | 491 |     basic_istream<charT, traits>& | 
 | 492 |     operator>>(basic_istream<charT, traits>& is, | 
 | 493 |                uniform_int_distribution& x); | 
 | 494 | }; | 
 | 495 |  | 
 | 496 | template<class RealType = double> | 
 | 497 | class uniform_real_distribution | 
 | 498 | { | 
 | 499 | public: | 
 | 500 |     // types | 
 | 501 |     typedef RealType result_type; | 
 | 502 |  | 
 | 503 |     class param_type | 
 | 504 |     { | 
 | 505 |     public: | 
 | 506 |         typedef uniform_real_distribution distribution_type; | 
 | 507 |  | 
 | 508 |         explicit param_type(RealType a = 0, | 
 | 509 |                             RealType b = 1); | 
 | 510 |  | 
 | 511 |         result_type a() const; | 
 | 512 |         result_type b() const; | 
 | 513 |  | 
 | 514 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 515 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 516 |     }; | 
 | 517 |  | 
 | 518 |     // constructors and reset functions | 
 | 519 |     explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); | 
 | 520 |     explicit uniform_real_distribution(const param_type& parm); | 
 | 521 |     void reset(); | 
 | 522 |  | 
 | 523 |     // generating functions | 
 | 524 |     template<class URNG> result_type operator()(URNG& g); | 
 | 525 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 526 |  | 
 | 527 |     // property functions | 
 | 528 |     result_type a() const; | 
 | 529 |     result_type b() const; | 
 | 530 |  | 
 | 531 |     param_type param() const; | 
 | 532 |     void param(const param_type& parm); | 
 | 533 |  | 
 | 534 |     result_type min() const; | 
 | 535 |     result_type max() const; | 
 | 536 |  | 
 | 537 |     friend bool operator==(const uniform_real_distribution& x, | 
 | 538 |                            const uniform_real_distribution& y); | 
 | 539 |     friend bool operator!=(const uniform_real_distribution& x, | 
 | 540 |                            const uniform_real_distribution& y); | 
 | 541 |  | 
 | 542 |     template <class charT, class traits> | 
 | 543 |     friend | 
 | 544 |     basic_ostream<charT, traits>& | 
 | 545 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 546 |                const uniform_real_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 547 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 |     template <class charT, class traits> | 
 | 549 |     friend | 
 | 550 |     basic_istream<charT, traits>& | 
 | 551 |     operator>>(basic_istream<charT, traits>& is, | 
 | 552 |                uniform_real_distribution& x); | 
 | 553 | }; | 
 | 554 |  | 
 | 555 | class bernoulli_distribution | 
 | 556 | { | 
 | 557 | public: | 
 | 558 |     // types | 
 | 559 |     typedef bool result_type; | 
 | 560 |  | 
 | 561 |     class param_type | 
 | 562 |     { | 
 | 563 |     public: | 
 | 564 |         typedef bernoulli_distribution distribution_type; | 
 | 565 |  | 
 | 566 |         explicit param_type(double p = 0.5); | 
 | 567 |  | 
 | 568 |         double p() const; | 
 | 569 |  | 
 | 570 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 571 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 572 |     }; | 
 | 573 |  | 
 | 574 |     // constructors and reset functions | 
 | 575 |     explicit bernoulli_distribution(double p = 0.5); | 
 | 576 |     explicit bernoulli_distribution(const param_type& parm); | 
 | 577 |     void reset(); | 
 | 578 |  | 
 | 579 |     // generating functions | 
 | 580 |     template<class URNG> result_type operator()(URNG& g); | 
 | 581 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 582 |  | 
 | 583 |     // property functions | 
 | 584 |     double p() const; | 
 | 585 |  | 
 | 586 |     param_type param() const; | 
 | 587 |     void param(const param_type& parm); | 
 | 588 |  | 
 | 589 |     result_type min() const; | 
 | 590 |     result_type max() const; | 
 | 591 |  | 
 | 592 |     friend bool operator==(const bernoulli_distribution& x, | 
 | 593 |                            const bernoulli_distribution& y); | 
 | 594 |     friend bool operator!=(const bernoulli_distribution& x, | 
 | 595 |                            const bernoulli_distribution& y); | 
 | 596 |  | 
 | 597 |     template <class charT, class traits> | 
 | 598 |     friend | 
 | 599 |     basic_ostream<charT, traits>& | 
 | 600 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 601 |                const bernoulli_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 602 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 |     template <class charT, class traits> | 
 | 604 |     friend | 
 | 605 |     basic_istream<charT, traits>& | 
 | 606 |     operator>>(basic_istream<charT, traits>& is, | 
 | 607 |                bernoulli_distribution& x); | 
 | 608 | }; | 
 | 609 |  | 
 | 610 | template<class IntType = int> | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 611 | class binomial_distribution | 
 | 612 | { | 
 | 613 | public: | 
 | 614 |     // types | 
 | 615 |     typedef IntType result_type; | 
 | 616 |  | 
 | 617 |     class param_type | 
 | 618 |     { | 
 | 619 |     public: | 
 | 620 |         typedef binomial_distribution distribution_type; | 
 | 621 |  | 
 | 622 |         explicit param_type(IntType t = 1, double p = 0.5); | 
 | 623 |  | 
 | 624 |         IntType t() const; | 
 | 625 |         double p() const; | 
 | 626 |  | 
 | 627 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 628 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 629 |     }; | 
 | 630 |  | 
 | 631 |     // constructors and reset functions | 
 | 632 |     explicit binomial_distribution(IntType t = 1, double p = 0.5); | 
 | 633 |     explicit binomial_distribution(const param_type& parm); | 
 | 634 |     void reset(); | 
 | 635 |  | 
 | 636 |     // generating functions | 
 | 637 |     template<class URNG> result_type operator()(URNG& g); | 
 | 638 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 639 |  | 
 | 640 |     // property functions | 
 | 641 |     IntType t() const; | 
 | 642 |     double p() const; | 
 | 643 |  | 
 | 644 |     param_type param() const; | 
 | 645 |     void param(const param_type& parm); | 
 | 646 |  | 
 | 647 |     result_type min() const; | 
 | 648 |     result_type max() const; | 
 | 649 |  | 
 | 650 |     friend bool operator==(const binomial_distribution& x, | 
 | 651 |                            const binomial_distribution& y); | 
 | 652 |     friend bool operator!=(const binomial_distribution& x, | 
 | 653 |                            const binomial_distribution& y); | 
 | 654 |  | 
 | 655 |     template <class charT, class traits> | 
 | 656 |     friend | 
 | 657 |     basic_ostream<charT, traits>& | 
 | 658 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 659 |                const binomial_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 660 |  | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 661 |     template <class charT, class traits> | 
 | 662 |     friend | 
 | 663 |     basic_istream<charT, traits>& | 
 | 664 |     operator>>(basic_istream<charT, traits>& is, | 
 | 665 |                binomial_distribution& x); | 
 | 666 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 |  | 
 | 668 | template<class IntType = int> | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 669 | class geometric_distribution | 
 | 670 | { | 
 | 671 | public: | 
 | 672 |     // types | 
 | 673 |     typedef IntType result_type; | 
 | 674 |  | 
 | 675 |     class param_type | 
 | 676 |     { | 
 | 677 |     public: | 
 | 678 |         typedef geometric_distribution distribution_type; | 
 | 679 |  | 
 | 680 |         explicit param_type(double p = 0.5); | 
 | 681 |  | 
 | 682 |         double p() const; | 
 | 683 |  | 
 | 684 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 685 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 686 |     }; | 
 | 687 |  | 
 | 688 |     // constructors and reset functions | 
 | 689 |     explicit geometric_distribution(double p = 0.5); | 
 | 690 |     explicit geometric_distribution(const param_type& parm); | 
 | 691 |     void reset(); | 
 | 692 |  | 
 | 693 |     // generating functions | 
 | 694 |     template<class URNG> result_type operator()(URNG& g); | 
 | 695 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 696 |  | 
 | 697 |     // property functions | 
 | 698 |     double p() const; | 
 | 699 |  | 
 | 700 |     param_type param() const; | 
 | 701 |     void param(const param_type& parm); | 
 | 702 |  | 
 | 703 |     result_type min() const; | 
 | 704 |     result_type max() const; | 
 | 705 |  | 
 | 706 |     friend bool operator==(const geometric_distribution& x, | 
 | 707 |                            const geometric_distribution& y); | 
 | 708 |     friend bool operator!=(const geometric_distribution& x, | 
 | 709 |                            const geometric_distribution& y); | 
 | 710 |  | 
 | 711 |     template <class charT, class traits> | 
 | 712 |     friend | 
 | 713 |     basic_ostream<charT, traits>& | 
 | 714 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 715 |                const geometric_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 716 |  | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 717 |     template <class charT, class traits> | 
 | 718 |     friend | 
 | 719 |     basic_istream<charT, traits>& | 
 | 720 |     operator>>(basic_istream<charT, traits>& is, | 
 | 721 |                geometric_distribution& x); | 
 | 722 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 |  | 
 | 724 | template<class IntType = int> | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 725 | class negative_binomial_distribution | 
 | 726 | { | 
 | 727 | public: | 
 | 728 |     // types | 
 | 729 |     typedef IntType result_type; | 
 | 730 |  | 
 | 731 |     class param_type | 
 | 732 |     { | 
 | 733 |     public: | 
 | 734 |         typedef negative_binomial_distribution distribution_type; | 
 | 735 |  | 
 | 736 |         explicit param_type(result_type k = 1, double p = 0.5); | 
 | 737 |  | 
 | 738 |         result_type k() const; | 
 | 739 |         double p() const; | 
 | 740 |  | 
 | 741 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 742 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 743 |     }; | 
 | 744 |  | 
 | 745 |     // constructor and reset functions | 
 | 746 |     explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); | 
 | 747 |     explicit negative_binomial_distribution(const param_type& parm); | 
 | 748 |     void reset(); | 
 | 749 |  | 
 | 750 |     // generating functions | 
 | 751 |     template<class URNG> result_type operator()(URNG& g); | 
 | 752 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 753 |  | 
 | 754 |     // property functions | 
 | 755 |     result_type k() const; | 
 | 756 |     double p() const; | 
 | 757 |  | 
 | 758 |     param_type param() const; | 
 | 759 |     void param(const param_type& parm); | 
 | 760 |  | 
 | 761 |     result_type min() const; | 
 | 762 |     result_type max() const; | 
 | 763 |  | 
 | 764 |     friend bool operator==(const negative_binomial_distribution& x, | 
 | 765 |                            const negative_binomial_distribution& y); | 
 | 766 |     friend bool operator!=(const negative_binomial_distribution& x, | 
 | 767 |                            const negative_binomial_distribution& y); | 
 | 768 |  | 
 | 769 |     template <class charT, class traits> | 
 | 770 |     friend | 
 | 771 |     basic_ostream<charT, traits>& | 
 | 772 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 773 |                const negative_binomial_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 774 |  | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 775 |     template <class charT, class traits> | 
 | 776 |     friend | 
 | 777 |     basic_istream<charT, traits>& | 
 | 778 |     operator>>(basic_istream<charT, traits>& is, | 
 | 779 |                negative_binomial_distribution& x); | 
 | 780 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 781 |  | 
 | 782 | template<class IntType = int> | 
| Howard Hinnant | 4ff556c | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 783 | class poisson_distribution | 
 | 784 | { | 
 | 785 | public: | 
 | 786 |     // types | 
 | 787 |     typedef IntType result_type; | 
 | 788 |  | 
 | 789 |     class param_type | 
 | 790 |     { | 
 | 791 |     public: | 
 | 792 |         typedef poisson_distribution distribution_type; | 
 | 793 |  | 
 | 794 |         explicit param_type(double mean = 1.0); | 
 | 795 |  | 
 | 796 |         double mean() const; | 
 | 797 |  | 
 | 798 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 799 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 800 |     }; | 
 | 801 |  | 
 | 802 |     // constructors and reset functions | 
 | 803 |     explicit poisson_distribution(double mean = 1.0); | 
 | 804 |     explicit poisson_distribution(const param_type& parm); | 
 | 805 |     void reset(); | 
 | 806 |  | 
 | 807 |     // generating functions | 
 | 808 |     template<class URNG> result_type operator()(URNG& g); | 
 | 809 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 810 |  | 
 | 811 |     // property functions | 
 | 812 |     double mean() const; | 
 | 813 |  | 
 | 814 |     param_type param() const; | 
 | 815 |     void param(const param_type& parm); | 
 | 816 |  | 
 | 817 |     result_type min() const; | 
 | 818 |     result_type max() const; | 
 | 819 |  | 
 | 820 |     friend bool operator==(const poisson_distribution& x, | 
 | 821 |                            const poisson_distribution& y); | 
 | 822 |     friend bool operator!=(const poisson_distribution& x, | 
 | 823 |                            const poisson_distribution& y); | 
 | 824 |  | 
 | 825 |     template <class charT, class traits> | 
 | 826 |     friend | 
 | 827 |     basic_ostream<charT, traits>& | 
 | 828 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 829 |                const poisson_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 830 |  | 
| Howard Hinnant | 4ff556c | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 831 |     template <class charT, class traits> | 
 | 832 |     friend | 
 | 833 |     basic_istream<charT, traits>& | 
 | 834 |     operator>>(basic_istream<charT, traits>& is, | 
 | 835 |                poisson_distribution& x); | 
 | 836 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 |  | 
 | 838 | template<class RealType = double> | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 839 | class exponential_distribution | 
 | 840 | { | 
 | 841 | public: | 
 | 842 |     // types | 
 | 843 |     typedef RealType result_type; | 
 | 844 |  | 
 | 845 |     class param_type | 
 | 846 |     { | 
 | 847 |     public: | 
 | 848 |         typedef exponential_distribution distribution_type; | 
 | 849 |  | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 850 |         explicit param_type(result_type lambda = 1.0); | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 851 |  | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 852 |         result_type lambda() const; | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 853 |  | 
 | 854 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 855 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 856 |     }; | 
 | 857 |  | 
 | 858 |     // constructors and reset functions | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 859 |     explicit exponential_distribution(result_type lambda = 1.0); | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 860 |     explicit exponential_distribution(const param_type& parm); | 
 | 861 |     void reset(); | 
 | 862 |  | 
 | 863 |     // generating functions | 
 | 864 |     template<class URNG> result_type operator()(URNG& g); | 
 | 865 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 866 |  | 
 | 867 |     // property functions | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 868 |     result_type lambda() const; | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 869 |  | 
 | 870 |     param_type param() const; | 
 | 871 |     void param(const param_type& parm); | 
 | 872 |  | 
 | 873 |     result_type min() const; | 
 | 874 |     result_type max() const; | 
 | 875 |  | 
 | 876 |     friend bool operator==(const exponential_distribution& x, | 
 | 877 |                            const exponential_distribution& y); | 
 | 878 |     friend bool operator!=(const exponential_distribution& x, | 
 | 879 |                            const exponential_distribution& y); | 
 | 880 |  | 
 | 881 |     template <class charT, class traits> | 
 | 882 |     friend | 
 | 883 |     basic_ostream<charT, traits>& | 
 | 884 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 885 |                const exponential_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 886 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 887 |     template <class charT, class traits> | 
 | 888 |     friend | 
 | 889 |     basic_istream<charT, traits>& | 
 | 890 |     operator>>(basic_istream<charT, traits>& is, | 
 | 891 |                exponential_distribution& x); | 
 | 892 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 |  | 
 | 894 | template<class RealType = double> | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 895 | class gamma_distribution | 
 | 896 | { | 
 | 897 | public: | 
 | 898 |     // types | 
 | 899 |     typedef RealType result_type; | 
 | 900 |  | 
 | 901 |     class param_type | 
 | 902 |     { | 
 | 903 |     public: | 
 | 904 |         typedef gamma_distribution distribution_type; | 
 | 905 |  | 
 | 906 |         explicit param_type(result_type alpha = 1, result_type beta = 1); | 
 | 907 |  | 
 | 908 |         result_type alpha() const; | 
 | 909 |         result_type beta() const; | 
 | 910 |  | 
 | 911 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 912 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 913 |     }; | 
 | 914 |  | 
 | 915 |     // constructors and reset functions | 
 | 916 |     explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); | 
 | 917 |     explicit gamma_distribution(const param_type& parm); | 
 | 918 |     void reset(); | 
 | 919 |  | 
 | 920 |     // generating functions | 
 | 921 |     template<class URNG> result_type operator()(URNG& g); | 
 | 922 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 923 |  | 
 | 924 |     // property functions | 
 | 925 |     result_type alpha() const; | 
 | 926 |     result_type beta() const; | 
 | 927 |  | 
 | 928 |     param_type param() const; | 
 | 929 |     void param(const param_type& parm); | 
 | 930 |  | 
 | 931 |     result_type min() const; | 
 | 932 |     result_type max() const; | 
 | 933 |  | 
 | 934 |     friend bool operator==(const gamma_distribution& x, | 
 | 935 |                            const gamma_distribution& y); | 
 | 936 |     friend bool operator!=(const gamma_distribution& x, | 
 | 937 |                            const gamma_distribution& y); | 
 | 938 |  | 
 | 939 |     template <class charT, class traits> | 
 | 940 |     friend | 
 | 941 |     basic_ostream<charT, traits>& | 
 | 942 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 943 |                const gamma_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 944 |  | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 945 |     template <class charT, class traits> | 
 | 946 |     friend | 
 | 947 |     basic_istream<charT, traits>& | 
 | 948 |     operator>>(basic_istream<charT, traits>& is, | 
 | 949 |                gamma_distribution& x); | 
 | 950 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 951 |  | 
 | 952 | template<class RealType = double> | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 953 | class weibull_distribution | 
 | 954 | { | 
 | 955 | public: | 
 | 956 |     // types | 
 | 957 |     typedef RealType result_type; | 
 | 958 |  | 
 | 959 |     class param_type | 
 | 960 |     { | 
 | 961 |     public: | 
 | 962 |         typedef weibull_distribution distribution_type; | 
 | 963 |  | 
 | 964 |         explicit param_type(result_type alpha = 1, result_type beta = 1); | 
 | 965 |  | 
 | 966 |         result_type a() const; | 
 | 967 |         result_type b() const; | 
 | 968 |  | 
 | 969 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 970 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 971 |     }; | 
 | 972 |  | 
 | 973 |     // constructor and reset functions | 
 | 974 |     explicit weibull_distribution(result_type a = 1, result_type b = 1); | 
 | 975 |     explicit weibull_distribution(const param_type& parm); | 
 | 976 |     void reset(); | 
 | 977 |  | 
 | 978 |     // generating functions | 
 | 979 |     template<class URNG> result_type operator()(URNG& g); | 
 | 980 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 981 |  | 
 | 982 |     // property functions | 
 | 983 |     result_type a() const; | 
 | 984 |     result_type b() const; | 
 | 985 |  | 
 | 986 |     param_type param() const; | 
 | 987 |     void param(const param_type& parm); | 
 | 988 |  | 
 | 989 |     result_type min() const; | 
 | 990 |     result_type max() const; | 
 | 991 |  | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 992 |     friend bool operator==(const weibull_distribution& x, | 
 | 993 |                            const weibull_distribution& y); | 
 | 994 |     friend bool operator!=(const weibull_distribution& x, | 
 | 995 |                            const weibull_distribution& y); | 
 | 996 |  | 
 | 997 |     template <class charT, class traits> | 
 | 998 |     friend | 
 | 999 |     basic_ostream<charT, traits>& | 
 | 1000 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1001 |                const weibull_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1002 |  | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1003 |     template <class charT, class traits> | 
 | 1004 |     friend | 
 | 1005 |     basic_istream<charT, traits>& | 
 | 1006 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1007 |                weibull_distribution& x); | 
 | 1008 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 |  | 
 | 1010 | template<class RealType = double> | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1011 | class extreme_value_distribution | 
 | 1012 | { | 
 | 1013 | public: | 
 | 1014 |     // types | 
 | 1015 |     typedef RealType result_type; | 
 | 1016 |  | 
 | 1017 |     class param_type | 
 | 1018 |     { | 
 | 1019 |     public: | 
 | 1020 |         typedef extreme_value_distribution distribution_type; | 
 | 1021 |  | 
 | 1022 |         explicit param_type(result_type a = 0, result_type b = 1); | 
 | 1023 |  | 
 | 1024 |         result_type a() const; | 
 | 1025 |         result_type b() const; | 
 | 1026 |  | 
 | 1027 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1028 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1029 |     }; | 
 | 1030 |  | 
 | 1031 |     // constructor and reset functions | 
 | 1032 |     explicit extreme_value_distribution(result_type a = 0, result_type b = 1); | 
 | 1033 |     explicit extreme_value_distribution(const param_type& parm); | 
 | 1034 |     void reset(); | 
 | 1035 |  | 
 | 1036 |     // generating functions | 
 | 1037 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1038 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1039 |  | 
 | 1040 |     // property functions | 
 | 1041 |     result_type a() const; | 
 | 1042 |     result_type b() const; | 
 | 1043 |  | 
 | 1044 |     param_type param() const; | 
 | 1045 |     void param(const param_type& parm); | 
 | 1046 |  | 
 | 1047 |     result_type min() const; | 
 | 1048 |     result_type max() const; | 
 | 1049 |  | 
 | 1050 |     friend bool operator==(const extreme_value_distribution& x, | 
 | 1051 |                            const extreme_value_distribution& y); | 
 | 1052 |     friend bool operator!=(const extreme_value_distribution& x, | 
 | 1053 |                            const extreme_value_distribution& y); | 
 | 1054 |  | 
 | 1055 |     template <class charT, class traits> | 
 | 1056 |     friend | 
 | 1057 |     basic_ostream<charT, traits>& | 
 | 1058 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1059 |                const extreme_value_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1060 |  | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1061 |     template <class charT, class traits> | 
 | 1062 |     friend | 
 | 1063 |     basic_istream<charT, traits>& | 
 | 1064 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1065 |                extreme_value_distribution& x); | 
 | 1066 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 |  | 
 | 1068 | template<class RealType = double> | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1069 | class normal_distribution | 
 | 1070 | { | 
 | 1071 | public: | 
 | 1072 |     // types | 
 | 1073 |     typedef RealType result_type; | 
 | 1074 |  | 
 | 1075 |     class param_type | 
 | 1076 |     { | 
 | 1077 |     public: | 
 | 1078 |         typedef normal_distribution distribution_type; | 
 | 1079 |  | 
 | 1080 |         explicit param_type(result_type mean = 0, result_type stddev = 1); | 
 | 1081 |  | 
 | 1082 |         result_type mean() const; | 
 | 1083 |         result_type stddev() const; | 
 | 1084 |  | 
 | 1085 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1086 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1087 |     }; | 
 | 1088 |  | 
 | 1089 |     // constructors and reset functions | 
 | 1090 |     explicit normal_distribution(result_type mean = 0, result_type stddev = 1); | 
 | 1091 |     explicit normal_distribution(const param_type& parm); | 
 | 1092 |     void reset(); | 
 | 1093 |  | 
 | 1094 |     // generating functions | 
 | 1095 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1096 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1097 |  | 
 | 1098 |     // property functions | 
 | 1099 |     result_type mean() const; | 
 | 1100 |     result_type stddev() const; | 
 | 1101 |  | 
 | 1102 |     param_type param() const; | 
 | 1103 |     void param(const param_type& parm); | 
 | 1104 |  | 
 | 1105 |     result_type min() const; | 
 | 1106 |     result_type max() const; | 
 | 1107 |  | 
 | 1108 |     friend bool operator==(const normal_distribution& x, | 
 | 1109 |                            const normal_distribution& y); | 
 | 1110 |     friend bool operator!=(const normal_distribution& x, | 
 | 1111 |                            const normal_distribution& y); | 
 | 1112 |  | 
 | 1113 |     template <class charT, class traits> | 
 | 1114 |     friend | 
 | 1115 |     basic_ostream<charT, traits>& | 
 | 1116 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1117 |                const normal_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1118 |  | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1119 |     template <class charT, class traits> | 
 | 1120 |     friend | 
 | 1121 |     basic_istream<charT, traits>& | 
 | 1122 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1123 |                normal_distribution& x); | 
 | 1124 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 |  | 
 | 1126 | template<class RealType = double> | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1127 | class lognormal_distribution | 
 | 1128 | { | 
 | 1129 | public: | 
 | 1130 |     // types | 
 | 1131 |     typedef RealType result_type; | 
 | 1132 |  | 
 | 1133 |     class param_type | 
 | 1134 |     { | 
 | 1135 |     public: | 
 | 1136 |         typedef lognormal_distribution distribution_type; | 
 | 1137 |  | 
 | 1138 |         explicit param_type(result_type m = 0, result_type s = 1); | 
 | 1139 |  | 
 | 1140 |         result_type m() const; | 
 | 1141 |         result_type s() const; | 
 | 1142 |  | 
 | 1143 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1144 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1145 |     }; | 
 | 1146 |  | 
 | 1147 |     // constructor and reset functions | 
 | 1148 |     explicit lognormal_distribution(result_type m = 0, result_type s = 1); | 
 | 1149 |     explicit lognormal_distribution(const param_type& parm); | 
 | 1150 |     void reset(); | 
 | 1151 |  | 
 | 1152 |     // generating functions | 
 | 1153 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1154 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1155 |  | 
 | 1156 |     // property functions | 
 | 1157 |     result_type m() const; | 
 | 1158 |     result_type s() const; | 
 | 1159 |  | 
 | 1160 |     param_type param() const; | 
 | 1161 |     void param(const param_type& parm); | 
 | 1162 |  | 
 | 1163 |     result_type min() const; | 
 | 1164 |     result_type max() const; | 
 | 1165 |  | 
 | 1166 |     friend bool operator==(const lognormal_distribution& x, | 
 | 1167 |                            const lognormal_distribution& y); | 
 | 1168 |     friend bool operator!=(const lognormal_distribution& x, | 
 | 1169 |                            const lognormal_distribution& y); | 
 | 1170 |  | 
 | 1171 |     template <class charT, class traits> | 
 | 1172 |     friend | 
 | 1173 |     basic_ostream<charT, traits>& | 
 | 1174 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1175 |                const lognormal_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 |  | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1177 |     template <class charT, class traits> | 
 | 1178 |     friend | 
 | 1179 |     basic_istream<charT, traits>& | 
 | 1180 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1181 |                lognormal_distribution& x); | 
 | 1182 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 |  | 
 | 1184 | template<class RealType = double> | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1185 | class chi_squared_distribution | 
 | 1186 | { | 
 | 1187 | public: | 
 | 1188 |     // types | 
 | 1189 |     typedef RealType result_type; | 
 | 1190 |  | 
 | 1191 |     class param_type | 
 | 1192 |     { | 
 | 1193 |     public: | 
 | 1194 |         typedef chi_squared_distribution distribution_type; | 
 | 1195 |  | 
 | 1196 |         explicit param_type(result_type n = 1); | 
 | 1197 |  | 
 | 1198 |         result_type n() const; | 
 | 1199 |  | 
 | 1200 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1201 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1202 |     }; | 
 | 1203 |  | 
 | 1204 |     // constructor and reset functions | 
 | 1205 |     explicit chi_squared_distribution(result_type n = 1); | 
 | 1206 |     explicit chi_squared_distribution(const param_type& parm); | 
 | 1207 |     void reset(); | 
 | 1208 |  | 
 | 1209 |     // generating functions | 
 | 1210 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1211 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1212 |  | 
 | 1213 |     // property functions | 
 | 1214 |     result_type n() const; | 
 | 1215 |  | 
 | 1216 |     param_type param() const; | 
 | 1217 |     void param(const param_type& parm); | 
 | 1218 |  | 
 | 1219 |     result_type min() const; | 
 | 1220 |     result_type max() const; | 
 | 1221 |  | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1222 |     friend bool operator==(const chi_squared_distribution& x, | 
 | 1223 |                            const chi_squared_distribution& y); | 
 | 1224 |     friend bool operator!=(const chi_squared_distribution& x, | 
 | 1225 |                            const chi_squared_distribution& y); | 
 | 1226 |  | 
 | 1227 |     template <class charT, class traits> | 
 | 1228 |     friend | 
 | 1229 |     basic_ostream<charT, traits>& | 
 | 1230 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1231 |                const chi_squared_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1232 |  | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1233 |     template <class charT, class traits> | 
 | 1234 |     friend | 
 | 1235 |     basic_istream<charT, traits>& | 
 | 1236 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1237 |                chi_squared_distribution& x); | 
 | 1238 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 |  | 
 | 1240 | template<class RealType = double> | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1241 | class cauchy_distribution | 
 | 1242 | { | 
 | 1243 | public: | 
 | 1244 |     // types | 
 | 1245 |     typedef RealType result_type; | 
 | 1246 |  | 
 | 1247 |     class param_type | 
 | 1248 |     { | 
 | 1249 |     public: | 
 | 1250 |         typedef cauchy_distribution distribution_type; | 
 | 1251 |  | 
 | 1252 |         explicit param_type(result_type a = 0, result_type b = 1); | 
 | 1253 |  | 
 | 1254 |         result_type a() const; | 
 | 1255 |         result_type b() const; | 
 | 1256 |  | 
 | 1257 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1258 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1259 |     }; | 
 | 1260 |  | 
 | 1261 |     // constructor and reset functions | 
 | 1262 |     explicit cauchy_distribution(result_type a = 0, result_type b = 1); | 
 | 1263 |     explicit cauchy_distribution(const param_type& parm); | 
 | 1264 |     void reset(); | 
 | 1265 |  | 
 | 1266 |     // generating functions | 
 | 1267 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1268 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1269 |  | 
 | 1270 |     // property functions | 
 | 1271 |     result_type a() const; | 
 | 1272 |     result_type b() const; | 
 | 1273 |  | 
 | 1274 |     param_type param() const; | 
 | 1275 |     void param(const param_type& parm); | 
 | 1276 |  | 
 | 1277 |     result_type min() const; | 
 | 1278 |     result_type max() const; | 
 | 1279 |  | 
 | 1280 |     friend bool operator==(const cauchy_distribution& x, | 
 | 1281 |                            const cauchy_distribution& y); | 
 | 1282 |     friend bool operator!=(const cauchy_distribution& x, | 
 | 1283 |                            const cauchy_distribution& y); | 
 | 1284 |  | 
 | 1285 |     template <class charT, class traits> | 
 | 1286 |     friend | 
 | 1287 |     basic_ostream<charT, traits>& | 
 | 1288 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1289 |                const cauchy_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1290 |  | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1291 |     template <class charT, class traits> | 
 | 1292 |     friend | 
 | 1293 |     basic_istream<charT, traits>& | 
 | 1294 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1295 |                cauchy_distribution& x); | 
 | 1296 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 |  | 
 | 1298 | template<class RealType = double> | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1299 | class fisher_f_distribution | 
 | 1300 | { | 
 | 1301 | public: | 
 | 1302 |     // types | 
 | 1303 |     typedef RealType result_type; | 
 | 1304 |  | 
 | 1305 |     class param_type | 
 | 1306 |     { | 
 | 1307 |     public: | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1308 |         typedef fisher_f_distribution distribution_type; | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1309 |  | 
 | 1310 |         explicit param_type(result_type m = 1, result_type n = 1); | 
 | 1311 |  | 
 | 1312 |         result_type m() const; | 
 | 1313 |         result_type n() const; | 
 | 1314 |  | 
 | 1315 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1316 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1317 |     }; | 
 | 1318 |  | 
 | 1319 |     // constructor and reset functions | 
 | 1320 |     explicit fisher_f_distribution(result_type m = 1, result_type n = 1); | 
 | 1321 |     explicit fisher_f_distribution(const param_type& parm); | 
 | 1322 |     void reset(); | 
 | 1323 |  | 
 | 1324 |     // generating functions | 
 | 1325 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1326 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1327 |  | 
 | 1328 |     // property functions | 
 | 1329 |     result_type m() const; | 
 | 1330 |     result_type n() const; | 
 | 1331 |  | 
 | 1332 |     param_type param() const; | 
 | 1333 |     void param(const param_type& parm); | 
 | 1334 |  | 
 | 1335 |     result_type min() const; | 
 | 1336 |     result_type max() const; | 
 | 1337 |  | 
 | 1338 |     friend bool operator==(const fisher_f_distribution& x, | 
 | 1339 |                            const fisher_f_distribution& y); | 
 | 1340 |     friend bool operator!=(const fisher_f_distribution& x, | 
 | 1341 |                            const fisher_f_distribution& y); | 
 | 1342 |  | 
 | 1343 |     template <class charT, class traits> | 
 | 1344 |     friend | 
 | 1345 |     basic_ostream<charT, traits>& | 
 | 1346 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1347 |                const fisher_f_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1348 |  | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1349 |     template <class charT, class traits> | 
 | 1350 |     friend | 
 | 1351 |     basic_istream<charT, traits>& | 
 | 1352 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1353 |                fisher_f_distribution& x); | 
 | 1354 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 |  | 
 | 1356 | template<class RealType = double> | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1357 | class student_t_distribution | 
 | 1358 | { | 
 | 1359 | public: | 
 | 1360 |     // types | 
 | 1361 |     typedef RealType result_type; | 
 | 1362 |  | 
 | 1363 |     class param_type | 
 | 1364 |     { | 
 | 1365 |     public: | 
 | 1366 |         typedef student_t_distribution distribution_type; | 
 | 1367 |  | 
 | 1368 |         explicit param_type(result_type n = 1); | 
 | 1369 |  | 
 | 1370 |         result_type n() const; | 
 | 1371 |  | 
 | 1372 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1373 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1374 |     }; | 
 | 1375 |  | 
 | 1376 |     // constructor and reset functions | 
 | 1377 |     explicit student_t_distribution(result_type n = 1); | 
 | 1378 |     explicit student_t_distribution(const param_type& parm); | 
 | 1379 |     void reset(); | 
 | 1380 |  | 
 | 1381 |     // generating functions | 
 | 1382 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1383 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1384 |  | 
 | 1385 |     // property functions | 
 | 1386 |     result_type n() const; | 
 | 1387 |  | 
 | 1388 |     param_type param() const; | 
 | 1389 |     void param(const param_type& parm); | 
 | 1390 |  | 
 | 1391 |     result_type min() const; | 
 | 1392 |     result_type max() const; | 
 | 1393 |  | 
 | 1394 |     friend bool operator==(const student_t_distribution& x, | 
 | 1395 |                            const student_t_distribution& y); | 
 | 1396 |     friend bool operator!=(const student_t_distribution& x, | 
 | 1397 |                            const student_t_distribution& y); | 
 | 1398 |  | 
 | 1399 |     template <class charT, class traits> | 
 | 1400 |     friend | 
 | 1401 |     basic_ostream<charT, traits>& | 
 | 1402 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1403 |                const student_t_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1404 |  | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1405 |     template <class charT, class traits> | 
 | 1406 |     friend | 
 | 1407 |     basic_istream<charT, traits>& | 
 | 1408 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1409 |                student_t_distribution& x); | 
 | 1410 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 |  | 
 | 1412 | template<class IntType = int> | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1413 | class discrete_distribution | 
 | 1414 | { | 
 | 1415 | public: | 
 | 1416 |     // types | 
 | 1417 |     typedef IntType result_type; | 
 | 1418 |  | 
 | 1419 |     class param_type | 
 | 1420 |     { | 
 | 1421 |     public: | 
 | 1422 |         typedef discrete_distribution distribution_type; | 
 | 1423 |  | 
 | 1424 |         param_type(); | 
 | 1425 |         template<class InputIterator> | 
 | 1426 |             param_type(InputIterator firstW, InputIterator lastW); | 
 | 1427 |         param_type(initializer_list<double> wl); | 
 | 1428 |         template<class UnaryOperation> | 
 | 1429 |             param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); | 
 | 1430 |  | 
 | 1431 |         vector<double> probabilities() const; | 
 | 1432 |  | 
 | 1433 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1434 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1435 |     }; | 
 | 1436 |  | 
 | 1437 |     // constructor and reset functions | 
 | 1438 |     discrete_distribution(); | 
 | 1439 |     template<class InputIterator> | 
 | 1440 |         discrete_distribution(InputIterator firstW, InputIterator lastW); | 
 | 1441 |     discrete_distribution(initializer_list<double> wl); | 
 | 1442 |     template<class UnaryOperation> | 
 | 1443 |         discrete_distribution(size_t nw, double xmin, double xmax, | 
 | 1444 |                               UnaryOperation fw); | 
 | 1445 |     explicit discrete_distribution(const param_type& parm); | 
 | 1446 |     void reset(); | 
 | 1447 |  | 
 | 1448 |     // generating functions | 
 | 1449 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1450 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1451 |  | 
 | 1452 |     // property functions | 
 | 1453 |     vector<double> probabilities() const; | 
 | 1454 |  | 
 | 1455 |     param_type param() const; | 
 | 1456 |     void param(const param_type& parm); | 
 | 1457 |  | 
 | 1458 |     result_type min() const; | 
 | 1459 |     result_type max() const; | 
 | 1460 |  | 
 | 1461 |     friend bool operator==(const discrete_distribution& x, | 
 | 1462 |                            const discrete_distribution& y); | 
 | 1463 |     friend bool operator!=(const discrete_distribution& x, | 
 | 1464 |                            const discrete_distribution& y); | 
 | 1465 |  | 
 | 1466 |     template <class charT, class traits> | 
 | 1467 |     friend | 
 | 1468 |     basic_ostream<charT, traits>& | 
 | 1469 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1470 |                const discrete_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1471 |  | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1472 |     template <class charT, class traits> | 
 | 1473 |     friend | 
 | 1474 |     basic_istream<charT, traits>& | 
 | 1475 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1476 |                discrete_distribution& x); | 
 | 1477 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 |  | 
 | 1479 | template<class RealType = double> | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1480 | class piecewise_constant_distribution | 
 | 1481 | { | 
 | 1482 |     // types | 
 | 1483 |     typedef RealType result_type; | 
 | 1484 |  | 
 | 1485 |     class param_type | 
 | 1486 |     { | 
 | 1487 |     public: | 
 | 1488 |         typedef piecewise_constant_distribution distribution_type; | 
 | 1489 |  | 
 | 1490 |         param_type(); | 
 | 1491 |         template<class InputIteratorB, class InputIteratorW> | 
 | 1492 |             param_type(InputIteratorB firstB, InputIteratorB lastB, | 
 | 1493 |                        InputIteratorW firstW); | 
 | 1494 |         template<class UnaryOperation> | 
 | 1495 |             param_type(initializer_list<result_type> bl, UnaryOperation fw); | 
 | 1496 |         template<class UnaryOperation> | 
 | 1497 |             param_type(size_t nw, result_type xmin, result_type xmax, | 
 | 1498 |                        UnaryOperation fw); | 
 | 1499 |  | 
 | 1500 |         vector<result_type> intervals() const; | 
| Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1501 |         vector<result_type> densities() const; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1502 |  | 
 | 1503 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1504 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1505 |     }; | 
 | 1506 |  | 
 | 1507 |     // constructor and reset functions | 
 | 1508 |     piecewise_constant_distribution(); | 
 | 1509 |     template<class InputIteratorB, class InputIteratorW> | 
 | 1510 |         piecewise_constant_distribution(InputIteratorB firstB, | 
 | 1511 |                                         InputIteratorB lastB, | 
 | 1512 |                                         InputIteratorW firstW); | 
 | 1513 |     template<class UnaryOperation> | 
 | 1514 |         piecewise_constant_distribution(initializer_list<result_type> bl, | 
 | 1515 |                                         UnaryOperation fw); | 
 | 1516 |     template<class UnaryOperation> | 
 | 1517 |         piecewise_constant_distribution(size_t nw, result_type xmin, | 
 | 1518 |                                         result_type xmax, UnaryOperation fw); | 
 | 1519 |     explicit piecewise_constant_distribution(const param_type& parm); | 
 | 1520 |     void reset(); | 
 | 1521 |  | 
 | 1522 |     // generating functions | 
 | 1523 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1524 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1525 |  | 
 | 1526 |     // property functions | 
 | 1527 |     vector<result_type> intervals() const; | 
| Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1528 |     vector<result_type> densities() const; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1529 |  | 
 | 1530 |     param_type param() const; | 
 | 1531 |     void param(const param_type& parm); | 
 | 1532 |  | 
 | 1533 |     result_type min() const; | 
 | 1534 |     result_type max() const; | 
 | 1535 |  | 
 | 1536 |     friend bool operator==(const piecewise_constant_distribution& x, | 
 | 1537 |                            const piecewise_constant_distribution& y); | 
 | 1538 |     friend bool operator!=(const piecewise_constant_distribution& x, | 
 | 1539 |                            const piecewise_constant_distribution& y); | 
 | 1540 |  | 
 | 1541 |     template <class charT, class traits> | 
 | 1542 |     friend | 
 | 1543 |     basic_ostream<charT, traits>& | 
 | 1544 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1545 |                const piecewise_constant_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1546 |  | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1547 |     template <class charT, class traits> | 
 | 1548 |     friend | 
 | 1549 |     basic_istream<charT, traits>& | 
 | 1550 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1551 |                piecewise_constant_distribution& x); | 
 | 1552 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1553 |  | 
 | 1554 | template<class RealType = double> | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1555 | class piecewise_linear_distribution | 
 | 1556 | { | 
 | 1557 |     // types | 
 | 1558 |     typedef RealType result_type; | 
 | 1559 |  | 
 | 1560 |     class param_type | 
 | 1561 |     { | 
 | 1562 |     public: | 
 | 1563 |         typedef piecewise_linear_distribution distribution_type; | 
 | 1564 |  | 
 | 1565 |         param_type(); | 
 | 1566 |         template<class InputIteratorB, class InputIteratorW> | 
 | 1567 |             param_type(InputIteratorB firstB, InputIteratorB lastB, | 
 | 1568 |                        InputIteratorW firstW); | 
 | 1569 |         template<class UnaryOperation> | 
 | 1570 |             param_type(initializer_list<result_type> bl, UnaryOperation fw); | 
 | 1571 |         template<class UnaryOperation> | 
 | 1572 |             param_type(size_t nw, result_type xmin, result_type xmax, | 
 | 1573 |                        UnaryOperation fw); | 
 | 1574 |  | 
 | 1575 |         vector<result_type> intervals() const; | 
| Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1576 |         vector<result_type> densities() const; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1577 |  | 
 | 1578 |         friend bool operator==(const param_type& x, const param_type& y); | 
 | 1579 |         friend bool operator!=(const param_type& x, const param_type& y); | 
 | 1580 |     }; | 
 | 1581 |  | 
 | 1582 |     // constructor and reset functions | 
 | 1583 |     piecewise_linear_distribution(); | 
 | 1584 |     template<class InputIteratorB, class InputIteratorW> | 
 | 1585 |         piecewise_linear_distribution(InputIteratorB firstB, | 
 | 1586 |                                       InputIteratorB lastB, | 
 | 1587 |                                       InputIteratorW firstW); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1588 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1589 |     template<class UnaryOperation> | 
 | 1590 |         piecewise_linear_distribution(initializer_list<result_type> bl, | 
 | 1591 |                                       UnaryOperation fw); | 
 | 1592 |  | 
 | 1593 |     template<class UnaryOperation> | 
 | 1594 |         piecewise_linear_distribution(size_t nw, result_type xmin, | 
 | 1595 |                                       result_type xmax, UnaryOperation fw); | 
 | 1596 |  | 
 | 1597 |     explicit piecewise_linear_distribution(const param_type& parm); | 
 | 1598 |     void reset(); | 
 | 1599 |  | 
 | 1600 |     // generating functions | 
 | 1601 |     template<class URNG> result_type operator()(URNG& g); | 
 | 1602 |     template<class URNG> result_type operator()(URNG& g, const param_type& parm); | 
 | 1603 |  | 
 | 1604 |     // property functions | 
 | 1605 |     vector<result_type> intervals() const; | 
| Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1606 |     vector<result_type> densities() const; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1607 |  | 
 | 1608 |     param_type param() const; | 
 | 1609 |     void param(const param_type& parm); | 
 | 1610 |  | 
 | 1611 |     result_type min() const; | 
 | 1612 |     result_type max() const; | 
 | 1613 |  | 
 | 1614 |     friend bool operator==(const piecewise_linear_distribution& x, | 
 | 1615 |                            const piecewise_linear_distribution& y); | 
 | 1616 |     friend bool operator!=(const piecewise_linear_distribution& x, | 
 | 1617 |                            const piecewise_linear_distribution& y); | 
 | 1618 |  | 
 | 1619 |     template <class charT, class traits> | 
 | 1620 |     friend | 
 | 1621 |     basic_ostream<charT, traits>& | 
 | 1622 |     operator<<(basic_ostream<charT, traits>& os, | 
 | 1623 |                const piecewise_linear_distribution& x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1624 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1625 |     template <class charT, class traits> | 
 | 1626 |     friend | 
 | 1627 |     basic_istream<charT, traits>& | 
 | 1628 |     operator>>(basic_istream<charT, traits>& is, | 
 | 1629 |                piecewise_linear_distribution& x); | 
 | 1630 | }; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1631 |  | 
 | 1632 | } // std | 
 | 1633 | */ | 
 | 1634 |  | 
 | 1635 | #include <__config> | 
 | 1636 | #include <cstddef> | 
 | 1637 | #include <type_traits> | 
 | 1638 | #include <initializer_list> | 
 | 1639 | #include <cstdint> | 
 | 1640 | #include <limits> | 
 | 1641 | #include <algorithm> | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1642 | #include <numeric> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | #include <vector> | 
 | 1644 | #include <string> | 
 | 1645 | #include <istream> | 
 | 1646 | #include <ostream> | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 1647 | #include <cmath> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1648 |  | 
 | 1649 | #pragma GCC system_header | 
 | 1650 |  | 
 | 1651 | _LIBCPP_BEGIN_NAMESPACE_STD | 
 | 1652 |  | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1653 | // __is_seed_sequence | 
 | 1654 |  | 
 | 1655 | template <class _Sseq, class _Engine> | 
 | 1656 | struct __is_seed_sequence | 
 | 1657 | { | 
 | 1658 |     static const bool value = | 
 | 1659 |               !is_convertible<_Sseq, typename _Engine::result_type>::value && | 
 | 1660 |               !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; | 
 | 1661 | }; | 
 | 1662 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | // linear_congruential_engine | 
 | 1664 |  | 
 | 1665 | template <unsigned long long __a, unsigned long long __c, | 
 | 1666 |           unsigned long long __m, unsigned long long _M, | 
 | 1667 |           bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_M-__c)/__a)> | 
 | 1668 | struct __lce_ta; | 
 | 1669 |  | 
 | 1670 | // 64 | 
 | 1671 |  | 
 | 1672 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> | 
 | 1673 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> | 
 | 1674 | { | 
 | 1675 |     typedef unsigned long long result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1676 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1677 |     static result_type next(result_type __x) | 
 | 1678 |     { | 
 | 1679 |         // Schrage's algorithm | 
 | 1680 |         const result_type __q = __m / __a; | 
 | 1681 |         const result_type __r = __m % __a; | 
 | 1682 |         const result_type __t0 = __a * (__x % __q); | 
 | 1683 |         const result_type __t1 = __r * (__x / __q); | 
 | 1684 |         __x = __t0 + (__t0 < __t1) * __m - __t1; | 
 | 1685 |         __x += __c - (__x >= __m - __c) * __m; | 
 | 1686 |         return __x; | 
 | 1687 |     } | 
 | 1688 | }; | 
 | 1689 |  | 
 | 1690 | template <unsigned long long __a, unsigned long long __m> | 
 | 1691 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> | 
 | 1692 | { | 
 | 1693 |     typedef unsigned long long result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1694 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 |     static result_type next(result_type __x) | 
 | 1696 |     { | 
 | 1697 |         // Schrage's algorithm | 
 | 1698 |         const result_type __q = __m / __a; | 
 | 1699 |         const result_type __r = __m % __a; | 
 | 1700 |         const result_type __t0 = __a * (__x % __q); | 
 | 1701 |         const result_type __t1 = __r * (__x / __q); | 
 | 1702 |         __x = __t0 + (__t0 < __t1) * __m - __t1; | 
 | 1703 |         return __x; | 
 | 1704 |     } | 
 | 1705 | }; | 
 | 1706 |  | 
 | 1707 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> | 
 | 1708 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> | 
 | 1709 | { | 
 | 1710 |     typedef unsigned long long result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1711 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1712 |     static result_type next(result_type __x) | 
 | 1713 |     { | 
 | 1714 |         return (__a * __x + __c) % __m; | 
 | 1715 |     } | 
 | 1716 | }; | 
 | 1717 |  | 
 | 1718 | template <unsigned long long __a, unsigned long long __c> | 
 | 1719 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> | 
 | 1720 | { | 
 | 1721 |     typedef unsigned long long result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1722 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1723 |     static result_type next(result_type __x) | 
 | 1724 |     { | 
 | 1725 |         return __a * __x + __c; | 
 | 1726 |     } | 
 | 1727 | }; | 
 | 1728 |  | 
 | 1729 | // 32 | 
 | 1730 |  | 
 | 1731 | template <unsigned long long _A, unsigned long long _C, unsigned long long _M> | 
 | 1732 | struct __lce_ta<_A, _C, _M, unsigned(~0), true> | 
 | 1733 | { | 
 | 1734 |     typedef unsigned result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1735 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 |     static result_type next(result_type __x) | 
 | 1737 |     { | 
 | 1738 |         const result_type __a = static_cast<result_type>(_A); | 
 | 1739 |         const result_type __c = static_cast<result_type>(_C); | 
 | 1740 |         const result_type __m = static_cast<result_type>(_M); | 
 | 1741 |         // Schrage's algorithm | 
 | 1742 |         const result_type __q = __m / __a; | 
 | 1743 |         const result_type __r = __m % __a; | 
 | 1744 |         const result_type __t0 = __a * (__x % __q); | 
 | 1745 |         const result_type __t1 = __r * (__x / __q); | 
 | 1746 |         __x = __t0 + (__t0 < __t1) * __m - __t1; | 
 | 1747 |         __x += __c - (__x >= __m - __c) * __m; | 
 | 1748 |         return __x; | 
 | 1749 |     } | 
 | 1750 | }; | 
 | 1751 |  | 
 | 1752 | template <unsigned long long _A, unsigned long long _M> | 
 | 1753 | struct __lce_ta<_A, 0, _M, unsigned(~0), true> | 
 | 1754 | { | 
 | 1755 |     typedef unsigned result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1756 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1757 |     static result_type next(result_type __x) | 
 | 1758 |     { | 
 | 1759 |         const result_type __a = static_cast<result_type>(_A); | 
 | 1760 |         const result_type __m = static_cast<result_type>(_M); | 
 | 1761 |         // Schrage's algorithm | 
 | 1762 |         const result_type __q = __m / __a; | 
 | 1763 |         const result_type __r = __m % __a; | 
 | 1764 |         const result_type __t0 = __a * (__x % __q); | 
 | 1765 |         const result_type __t1 = __r * (__x / __q); | 
 | 1766 |         __x = __t0 + (__t0 < __t1) * __m - __t1; | 
 | 1767 |         return __x; | 
 | 1768 |     } | 
 | 1769 | }; | 
 | 1770 |  | 
 | 1771 | template <unsigned long long _A, unsigned long long _C, unsigned long long _M> | 
 | 1772 | struct __lce_ta<_A, _C, _M, unsigned(~0), false> | 
 | 1773 | { | 
 | 1774 |     typedef unsigned result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1775 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 |     static result_type next(result_type __x) | 
 | 1777 |     { | 
 | 1778 |         const result_type __a = static_cast<result_type>(_A); | 
 | 1779 |         const result_type __c = static_cast<result_type>(_C); | 
 | 1780 |         const result_type __m = static_cast<result_type>(_M); | 
 | 1781 |         return (__a * __x + __c) % __m; | 
 | 1782 |     } | 
 | 1783 | }; | 
 | 1784 |  | 
 | 1785 | template <unsigned long long _A, unsigned long long _C> | 
 | 1786 | struct __lce_ta<_A, _C, 0, unsigned(~0), false> | 
 | 1787 | { | 
 | 1788 |     typedef unsigned result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1789 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1790 |     static result_type next(result_type __x) | 
 | 1791 |     { | 
 | 1792 |         const result_type __a = static_cast<result_type>(_A); | 
 | 1793 |         const result_type __c = static_cast<result_type>(_C); | 
 | 1794 |         return __a * __x + __c; | 
 | 1795 |     } | 
 | 1796 | }; | 
 | 1797 |  | 
 | 1798 | // 16 | 
 | 1799 |  | 
 | 1800 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> | 
 | 1801 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> | 
 | 1802 | { | 
 | 1803 |     typedef unsigned short result_type; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1804 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 |     static result_type next(result_type __x) | 
 | 1806 |     { | 
 | 1807 |         return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); | 
 | 1808 |     } | 
 | 1809 | }; | 
 | 1810 |  | 
 | 1811 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
 | 1812 | class linear_congruential_engine; | 
 | 1813 |  | 
 | 1814 | template <class _CharT, class _Traits, | 
 | 1815 |           class _U, _U _A, _U _C, _U _N> | 
 | 1816 | basic_ostream<_CharT, _Traits>& | 
 | 1817 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 1818 |            const linear_congruential_engine<_U, _A, _C, _N>&); | 
 | 1819 |  | 
 | 1820 | template <class _CharT, class _Traits, | 
 | 1821 |           class _U, _U _A, _U _C, _U _N> | 
 | 1822 | basic_istream<_CharT, _Traits>& | 
 | 1823 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 1824 |            linear_congruential_engine<_U, _A, _C, _N>& __x); | 
 | 1825 |  | 
 | 1826 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1827 | class _LIBCPP_VISIBLE linear_congruential_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1828 | { | 
 | 1829 | public: | 
 | 1830 |     // types | 
 | 1831 |     typedef _UIntType result_type; | 
 | 1832 |  | 
 | 1833 | private: | 
 | 1834 |     result_type __x_; | 
 | 1835 |  | 
 | 1836 |     static const result_type _M = result_type(~0); | 
 | 1837 |  | 
 | 1838 |     static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); | 
 | 1839 |     static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); | 
 | 1840 | public: | 
 | 1841 |     static const result_type _Min = __c == 0u ? 1u: 0u; | 
 | 1842 |     static const result_type _Max = __m - 1u; | 
 | 1843 |     static_assert(_Min < _Max,           "linear_congruential_engine invalid parameters"); | 
 | 1844 |  | 
 | 1845 |     // engine characteristics | 
 | 1846 |     static const/*expr*/ result_type multiplier = __a; | 
 | 1847 |     static const/*expr*/ result_type increment = __c; | 
 | 1848 |     static const/*expr*/ result_type modulus = __m; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1849 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 |     static const/*expr*/ result_type min() {return _Min;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1851 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 |     static const/*expr*/ result_type max() {return _Max;} | 
 | 1853 |     static const/*expr*/ result_type default_seed = 1u; | 
 | 1854 |  | 
 | 1855 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1856 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1857 |     explicit linear_congruential_engine(result_type __s = default_seed) | 
 | 1858 |         {seed(__s);} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 1859 |     template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q, | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1860 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1861 |         typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 |         {seed(__q);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1863 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1864 |     void seed(result_type __s = default_seed) | 
 | 1865 |         {seed(integral_constant<bool, __m == 0>(), | 
 | 1866 |               integral_constant<bool, __c == 0>(), __s);} | 
 | 1867 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1868 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1869 |         typename enable_if | 
 | 1870 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1871 |             __is_seed_sequence<_Sseq, linear_congruential_engine>::value, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1872 |             void | 
 | 1873 |         >::type | 
 | 1874 |         seed(_Sseq& __q) | 
 | 1875 |             {__seed(__q, integral_constant<unsigned, | 
 | 1876 |                 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 | 
 | 1877 |                              :  (__m-1) / 0x100000000ull)>());} | 
 | 1878 |  | 
 | 1879 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1880 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1881 |     result_type operator()() | 
 | 1882 |         {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _M>::next(__x_));} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1883 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1884 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 1885 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1886 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 1887 |     bool operator==(const linear_congruential_engine& __x, | 
 | 1888 |                     const linear_congruential_engine& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1889 |         {return __x.__x_ == __y.__x_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1890 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 1891 |     bool operator!=(const linear_congruential_engine& __x, | 
 | 1892 |                     const linear_congruential_engine& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1893 |         {return !(__x == __y);} | 
 | 1894 |  | 
 | 1895 | private: | 
 | 1896 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1897 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1898 |     void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1899 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 |     void seed(true_type, false_type, result_type __s) {__x_ = __s;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1901 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1902 |     void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? | 
 | 1903 |                                                                  1 : __s % __m;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1904 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1905 |     void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} | 
 | 1906 |  | 
 | 1907 |     template<class _Sseq> | 
 | 1908 |         void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
 | 1909 |     template<class _Sseq> | 
 | 1910 |         void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
 | 1911 |  | 
 | 1912 |     template <class _CharT, class _Traits, | 
 | 1913 |               class _U, _U _A, _U _C, _U _N> | 
 | 1914 |     friend | 
 | 1915 |     basic_ostream<_CharT, _Traits>& | 
 | 1916 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 1917 |                const linear_congruential_engine<_U, _A, _C, _N>&); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1918 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1919 |     template <class _CharT, class _Traits, | 
 | 1920 |               class _U, _U _A, _U _C, _U _N> | 
 | 1921 |     friend | 
 | 1922 |     basic_istream<_CharT, _Traits>& | 
 | 1923 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 1924 |                linear_congruential_engine<_U, _A, _C, _N>& __x); | 
 | 1925 | }; | 
 | 1926 |  | 
 | 1927 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
 | 1928 | template<class _Sseq> | 
 | 1929 | void | 
 | 1930 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, | 
 | 1931 |                                                  integral_constant<unsigned, 1>) | 
 | 1932 | { | 
 | 1933 |     const unsigned __k = 1; | 
 | 1934 |     uint32_t __ar[__k+3]; | 
 | 1935 |     __q.generate(__ar, __ar + __k + 3); | 
 | 1936 |     result_type __s = static_cast<result_type>(__ar[3] % __m); | 
 | 1937 |     __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; | 
 | 1938 | } | 
 | 1939 |  | 
 | 1940 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
 | 1941 | template<class _Sseq> | 
 | 1942 | void | 
 | 1943 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, | 
 | 1944 |                                                  integral_constant<unsigned, 2>) | 
 | 1945 | { | 
 | 1946 |     const unsigned __k = 2; | 
 | 1947 |     uint32_t __ar[__k+3]; | 
 | 1948 |     __q.generate(__ar, __ar + __k + 3); | 
 | 1949 |     result_type __s = static_cast<result_type>((__ar[3] + | 
 | 1950 |                                                 (uint64_t)__ar[4] << 32) % __m); | 
 | 1951 |     __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; | 
 | 1952 | } | 
 | 1953 |  | 
 | 1954 | template <class _CharT, class _Traits> | 
 | 1955 | class __save_flags | 
 | 1956 | { | 
 | 1957 |     typedef basic_ios<_CharT, _Traits> __stream_type; | 
 | 1958 |     typedef typename __stream_type::fmtflags fmtflags; | 
 | 1959 |  | 
 | 1960 |     __stream_type& __stream_; | 
 | 1961 |     fmtflags       __fmtflags_; | 
 | 1962 |     _CharT         __fill_; | 
 | 1963 |  | 
 | 1964 |     __save_flags(const __save_flags&); | 
 | 1965 |     __save_flags& operator=(const __save_flags&); | 
 | 1966 | public: | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1967 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 |     explicit __save_flags(__stream_type& __stream) | 
 | 1969 |         : __stream_(__stream), | 
 | 1970 |           __fmtflags_(__stream.flags()), | 
 | 1971 |           __fill_(__stream.fill()) | 
 | 1972 |         {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1973 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1974 |     ~__save_flags() | 
 | 1975 |     { | 
 | 1976 |         __stream_.flags(__fmtflags_); | 
 | 1977 |         __stream_.fill(__fill_); | 
 | 1978 |     } | 
 | 1979 | }; | 
 | 1980 |  | 
 | 1981 | template <class _CharT, class _Traits, | 
 | 1982 |           class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1983 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1984 | basic_ostream<_CharT, _Traits>& | 
 | 1985 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 1986 |            const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) | 
 | 1987 | { | 
 | 1988 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 1989 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 1990 |     __os.fill(__os.widen(' ')); | 
 | 1991 |     return __os << __x.__x_; | 
 | 1992 | } | 
 | 1993 |  | 
 | 1994 | template <class _CharT, class _Traits, | 
 | 1995 |           class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
 | 1996 | basic_istream<_CharT, _Traits>& | 
 | 1997 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 1998 |            linear_congruential_engine<_UIntType, __a, __c, __m>& __x) | 
 | 1999 | { | 
 | 2000 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 2001 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 2002 |     _UIntType __t; | 
 | 2003 |     __is >> __t; | 
 | 2004 |     if (!__is.fail()) | 
 | 2005 |         __x.__x_ = __t; | 
 | 2006 |     return __is; | 
 | 2007 | } | 
 | 2008 |  | 
 | 2009 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> | 
 | 2010 |                                                                    minstd_rand0; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2011 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> | 
 | 2012 |                                                                     minstd_rand; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2013 | typedef minstd_rand                                       default_random_engine; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | // mersenne_twister_engine | 
 | 2015 |  | 
 | 2016 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2017 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2018 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
 | 2019 | class mersenne_twister_engine; | 
 | 2020 |  | 
 | 2021 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2022 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2023 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2024 | bool | 
 | 2025 | operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2026 |                                          _B, _T, _C, _L, _F>& __x, | 
 | 2027 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2028 |                                          _B, _T, _C, _L, _F>& __y); | 
 | 2029 |  | 
 | 2030 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2031 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2032 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2033 | bool | 
 | 2034 | operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2035 |                                          _B, _T, _C, _L, _F>& __x, | 
 | 2036 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2037 |                                          _B, _T, _C, _L, _F>& __y); | 
 | 2038 |  | 
 | 2039 | template <class _CharT, class _Traits, | 
 | 2040 |           class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2041 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2042 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2043 | basic_ostream<_CharT, _Traits>& | 
 | 2044 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2045 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2046 |                                          _B, _T, _C, _L, _F>& __x); | 
 | 2047 |  | 
 | 2048 | template <class _CharT, class _Traits, | 
 | 2049 |           class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2050 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2051 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2052 | basic_istream<_CharT, _Traits>& | 
 | 2053 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2054 |            mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2055 |                                    _B, _T, _C, _L, _F>& __x); | 
 | 2056 |  | 
 | 2057 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2058 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2059 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2060 | class _LIBCPP_VISIBLE mersenne_twister_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2061 | { | 
 | 2062 | public: | 
 | 2063 |     // types | 
 | 2064 |     typedef _UIntType result_type; | 
 | 2065 |  | 
 | 2066 | private: | 
 | 2067 |     result_type __x_[__n]; | 
 | 2068 |     size_t      __i_; | 
 | 2069 |  | 
 | 2070 |     static_assert(  0 <  __m, "mersenne_twister_engine invalid parameters"); | 
 | 2071 |     static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); | 
 | 2072 |     static const result_type _Dt = numeric_limits<result_type>::digits; | 
 | 2073 |     static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); | 
 | 2074 |     static_assert(  2 <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2075 |     static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2076 |     static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2077 |     static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2078 |     static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2079 |     static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); | 
 | 2080 | public: | 
 | 2081 |     static const result_type _Min = 0; | 
 | 2082 |     static const result_type _Max = __w == _Dt ? result_type(~0) : | 
 | 2083 |                                    (result_type(1) << __w) - result_type(1); | 
 | 2084 |     static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2085 |     static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2086 |     static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2087 |     static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2088 |     static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2089 |     static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); | 
 | 2090 |  | 
 | 2091 |     // engine characteristics | 
 | 2092 |     static const/*expr*/ size_t word_size = __w; | 
 | 2093 |     static const/*expr*/ size_t state_size = __n; | 
 | 2094 |     static const/*expr*/ size_t shift_size = __m; | 
 | 2095 |     static const/*expr*/ size_t mask_bits = __r; | 
 | 2096 |     static const/*expr*/ result_type xor_mask = __a; | 
 | 2097 |     static const/*expr*/ size_t tempering_u = __u; | 
 | 2098 |     static const/*expr*/ result_type tempering_d = __d; | 
 | 2099 |     static const/*expr*/ size_t tempering_s = __s; | 
 | 2100 |     static const/*expr*/ result_type tempering_b = __b; | 
 | 2101 |     static const/*expr*/ size_t tempering_t = __t; | 
 | 2102 |     static const/*expr*/ result_type tempering_c = __c; | 
 | 2103 |     static const/*expr*/ size_t tempering_l = __l; | 
 | 2104 |     static const/*expr*/ result_type initialization_multiplier = __f; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2105 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 |     static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2107 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2108 |     static const/*expr*/ result_type max() { return _Max; } | 
 | 2109 |     static const/*expr*/ result_type default_seed = 5489u; | 
 | 2110 |  | 
 | 2111 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2112 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2113 |     explicit mersenne_twister_engine(result_type __sd = default_seed) | 
 | 2114 |         {seed(__sd);} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2115 |     template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q, | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2116 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2117 |         typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2118 |         {seed(__q);} | 
 | 2119 |     void seed(result_type __sd = default_seed); | 
 | 2120 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2121 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 |         typename enable_if | 
 | 2123 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2124 |             __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2125 |             void | 
 | 2126 |         >::type | 
 | 2127 |         seed(_Sseq& __q) | 
 | 2128 |             {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
 | 2129 |  | 
 | 2130 |     // generating functions | 
 | 2131 |     result_type operator()(); | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2132 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2133 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 2134 |  | 
 | 2135 |     template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2136 |               _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2137 |               _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2138 |     friend | 
 | 2139 |     bool | 
 | 2140 |     operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2141 |                                              _B, _T, _C, _L, _F>& __x, | 
 | 2142 |                const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2143 |                                              _B, _T, _C, _L, _F>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2144 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2145 |     template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2146 |               _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2147 |               _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2148 |     friend | 
 | 2149 |     bool | 
 | 2150 |     operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2151 |                                              _B, _T, _C, _L, _F>& __x, | 
 | 2152 |                const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2153 |                                              _B, _T, _C, _L, _F>& __y); | 
 | 2154 |  | 
 | 2155 |     template <class _CharT, class _Traits, | 
 | 2156 |               class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2157 |               _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2158 |               _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2159 |     friend | 
 | 2160 |     basic_ostream<_CharT, _Traits>& | 
 | 2161 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2162 |                const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2163 |                                              _B, _T, _C, _L, _F>& __x); | 
 | 2164 |  | 
 | 2165 |     template <class _CharT, class _Traits, | 
 | 2166 |               class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2167 |               _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2168 |               _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2169 |     friend | 
 | 2170 |     basic_istream<_CharT, _Traits>& | 
 | 2171 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2172 |                mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2173 |                                        _B, _T, _C, _L, _F>& __x); | 
 | 2174 | private: | 
 | 2175 |  | 
 | 2176 |     template<class _Sseq> | 
 | 2177 |         void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
 | 2178 |     template<class _Sseq> | 
 | 2179 |         void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
 | 2180 |  | 
 | 2181 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2182 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2183 |         static | 
 | 2184 |         typename enable_if | 
 | 2185 |         < | 
 | 2186 |             __count < __w, | 
 | 2187 |             result_type | 
 | 2188 |         >::type | 
 | 2189 |         __lshift(result_type __x) {return (__x << __count) & _Max;} | 
 | 2190 |  | 
 | 2191 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2192 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2193 |         static | 
 | 2194 |         typename enable_if | 
 | 2195 |         < | 
 | 2196 |             (__count >= __w), | 
 | 2197 |             result_type | 
 | 2198 |         >::type | 
 | 2199 |         __lshift(result_type __x) {return result_type(0);} | 
 | 2200 |  | 
 | 2201 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2202 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2203 |         static | 
 | 2204 |         typename enable_if | 
 | 2205 |         < | 
 | 2206 |             __count < _Dt, | 
 | 2207 |             result_type | 
 | 2208 |         >::type | 
 | 2209 |         __rshift(result_type __x) {return __x >> __count;} | 
 | 2210 |  | 
 | 2211 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2212 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2213 |         static | 
 | 2214 |         typename enable_if | 
 | 2215 |         < | 
 | 2216 |             (__count >= _Dt), | 
 | 2217 |             result_type | 
 | 2218 |         >::type | 
 | 2219 |         __rshift(result_type __x) {return result_type(0);} | 
 | 2220 | }; | 
 | 2221 |  | 
 | 2222 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2223 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2224 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
 | 2225 | void | 
 | 2226 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
 | 2227 |     __t, __c, __l, __f>::seed(result_type __sd) | 
 | 2228 | {   // __w >= 2 | 
 | 2229 |     __x_[0] = __sd & _Max; | 
 | 2230 |     for (size_t __i = 1; __i < __n; ++__i) | 
 | 2231 |         __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; | 
 | 2232 |     __i_ = 0; | 
 | 2233 | } | 
 | 2234 |  | 
 | 2235 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2236 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2237 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
 | 2238 | template<class _Sseq> | 
 | 2239 | void | 
 | 2240 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
 | 2241 |     __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) | 
 | 2242 | { | 
 | 2243 |     const unsigned __k = 1; | 
 | 2244 |     uint32_t __ar[__n * __k]; | 
 | 2245 |     __q.generate(__ar, __ar + __n * __k); | 
 | 2246 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 2247 |         __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); | 
 | 2248 |     const result_type __mask = __r == _Dt ? result_type(~0) : | 
 | 2249 |                                        (result_type(1) << __r) - result_type(1); | 
 | 2250 |     __i_ = 0; | 
 | 2251 |     if ((__x_[0] & ~__mask) == 0) | 
 | 2252 |     { | 
 | 2253 |         for (size_t __i = 1; __i < __n; ++__i) | 
 | 2254 |             if (__x_[__i] != 0) | 
 | 2255 |                 return; | 
 | 2256 |         __x_[0] = _Max; | 
 | 2257 |     } | 
 | 2258 | } | 
 | 2259 |  | 
 | 2260 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2261 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2262 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
 | 2263 | template<class _Sseq> | 
 | 2264 | void | 
 | 2265 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
 | 2266 |     __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) | 
 | 2267 | { | 
 | 2268 |     const unsigned __k = 2; | 
 | 2269 |     uint32_t __ar[__n * __k]; | 
 | 2270 |     __q.generate(__ar, __ar + __n * __k); | 
 | 2271 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 2272 |         __x_[__i] = static_cast<result_type>( | 
 | 2273 |             (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); | 
 | 2274 |     const result_type __mask = __r == _Dt ? result_type(~0) : | 
 | 2275 |                                        (result_type(1) << __r) - result_type(1); | 
 | 2276 |     __i_ = 0; | 
 | 2277 |     if ((__x_[0] & ~__mask) == 0) | 
 | 2278 |     { | 
 | 2279 |         for (size_t __i = 1; __i < __n; ++__i) | 
 | 2280 |             if (__x_[__i] != 0) | 
 | 2281 |                 return; | 
 | 2282 |         __x_[0] = _Max; | 
 | 2283 |     } | 
 | 2284 | } | 
 | 2285 |  | 
 | 2286 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
 | 2287 |           _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
 | 2288 |           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
 | 2289 | _UIntType | 
 | 2290 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
 | 2291 |     __t, __c, __l, __f>::operator()() | 
 | 2292 | { | 
 | 2293 |     const size_t __j = (__i_ + 1) % __n; | 
 | 2294 |     const result_type __mask = __r == _Dt ? result_type(~0) : | 
 | 2295 |                                        (result_type(1) << __r) - result_type(1); | 
 | 2296 |     const result_type _Y = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); | 
 | 2297 |     const size_t __k = (__i_ + __m) % __n; | 
 | 2298 |     __x_[__i_] = __x_[__k] ^ __rshift<1>(_Y) ^ (__a * (_Y & 1)); | 
 | 2299 |     result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); | 
 | 2300 |     __i_ = __j; | 
 | 2301 |     __z ^= __lshift<__s>(__z) & __b; | 
 | 2302 |     __z ^= __lshift<__t>(__z) & __c; | 
 | 2303 |     return __z ^ __rshift<__l>(__z); | 
 | 2304 | } | 
 | 2305 |  | 
 | 2306 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2307 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2308 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2309 | bool | 
 | 2310 | operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2311 |                                          _B, _T, _C, _L, _F>& __x, | 
 | 2312 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2313 |                                          _B, _T, _C, _L, _F>& __y) | 
 | 2314 | { | 
 | 2315 |     if (__x.__i_ == __y.__i_) | 
 | 2316 |         return _STD::equal(__x.__x_, __x.__x_ + _N, __y.__x_); | 
 | 2317 |     if (__x.__i_ == 0 || __y.__i_ == 0) | 
 | 2318 |     { | 
 | 2319 |         size_t __j = _STD::min(_N - __x.__i_, _N - __y.__i_); | 
 | 2320 |         if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, | 
 | 2321 |                          __y.__x_ + __y.__i_)) | 
 | 2322 |             return false; | 
 | 2323 |         if (__x.__i_ == 0) | 
 | 2324 |             return _STD::equal(__x.__x_ + __j, __x.__x_ + _N, __y.__x_); | 
 | 2325 |         return _STD::equal(__x.__x_, __x.__x_ + (_N - __j), __y.__x_ + __j); | 
 | 2326 |     } | 
 | 2327 |     if (__x.__i_ < __y.__i_) | 
 | 2328 |     { | 
 | 2329 |         size_t __j = _N - __y.__i_; | 
 | 2330 |         if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), | 
 | 2331 |                          __y.__x_ + __y.__i_)) | 
 | 2332 |             return false; | 
 | 2333 |         if (!_STD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _N, | 
 | 2334 |                          __y.__x_)) | 
 | 2335 |             return false; | 
 | 2336 |         return _STD::equal(__x.__x_, __x.__x_ + __x.__i_, | 
 | 2337 |                            __y.__x_ + (_N - (__x.__i_ + __j))); | 
 | 2338 |     } | 
 | 2339 |     size_t __j = _N - __x.__i_; | 
 | 2340 |     if (!_STD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), | 
 | 2341 |                      __x.__x_ + __x.__i_)) | 
 | 2342 |         return false; | 
 | 2343 |     if (!_STD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _N, | 
 | 2344 |                      __x.__x_)) | 
 | 2345 |         return false; | 
 | 2346 |     return _STD::equal(__y.__x_, __y.__x_ + __y.__i_, | 
 | 2347 |                        __x.__x_ + (_N - (__y.__i_ + __j))); | 
 | 2348 | } | 
 | 2349 |  | 
 | 2350 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2351 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2352 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2353 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | bool | 
 | 2355 | operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2356 |                                          _B, _T, _C, _L, _F>& __x, | 
 | 2357 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2358 |                                          _B, _T, _C, _L, _F>& __y) | 
 | 2359 | { | 
 | 2360 |     return !(__x == __y); | 
 | 2361 | } | 
 | 2362 |  | 
 | 2363 | template <class _CharT, class _Traits, | 
 | 2364 |           class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2365 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2366 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2367 | basic_ostream<_CharT, _Traits>& | 
 | 2368 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2369 |            const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2370 |                                          _B, _T, _C, _L, _F>& __x) | 
 | 2371 | { | 
 | 2372 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 2373 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 2374 |     _CharT __sp = __os.widen(' '); | 
 | 2375 |     __os.fill(__sp); | 
 | 2376 |     __os << __x.__x_[__x.__i_]; | 
 | 2377 |     for (size_t __j = __x.__i_ + 1; __j < _N; ++__j) | 
 | 2378 |         __os << __sp << __x.__x_[__j]; | 
 | 2379 |     for (size_t __j = 0; __j < __x.__i_; ++__j) | 
 | 2380 |         __os << __sp << __x.__x_[__j]; | 
 | 2381 |     return __os; | 
 | 2382 | } | 
 | 2383 |  | 
 | 2384 | template <class _CharT, class _Traits, | 
 | 2385 |           class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
 | 2386 |           _UI _A, size_t _U, _UI _D, size_t _S, | 
 | 2387 |           _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
 | 2388 | basic_istream<_CharT, _Traits>& | 
 | 2389 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2390 |            mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
 | 2391 |                                    _B, _T, _C, _L, _F>& __x) | 
 | 2392 | { | 
 | 2393 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 2394 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 2395 |     _UI __t[_N]; | 
 | 2396 |     for (size_t __i = 0; __i < _N; ++__i) | 
 | 2397 |         __is >> __t[__i]; | 
 | 2398 |     if (!__is.fail()) | 
 | 2399 |     { | 
 | 2400 |         for (size_t __i = 0; __i < _N; ++__i) | 
 | 2401 |             __x.__x_[__i] = __t[__i]; | 
 | 2402 |         __x.__i_ = 0; | 
 | 2403 |     } | 
 | 2404 |     return __is; | 
 | 2405 | } | 
 | 2406 |  | 
 | 2407 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, | 
 | 2408 |                                 0x9908b0df, 11, 0xffffffff, | 
 | 2409 |                                 7,  0x9d2c5680, | 
 | 2410 |                                 15, 0xefc60000, | 
 | 2411 |                                 18, 1812433253>                         mt19937; | 
 | 2412 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, | 
 | 2413 |                                 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, | 
 | 2414 |                                 17, 0x71d67fffeda60000ULL, | 
 | 2415 |                                 37, 0xfff7eee000000000ULL, | 
 | 2416 |                                 43, 6364136223846793005ULL>          mt19937_64; | 
 | 2417 |  | 
 | 2418 | // subtract_with_carry_engine | 
 | 2419 |  | 
 | 2420 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2421 | class subtract_with_carry_engine; | 
 | 2422 |  | 
 | 2423 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2424 | bool | 
 | 2425 | operator==( | 
 | 2426 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2427 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
 | 2428 |  | 
 | 2429 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2430 | bool | 
 | 2431 | operator!=( | 
 | 2432 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2433 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
 | 2434 |  | 
 | 2435 | template <class _CharT, class _Traits, | 
 | 2436 |           class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2437 | basic_ostream<_CharT, _Traits>& | 
 | 2438 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2439 |            const subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
 | 2440 |  | 
 | 2441 | template <class _CharT, class _Traits, | 
 | 2442 |           class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2443 | basic_istream<_CharT, _Traits>& | 
 | 2444 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2445 |            subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
 | 2446 |  | 
 | 2447 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2448 | class _LIBCPP_VISIBLE subtract_with_carry_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2449 | { | 
 | 2450 | public: | 
 | 2451 |     // types | 
 | 2452 |     typedef _UIntType result_type; | 
 | 2453 |  | 
 | 2454 | private: | 
 | 2455 |     result_type __x_[__r]; | 
 | 2456 |     result_type  __c_; | 
 | 2457 |     size_t      __i_; | 
 | 2458 |  | 
 | 2459 |     static const result_type _Dt = numeric_limits<result_type>::digits; | 
 | 2460 |     static_assert(  0 <  __w, "subtract_with_carry_engine invalid parameters"); | 
 | 2461 |     static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); | 
 | 2462 |     static_assert(  0 <  __s, "subtract_with_carry_engine invalid parameters"); | 
 | 2463 |     static_assert(__s <  __r, "subtract_with_carry_engine invalid parameters"); | 
 | 2464 | public: | 
 | 2465 |     static const result_type _Min = 0; | 
 | 2466 |     static const result_type _Max = __w == _Dt ? result_type(~0) : | 
 | 2467 |                                    (result_type(1) << __w) - result_type(1); | 
 | 2468 |     static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); | 
 | 2469 |  | 
 | 2470 |     // engine characteristics | 
 | 2471 |     static const/*expr*/ size_t word_size = __w; | 
 | 2472 |     static const/*expr*/ size_t short_lag = __s; | 
 | 2473 |     static const/*expr*/ size_t long_lag = __r; | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2474 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2475 |     static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2476 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2477 |     static const/*expr*/ result_type max() { return _Max; } | 
 | 2478 |     static const/*expr*/ result_type default_seed = 19780503u; | 
 | 2479 |  | 
 | 2480 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2481 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2482 |     explicit subtract_with_carry_engine(result_type __sd = default_seed) | 
 | 2483 |         {seed(__sd);} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2484 |     template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q, | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2485 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2486 |         typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2487 |         {seed(__q);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2488 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2489 |     void seed(result_type __sd = default_seed) | 
 | 2490 |         {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
 | 2491 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2492 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2493 |         typename enable_if | 
 | 2494 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2495 |             __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2496 |             void | 
 | 2497 |         >::type | 
 | 2498 |         seed(_Sseq& __q) | 
 | 2499 |             {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
 | 2500 |  | 
 | 2501 |     // generating functions | 
 | 2502 |     result_type operator()(); | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2503 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2504 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 2505 |  | 
 | 2506 |     template<class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2507 |     friend | 
 | 2508 |     bool | 
 | 2509 |     operator==( | 
 | 2510 |         const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2511 |         const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2512 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2513 |     template<class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2514 |     friend | 
 | 2515 |     bool | 
 | 2516 |     operator!=( | 
 | 2517 |         const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2518 |         const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2519 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2520 |     template <class _CharT, class _Traits, | 
 | 2521 |               class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2522 |     friend | 
 | 2523 |     basic_ostream<_CharT, _Traits>& | 
 | 2524 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2525 |                const subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2526 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2527 |     template <class _CharT, class _Traits, | 
 | 2528 |               class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2529 |     friend | 
 | 2530 |     basic_istream<_CharT, _Traits>& | 
 | 2531 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2532 |                subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
 | 2533 |  | 
 | 2534 | private: | 
 | 2535 |  | 
 | 2536 |     void seed(result_type __sd, integral_constant<unsigned, 1>); | 
 | 2537 |     void seed(result_type __sd, integral_constant<unsigned, 2>); | 
 | 2538 |     template<class _Sseq> | 
 | 2539 |         void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
 | 2540 |     template<class _Sseq> | 
 | 2541 |         void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
 | 2542 | }; | 
 | 2543 |  | 
 | 2544 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2545 | void | 
 | 2546 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, | 
 | 2547 |         integral_constant<unsigned, 1>) | 
 | 2548 | { | 
 | 2549 |     linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> | 
 | 2550 |         __e(__sd == 0u ? default_seed : __sd); | 
 | 2551 |     for (size_t __i = 0; __i < __r; ++__i) | 
 | 2552 |         __x_[__i] = static_cast<result_type>(__e() & _Max); | 
 | 2553 |     __c_ = __x_[__r-1] == 0; | 
 | 2554 |     __i_ = 0; | 
 | 2555 | } | 
 | 2556 |  | 
 | 2557 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2558 | void | 
 | 2559 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, | 
 | 2560 |         integral_constant<unsigned, 2>) | 
 | 2561 | { | 
 | 2562 |     linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> | 
 | 2563 |         __e(__sd == 0u ? default_seed : __sd); | 
 | 2564 |     for (size_t __i = 0; __i < __r; ++__i) | 
 | 2565 |         __x_[__i] = static_cast<result_type>( | 
 | 2566 |                                     (__e() + ((uint64_t)__e() << 32)) & _Max); | 
 | 2567 |     __c_ = __x_[__r-1] == 0; | 
 | 2568 |     __i_ = 0; | 
 | 2569 | } | 
 | 2570 |  | 
 | 2571 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2572 | template<class _Sseq> | 
 | 2573 | void | 
 | 2574 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, | 
 | 2575 |         integral_constant<unsigned, 1>) | 
 | 2576 | { | 
 | 2577 |     const unsigned __k = 1; | 
 | 2578 |     uint32_t __ar[__r * __k]; | 
 | 2579 |     __q.generate(__ar, __ar + __r * __k); | 
 | 2580 |     for (size_t __i = 0; __i < __r; ++__i) | 
 | 2581 |         __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); | 
 | 2582 |     __c_ = __x_[__r-1] == 0; | 
 | 2583 |     __i_ = 0; | 
 | 2584 | } | 
 | 2585 |  | 
 | 2586 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2587 | template<class _Sseq> | 
 | 2588 | void | 
 | 2589 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, | 
 | 2590 |         integral_constant<unsigned, 2>) | 
 | 2591 | { | 
 | 2592 |     const unsigned __k = 2; | 
 | 2593 |     uint32_t __ar[__r * __k]; | 
 | 2594 |     __q.generate(__ar, __ar + __r * __k); | 
 | 2595 |     for (size_t __i = 0; __i < __r; ++__i) | 
 | 2596 |         __x_[__i] = static_cast<result_type>( | 
 | 2597 |                   (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); | 
 | 2598 |     __c_ = __x_[__r-1] == 0; | 
 | 2599 |     __i_ = 0; | 
 | 2600 | } | 
 | 2601 |  | 
 | 2602 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
 | 2603 | _UIntType | 
 | 2604 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() | 
 | 2605 | { | 
 | 2606 |     const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; | 
 | 2607 |     result_type& __xr = __x_[__i_]; | 
 | 2608 |     result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; | 
 | 2609 |     __xr = (__xs - __xr - __c_) & _Max; | 
 | 2610 |     __c_ = __new_c; | 
 | 2611 |     __i_ = (__i_ + 1) % __r; | 
 | 2612 |     return __xr; | 
 | 2613 | } | 
 | 2614 |  | 
 | 2615 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2616 | bool | 
 | 2617 | operator==( | 
 | 2618 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2619 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __y) | 
 | 2620 | { | 
 | 2621 |     if (__x.__c_ != __y.__c_) | 
 | 2622 |         return false; | 
 | 2623 |     if (__x.__i_ == __y.__i_) | 
 | 2624 |         return _STD::equal(__x.__x_, __x.__x_ + _R, __y.__x_); | 
 | 2625 |     if (__x.__i_ == 0 || __y.__i_ == 0) | 
 | 2626 |     { | 
 | 2627 |         size_t __j = _STD::min(_R - __x.__i_, _R - __y.__i_); | 
 | 2628 |         if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, | 
 | 2629 |                          __y.__x_ + __y.__i_)) | 
 | 2630 |             return false; | 
 | 2631 |         if (__x.__i_ == 0) | 
 | 2632 |             return _STD::equal(__x.__x_ + __j, __x.__x_ + _R, __y.__x_); | 
 | 2633 |         return _STD::equal(__x.__x_, __x.__x_ + (_R - __j), __y.__x_ + __j); | 
 | 2634 |     } | 
 | 2635 |     if (__x.__i_ < __y.__i_) | 
 | 2636 |     { | 
 | 2637 |         size_t __j = _R - __y.__i_; | 
 | 2638 |         if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), | 
 | 2639 |                          __y.__x_ + __y.__i_)) | 
 | 2640 |             return false; | 
 | 2641 |         if (!_STD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _R, | 
 | 2642 |                          __y.__x_)) | 
 | 2643 |             return false; | 
 | 2644 |         return _STD::equal(__x.__x_, __x.__x_ + __x.__i_, | 
 | 2645 |                            __y.__x_ + (_R - (__x.__i_ + __j))); | 
 | 2646 |     } | 
 | 2647 |     size_t __j = _R - __x.__i_; | 
 | 2648 |     if (!_STD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), | 
 | 2649 |                      __x.__x_ + __x.__i_)) | 
 | 2650 |         return false; | 
 | 2651 |     if (!_STD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _R, | 
 | 2652 |                      __x.__x_)) | 
 | 2653 |         return false; | 
 | 2654 |     return _STD::equal(__y.__x_, __y.__x_ + __y.__i_, | 
 | 2655 |                        __x.__x_ + (_R - (__y.__i_ + __j))); | 
 | 2656 | } | 
 | 2657 |  | 
 | 2658 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2659 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | bool | 
 | 2661 | operator!=( | 
 | 2662 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
 | 2663 |     const subtract_with_carry_engine<_UI, _W, _S, _R>& __y) | 
 | 2664 | { | 
 | 2665 |     return !(__x == __y); | 
 | 2666 | } | 
 | 2667 |  | 
 | 2668 | template <class _CharT, class _Traits, | 
 | 2669 |           class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2670 | basic_ostream<_CharT, _Traits>& | 
 | 2671 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2672 |            const subtract_with_carry_engine<_UI, _W, _S, _R>& __x) | 
 | 2673 | { | 
 | 2674 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 2675 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 2676 |     _CharT __sp = __os.widen(' '); | 
 | 2677 |     __os.fill(__sp); | 
 | 2678 |     __os << __x.__x_[__x.__i_]; | 
 | 2679 |     for (size_t __j = __x.__i_ + 1; __j < _R; ++__j) | 
 | 2680 |         __os << __sp << __x.__x_[__j]; | 
 | 2681 |     for (size_t __j = 0; __j < __x.__i_; ++__j) | 
 | 2682 |         __os << __sp << __x.__x_[__j]; | 
 | 2683 |     __os << __sp << __x.__c_; | 
 | 2684 |     return __os; | 
 | 2685 | } | 
 | 2686 |  | 
 | 2687 | template <class _CharT, class _Traits, | 
 | 2688 |           class _UI, size_t _W, size_t _S, size_t _R> | 
 | 2689 | basic_istream<_CharT, _Traits>& | 
 | 2690 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2691 |            subtract_with_carry_engine<_UI, _W, _S, _R>& __x) | 
 | 2692 | { | 
 | 2693 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 2694 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 2695 |     _UI __t[_R+1]; | 
 | 2696 |     for (size_t __i = 0; __i < _R+1; ++__i) | 
 | 2697 |         __is >> __t[__i]; | 
 | 2698 |     if (!__is.fail()) | 
 | 2699 |     { | 
 | 2700 |         for (size_t __i = 0; __i < _R; ++__i) | 
 | 2701 |             __x.__x_[__i] = __t[__i]; | 
 | 2702 |         __x.__c_ = __t[_R]; | 
 | 2703 |         __x.__i_ = 0; | 
 | 2704 |     } | 
 | 2705 |     return __is; | 
 | 2706 | } | 
 | 2707 |  | 
 | 2708 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base; | 
 | 2709 | typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base; | 
 | 2710 |  | 
 | 2711 | // discard_block_engine | 
 | 2712 |  | 
 | 2713 | template<class _Engine, size_t __p, size_t __r> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2714 | class _LIBCPP_VISIBLE discard_block_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2715 | { | 
 | 2716 |     _Engine __e_; | 
 | 2717 |     int     __n_; | 
 | 2718 |  | 
 | 2719 |     static_assert(  0 <  __r, "discard_block_engine invalid parameters"); | 
 | 2720 |     static_assert(__r <= __p, "discard_block_engine invalid parameters"); | 
 | 2721 | public: | 
 | 2722 |     // types | 
 | 2723 |     typedef typename _Engine::result_type result_type; | 
 | 2724 |  | 
 | 2725 |     // engine characteristics | 
 | 2726 |     static const/*expr*/ size_t block_size = __p; | 
 | 2727 |     static const/*expr*/ size_t used_block = __r; | 
 | 2728 |  | 
 | 2729 |     // Temporary work around for lack of constexpr | 
 | 2730 |     static const result_type _Min = _Engine::_Min; | 
 | 2731 |     static const result_type _Max = _Engine::_Max; | 
 | 2732 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2733 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2734 |     static const/*expr*/ result_type min() { return _Engine::min(); } | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2735 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2736 |     static const/*expr*/ result_type max() { return _Engine::max(); } | 
 | 2737 |  | 
 | 2738 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2739 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2740 |     discard_block_engine() : __n_(0) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2741 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2742 |     explicit discard_block_engine(const _Engine& __e) | 
 | 2743 |         : __e_(__e), __n_(0) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2744 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2745 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2746 |     explicit discard_block_engine(_Engine&& __e) | 
 | 2747 |         : __e_(_STD::move(__e)), __n_(0) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2748 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2749 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2750 |     explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2751 |     template<class _Sseq> | 
 | 2752 |         _LIBCPP_INLINE_VISIBILITY | 
 | 2753 |         explicit discard_block_engine(_Sseq& __q, | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2754 |         typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2755 |                            !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2756 |         : __e_(__q), __n_(0) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2757 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2758 |     void seed() {__e_.seed(); __n_ = 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2759 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2760 |     void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2761 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2762 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2763 |         typename enable_if | 
 | 2764 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2765 |             __is_seed_sequence<_Sseq, discard_block_engine>::value, | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2766 |             void | 
 | 2767 |         >::type | 
 | 2768 |         seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2769 |  | 
 | 2770 |     // generating functions | 
 | 2771 |     result_type operator()(); | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2772 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2773 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 2774 |  | 
 | 2775 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2776 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2777 |     const _Engine& base() const {return __e_;} | 
 | 2778 |  | 
 | 2779 |     template<class _Eng, size_t _P, size_t _R> | 
 | 2780 |     friend | 
 | 2781 |     bool | 
 | 2782 |     operator==( | 
 | 2783 |         const discard_block_engine<_Eng, _P, _R>& __x, | 
 | 2784 |         const discard_block_engine<_Eng, _P, _R>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2785 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2786 |     template<class _Eng, size_t _P, size_t _R> | 
 | 2787 |     friend | 
 | 2788 |     bool | 
 | 2789 |     operator!=( | 
 | 2790 |         const discard_block_engine<_Eng, _P, _R>& __x, | 
 | 2791 |         const discard_block_engine<_Eng, _P, _R>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2792 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2793 |     template <class _CharT, class _Traits, | 
 | 2794 |               class _Eng, size_t _P, size_t _R> | 
 | 2795 |     friend | 
 | 2796 |     basic_ostream<_CharT, _Traits>& | 
 | 2797 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2798 |                const discard_block_engine<_Eng, _P, _R>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2799 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2800 |     template <class _CharT, class _Traits, | 
 | 2801 |               class _Eng, size_t _P, size_t _R> | 
 | 2802 |     friend | 
 | 2803 |     basic_istream<_CharT, _Traits>& | 
 | 2804 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2805 |                discard_block_engine<_Eng, _P, _R>& __x); | 
 | 2806 | }; | 
 | 2807 |  | 
 | 2808 | template<class _Engine, size_t __p, size_t __r> | 
 | 2809 | typename discard_block_engine<_Engine, __p, __r>::result_type | 
 | 2810 | discard_block_engine<_Engine, __p, __r>::operator()() | 
 | 2811 | { | 
 | 2812 |     if (__n_ >= __r) | 
 | 2813 |     { | 
 | 2814 |         __e_.discard(__p - __r); | 
 | 2815 |         __n_ = 0; | 
 | 2816 |     } | 
 | 2817 |     ++__n_; | 
 | 2818 |     return __e_(); | 
 | 2819 | } | 
 | 2820 |  | 
 | 2821 | template<class _Eng, size_t _P, size_t _R> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2822 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2823 | bool | 
 | 2824 | operator==(const discard_block_engine<_Eng, _P, _R>& __x, | 
 | 2825 |            const discard_block_engine<_Eng, _P, _R>& __y) | 
 | 2826 | { | 
 | 2827 |     return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; | 
 | 2828 | } | 
 | 2829 |  | 
 | 2830 | template<class _Eng, size_t _P, size_t _R> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2831 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2832 | bool | 
 | 2833 | operator!=(const discard_block_engine<_Eng, _P, _R>& __x, | 
 | 2834 |            const discard_block_engine<_Eng, _P, _R>& __y) | 
 | 2835 | { | 
 | 2836 |     return !(__x == __y); | 
 | 2837 | } | 
 | 2838 |  | 
 | 2839 | template <class _CharT, class _Traits, | 
 | 2840 |           class _Eng, size_t _P, size_t _R> | 
 | 2841 | basic_ostream<_CharT, _Traits>& | 
 | 2842 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2843 |            const discard_block_engine<_Eng, _P, _R>& __x) | 
 | 2844 | { | 
 | 2845 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 2846 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 2847 |     _CharT __sp = __os.widen(' '); | 
 | 2848 |     __os.fill(__sp); | 
 | 2849 |     return __os << __x.__e_ << __sp << __x.__n_; | 
 | 2850 | } | 
 | 2851 |  | 
 | 2852 | template <class _CharT, class _Traits, | 
 | 2853 |           class _Eng, size_t _P, size_t _R> | 
 | 2854 | basic_istream<_CharT, _Traits>& | 
 | 2855 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 2856 |            discard_block_engine<_Eng, _P, _R>& __x) | 
 | 2857 | { | 
 | 2858 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 2859 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 2860 |     _Eng __e; | 
 | 2861 |     int __n; | 
 | 2862 |     __is >> __e >> __n; | 
 | 2863 |     if (!__is.fail()) | 
 | 2864 |     { | 
 | 2865 |         __x.__e_ = __e; | 
 | 2866 |         __x.__n_ = __n; | 
 | 2867 |     } | 
 | 2868 |     return __is; | 
 | 2869 | } | 
 | 2870 |  | 
 | 2871 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; | 
 | 2872 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; | 
 | 2873 |  | 
 | 2874 | // independent_bits_engine | 
 | 2875 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2876 | template<class _Engine, size_t __w, class _UIntType> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2877 | class _LIBCPP_VISIBLE independent_bits_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2878 | { | 
 | 2879 |     template <class _UI, _UI _R0, size_t _W, size_t _M> | 
 | 2880 |     class __get_n | 
 | 2881 |     { | 
 | 2882 |         static const size_t _Dt = numeric_limits<_UI>::digits; | 
 | 2883 |         static const size_t _N = _W / _M + (_W % _M != 0); | 
 | 2884 |         static const size_t _W0 = _W / _N; | 
 | 2885 |         static const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; | 
 | 2886 |     public: | 
 | 2887 |         static const size_t value = _R0 - _Y0 > _Y0 / _N ? _N + 1 : _N; | 
 | 2888 |     }; | 
 | 2889 | public: | 
 | 2890 |     // types | 
 | 2891 |     typedef _UIntType result_type; | 
 | 2892 |  | 
 | 2893 | private: | 
 | 2894 |     _Engine __e_; | 
 | 2895 |  | 
 | 2896 |     static const result_type _Dt = numeric_limits<result_type>::digits; | 
 | 2897 |     static_assert(  0 <  __w, "independent_bits_engine invalid parameters"); | 
 | 2898 |     static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); | 
 | 2899 |  | 
 | 2900 |     typedef typename _Engine::result_type _Engine_result_type; | 
 | 2901 |     typedef typename conditional | 
 | 2902 |         < | 
 | 2903 |             sizeof(_Engine_result_type) <= sizeof(result_type), | 
 | 2904 |                 result_type, | 
 | 2905 |                 _Engine_result_type | 
 | 2906 |         >::type _Working_result_type; | 
 | 2907 |     // Temporary work around for lack of constexpr | 
 | 2908 |     static const _Working_result_type _R = _Engine::_Max - _Engine::_Min | 
 | 2909 |                                                          + _Working_result_type(1); | 
 | 2910 |     static const size_t __m = __log2<_Working_result_type, _R>::value; | 
 | 2911 |     static const size_t __n = __get_n<_Working_result_type, _R, __w, __m>::value; | 
 | 2912 |     static const size_t __w0 = __w / __n; | 
 | 2913 |     static const size_t __n0 = __n - __w % __n; | 
 | 2914 |     static const size_t _WDt = numeric_limits<_Working_result_type>::digits; | 
 | 2915 |     static const size_t _EDt = numeric_limits<_Engine_result_type>::digits; | 
 | 2916 |     static const _Working_result_type __y0 = __w0 >= _WDt ? 0 : | 
 | 2917 |                                                    (_R >> __w0) << __w0; | 
 | 2918 |     static const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : | 
 | 2919 |                                                    (_R >> (__w0+1)) << (__w0+1); | 
 | 2920 |     static const _Engine_result_type __mask0 = __w0 > 0 ? | 
 | 2921 |                                 _Engine_result_type(~0) >> (_EDt - __w0) : | 
 | 2922 |                                 _Engine_result_type(0); | 
 | 2923 |     static const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? | 
 | 2924 |                                 _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : | 
 | 2925 |                                 _Engine_result_type(~0); | 
 | 2926 | public: | 
 | 2927 |     static const result_type _Min = 0; | 
 | 2928 |     static const result_type _Max = __w == _Dt ? result_type(~0) : | 
 | 2929 |                                    (result_type(1) << __w) - result_type(1); | 
 | 2930 |     static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); | 
 | 2931 |  | 
 | 2932 |     // engine characteristics | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2933 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2934 |     static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2935 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2936 |     static const/*expr*/ result_type max() { return _Max; } | 
 | 2937 |  | 
 | 2938 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2939 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2940 |     independent_bits_engine() {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2941 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2942 |     explicit independent_bits_engine(const _Engine& __e) | 
 | 2943 |         : __e_(__e) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2944 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2945 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2946 |     explicit independent_bits_engine(_Engine&& __e) | 
 | 2947 |         : __e_(_STD::move(__e)) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2948 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2949 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2950 |     explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2951 |     template<class _Sseq> explicit independent_bits_engine(_Sseq& __q, | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2952 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2953 |         typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2954 |                            !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2955 |          : __e_(__q) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2956 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2957 |     void seed() {__e_.seed();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2958 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2959 |     void seed(result_type __sd) {__e_.seed(__sd);} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2960 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2961 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2962 |         typename enable_if | 
 | 2963 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2964 |             __is_seed_sequence<_Sseq, independent_bits_engine>::value, | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2965 |             void | 
 | 2966 |         >::type | 
 | 2967 |         seed(_Sseq& __q) {__e_.seed(__q);} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2968 |  | 
 | 2969 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2970 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2971 |     result_type operator()() {return __eval(integral_constant<bool, _R != 0>());} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2972 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2973 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 2974 |  | 
 | 2975 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2976 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2977 |     const _Engine& base() const {return __e_;} | 
 | 2978 |  | 
 | 2979 |     template<class _Eng, size_t _W, class _UI> | 
 | 2980 |     friend | 
 | 2981 |     bool | 
 | 2982 |     operator==( | 
 | 2983 |         const independent_bits_engine<_Eng, _W, _UI>& __x, | 
 | 2984 |         const independent_bits_engine<_Eng, _W, _UI>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2985 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 |     template<class _Eng, size_t _W, class _UI> | 
 | 2987 |     friend | 
 | 2988 |     bool | 
 | 2989 |     operator!=( | 
 | 2990 |         const independent_bits_engine<_Eng, _W, _UI>& __x, | 
 | 2991 |         const independent_bits_engine<_Eng, _W, _UI>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2992 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2993 |     template <class _CharT, class _Traits, | 
 | 2994 |               class _Eng, size_t _W, class _UI> | 
 | 2995 |     friend | 
 | 2996 |     basic_ostream<_CharT, _Traits>& | 
 | 2997 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 2998 |                const independent_bits_engine<_Eng, _W, _UI>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2999 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3000 |     template <class _CharT, class _Traits, | 
 | 3001 |               class _Eng, size_t _W, class _UI> | 
 | 3002 |     friend | 
 | 3003 |     basic_istream<_CharT, _Traits>& | 
 | 3004 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3005 |                independent_bits_engine<_Eng, _W, _UI>& __x); | 
 | 3006 |  | 
 | 3007 | private: | 
 | 3008 |     result_type __eval(false_type); | 
 | 3009 |     result_type __eval(true_type); | 
 | 3010 |  | 
 | 3011 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3012 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3013 |         static | 
 | 3014 |         typename enable_if | 
 | 3015 |         < | 
 | 3016 |             __count < _Dt, | 
 | 3017 |             result_type | 
 | 3018 |         >::type | 
 | 3019 |         __lshift(result_type __x) {return __x << __count;} | 
 | 3020 |  | 
 | 3021 |     template <size_t __count> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3022 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3023 |         static | 
 | 3024 |         typename enable_if | 
 | 3025 |         < | 
 | 3026 |             (__count >= _Dt), | 
 | 3027 |             result_type | 
 | 3028 |         >::type | 
 | 3029 |         __lshift(result_type __x) {return result_type(0);} | 
 | 3030 | }; | 
 | 3031 |  | 
 | 3032 | template<class _Engine, size_t __w, class _UIntType> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3033 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3034 | _UIntType | 
 | 3035 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) | 
 | 3036 | { | 
 | 3037 |     return static_cast<result_type>(__e_() & __mask0); | 
 | 3038 | } | 
 | 3039 |  | 
 | 3040 | template<class _Engine, size_t __w, class _UIntType> | 
 | 3041 | _UIntType | 
 | 3042 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) | 
 | 3043 | { | 
 | 3044 |     result_type _S = 0; | 
 | 3045 |     for (size_t __k = 0; __k < __n0; ++__k) | 
 | 3046 |     { | 
 | 3047 |         _Engine_result_type __u; | 
 | 3048 |         do | 
 | 3049 |         { | 
 | 3050 |             __u = __e_() - _Engine::min(); | 
 | 3051 |         } while (__u >= __y0); | 
 | 3052 |         _S = static_cast<result_type>(__lshift<__w0>(_S) + (__u & __mask0)); | 
 | 3053 |     } | 
 | 3054 |     for (size_t __k = __n0; __k < __n; ++__k) | 
 | 3055 |     { | 
 | 3056 |         _Engine_result_type __u; | 
 | 3057 |         do | 
 | 3058 |         { | 
 | 3059 |             __u = __e_() - _Engine::min(); | 
 | 3060 |         } while (__u >= __y1); | 
 | 3061 |         _S = static_cast<result_type>(__lshift<__w0+1>(_S) + (__u & __mask1)); | 
 | 3062 |     } | 
 | 3063 |     return _S; | 
 | 3064 | } | 
 | 3065 |  | 
 | 3066 | template<class _Eng, size_t _W, class _UI> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3067 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3068 | bool | 
 | 3069 | operator==( | 
 | 3070 |     const independent_bits_engine<_Eng, _W, _UI>& __x, | 
 | 3071 |     const independent_bits_engine<_Eng, _W, _UI>& __y) | 
 | 3072 | { | 
 | 3073 |     return __x.base() == __y.base(); | 
 | 3074 | } | 
 | 3075 |  | 
 | 3076 | template<class _Eng, size_t _W, class _UI> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3077 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3078 | bool | 
 | 3079 | operator!=( | 
 | 3080 |     const independent_bits_engine<_Eng, _W, _UI>& __x, | 
 | 3081 |     const independent_bits_engine<_Eng, _W, _UI>& __y) | 
 | 3082 | { | 
 | 3083 |     return !(__x == __y); | 
 | 3084 | } | 
 | 3085 |  | 
 | 3086 | template <class _CharT, class _Traits, | 
 | 3087 |           class _Eng, size_t _W, class _UI> | 
 | 3088 | basic_ostream<_CharT, _Traits>& | 
 | 3089 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3090 |            const independent_bits_engine<_Eng, _W, _UI>& __x) | 
 | 3091 | { | 
 | 3092 |     return __os << __x.base(); | 
 | 3093 | } | 
 | 3094 |  | 
 | 3095 | template <class _CharT, class _Traits, | 
 | 3096 |           class _Eng, size_t _W, class _UI> | 
 | 3097 | basic_istream<_CharT, _Traits>& | 
 | 3098 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3099 |            independent_bits_engine<_Eng, _W, _UI>& __x) | 
 | 3100 | { | 
 | 3101 |     _Eng __e; | 
 | 3102 |     __is >> __e; | 
 | 3103 |     if (!__is.fail()) | 
 | 3104 |         __x.__e_ = __e; | 
 | 3105 |     return __is; | 
 | 3106 | } | 
 | 3107 |  | 
 | 3108 | // shuffle_order_engine | 
 | 3109 |  | 
 | 3110 | template <uint64_t _Xp, uint64_t _Yp> | 
 | 3111 | struct __ugcd | 
 | 3112 | { | 
 | 3113 |     static const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; | 
 | 3114 | }; | 
 | 3115 |  | 
 | 3116 | template <uint64_t _Xp> | 
 | 3117 | struct __ugcd<_Xp, 0> | 
 | 3118 | { | 
 | 3119 |     static const uint64_t value = _Xp; | 
 | 3120 | }; | 
 | 3121 |  | 
 | 3122 | template <uint64_t _N, uint64_t _D> | 
 | 3123 | class __uratio | 
 | 3124 | { | 
 | 3125 |     static_assert(_D != 0, "__uratio divide by 0"); | 
 | 3126 |     static const uint64_t __gcd = __ugcd<_N, _D>::value; | 
 | 3127 | public: | 
 | 3128 |     static const uint64_t num = _N / __gcd; | 
 | 3129 |     static const uint64_t den = _D / __gcd; | 
 | 3130 |  | 
 | 3131 |     typedef __uratio<num, den> type; | 
 | 3132 | }; | 
 | 3133 |  | 
 | 3134 | template<class _Engine, size_t __k> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3135 | class _LIBCPP_VISIBLE shuffle_order_engine | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3136 | { | 
 | 3137 |     static_assert(0 < __k, "shuffle_order_engine invalid parameters"); | 
 | 3138 | public: | 
 | 3139 |     // types | 
 | 3140 |     typedef typename _Engine::result_type result_type; | 
 | 3141 |  | 
 | 3142 | private: | 
 | 3143 |     _Engine __e_; | 
 | 3144 |     result_type _V_[__k]; | 
 | 3145 |     result_type _Y_; | 
 | 3146 |  | 
 | 3147 | public: | 
 | 3148 |     // engine characteristics | 
 | 3149 |     static const/*expr*/ size_t table_size = __k; | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3150 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 |     static const result_type _Min = _Engine::_Min; | 
 | 3152 |     static const result_type _Max = _Engine::_Max; | 
 | 3153 |     static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3154 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 |     static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3156 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3157 |     static const/*expr*/ result_type max() { return _Max; } | 
 | 3158 |  | 
 | 3159 |     static const unsigned long long _R = _Max - _Min + 1ull; | 
 | 3160 |  | 
 | 3161 |     // constructors and seeding functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3162 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3163 |     shuffle_order_engine() {__init();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3164 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3165 |     explicit shuffle_order_engine(const _Engine& __e) | 
 | 3166 |         : __e_(__e) {__init();} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3167 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3168 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3169 |     explicit shuffle_order_engine(_Engine&& __e) | 
 | 3170 |         : __e_(_STD::move(__e)) {__init();} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3171 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3172 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3173 |     explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3174 |     template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q, | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3175 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3176 |         typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3177 |                            !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 |          : __e_(__q) {__init();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3179 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3180 |     void seed() {__e_.seed(); __init();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3181 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3182 |     void seed(result_type __sd) {__e_.seed(__sd); __init();} | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3183 |     template<class _Sseq> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3184 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3185 |         typename enable_if | 
 | 3186 |         < | 
| Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3187 |             __is_seed_sequence<_Sseq, shuffle_order_engine>::value, | 
| Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3188 |             void | 
 | 3189 |         >::type | 
 | 3190 |         seed(_Sseq& __q) {__e_.seed(__q); __init();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3191 |  | 
 | 3192 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3193 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3194 |     result_type operator()() {return __eval(integral_constant<bool, _R != 0>());} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3195 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3196 |     void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
 | 3197 |  | 
 | 3198 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3199 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3200 |     const _Engine& base() const {return __e_;} | 
 | 3201 |  | 
 | 3202 | private: | 
 | 3203 |     template<class _Eng, size_t _K> | 
 | 3204 |     friend | 
 | 3205 |     bool | 
 | 3206 |     operator==( | 
 | 3207 |         const shuffle_order_engine<_Eng, _K>& __x, | 
 | 3208 |         const shuffle_order_engine<_Eng, _K>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3209 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 |     template<class _Eng, size_t _K> | 
 | 3211 |     friend | 
 | 3212 |     bool | 
 | 3213 |     operator!=( | 
 | 3214 |         const shuffle_order_engine<_Eng, _K>& __x, | 
 | 3215 |         const shuffle_order_engine<_Eng, _K>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3216 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3217 |     template <class _CharT, class _Traits, | 
 | 3218 |               class _Eng, size_t _K> | 
 | 3219 |     friend | 
 | 3220 |     basic_ostream<_CharT, _Traits>& | 
 | 3221 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3222 |                const shuffle_order_engine<_Eng, _K>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3223 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3224 |     template <class _CharT, class _Traits, | 
 | 3225 |               class _Eng, size_t _K> | 
 | 3226 |     friend | 
 | 3227 |     basic_istream<_CharT, _Traits>& | 
 | 3228 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3229 |                shuffle_order_engine<_Eng, _K>& __x); | 
 | 3230 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3231 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3232 |     void __init() | 
 | 3233 |     { | 
 | 3234 |         for (size_t __i = 0; __i < __k; ++__i) | 
 | 3235 |             _V_[__i] = __e_(); | 
 | 3236 |         _Y_ = __e_(); | 
 | 3237 |     } | 
 | 3238 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3239 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3240 |     result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3241 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3242 |     result_type __eval(true_type) {return __eval(__uratio<__k, _R>());} | 
 | 3243 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3244 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3245 |     result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3246 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3247 |     result_type __eval2(true_type) {return __evalf<__k, 0>();} | 
 | 3248 |  | 
 | 3249 |     template <uint64_t _N, uint64_t _D> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3250 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3251 |         typename enable_if | 
 | 3252 |         < | 
 | 3253 |             (__uratio<_N, _D>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), | 
 | 3254 |             result_type | 
 | 3255 |         >::type | 
 | 3256 |         __eval(__uratio<_N, _D>) | 
 | 3257 |             {return __evalf<__uratio<_N, _D>::num, __uratio<_N, _D>::den>();} | 
 | 3258 |  | 
 | 3259 |     template <uint64_t _N, uint64_t _D> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3260 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3261 |         typename enable_if | 
 | 3262 |         < | 
 | 3263 |             __uratio<_N, _D>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), | 
 | 3264 |             result_type | 
 | 3265 |         >::type | 
 | 3266 |         __eval(__uratio<_N, _D>) | 
 | 3267 |         { | 
 | 3268 |             const size_t __j = static_cast<size_t>(__uratio<_N, _D>::num * (_Y_ - _Min) | 
 | 3269 |                                                    / __uratio<_N, _D>::den); | 
 | 3270 |             _Y_ = _V_[__j]; | 
 | 3271 |             _V_[__j] = __e_(); | 
 | 3272 |             return _Y_; | 
 | 3273 |         } | 
 | 3274 |  | 
 | 3275 |     template <uint64_t __n, uint64_t __d> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3276 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3277 |         result_type __evalf() | 
 | 3278 |         { | 
 | 3279 |             const double _F = __d == 0 ? | 
 | 3280 |                 __n / (2. * 0x8000000000000000ull) : | 
 | 3281 |                 __n / (double)__d; | 
 | 3282 |             const size_t __j = static_cast<size_t>(_F * (_Y_ - _Min)); | 
 | 3283 |             _Y_ = _V_[__j]; | 
 | 3284 |             _V_[__j] = __e_(); | 
 | 3285 |             return _Y_; | 
 | 3286 |         } | 
 | 3287 | }; | 
 | 3288 |  | 
 | 3289 | template<class _Eng, size_t _K> | 
 | 3290 | bool | 
 | 3291 | operator==( | 
 | 3292 |     const shuffle_order_engine<_Eng, _K>& __x, | 
 | 3293 |     const shuffle_order_engine<_Eng, _K>& __y) | 
 | 3294 | { | 
 | 3295 |     return __x._Y_ == __y._Y_ && _STD::equal(__x._V_, __x._V_ + _K, __y._V_) && | 
 | 3296 |            __x.__e_ == __y.__e_; | 
 | 3297 | } | 
 | 3298 |  | 
 | 3299 | template<class _Eng, size_t _K> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3300 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3301 | bool | 
 | 3302 | operator!=( | 
 | 3303 |     const shuffle_order_engine<_Eng, _K>& __x, | 
 | 3304 |     const shuffle_order_engine<_Eng, _K>& __y) | 
 | 3305 | { | 
 | 3306 |     return !(__x == __y); | 
 | 3307 | } | 
 | 3308 |  | 
 | 3309 | template <class _CharT, class _Traits, | 
 | 3310 |           class _Eng, size_t _K> | 
 | 3311 | basic_ostream<_CharT, _Traits>& | 
 | 3312 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3313 |            const shuffle_order_engine<_Eng, _K>& __x) | 
 | 3314 | { | 
 | 3315 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 3316 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 3317 |     _CharT __sp = __os.widen(' '); | 
 | 3318 |     __os.fill(__sp); | 
 | 3319 |     __os << __x.__e_ << __sp << __x._V_[0]; | 
 | 3320 |     for (size_t __i = 1; __i < _K; ++__i) | 
 | 3321 |         __os << __sp << __x._V_[__i]; | 
 | 3322 |     return __os << __sp << __x._Y_; | 
 | 3323 | } | 
 | 3324 |  | 
 | 3325 | template <class _CharT, class _Traits, | 
 | 3326 |           class _Eng, size_t _K> | 
 | 3327 | basic_istream<_CharT, _Traits>& | 
 | 3328 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3329 |            shuffle_order_engine<_Eng, _K>& __x) | 
 | 3330 | { | 
 | 3331 |     typedef typename shuffle_order_engine<_Eng, _K>::result_type result_type; | 
 | 3332 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 3333 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 3334 |     _Eng __e; | 
 | 3335 |     result_type _V[_K+1]; | 
 | 3336 |     __is >> __e; | 
 | 3337 |     for (size_t __i = 0; __i < _K+1; ++__i) | 
 | 3338 |         __is >> _V[__i]; | 
 | 3339 |     if (!__is.fail()) | 
 | 3340 |     { | 
 | 3341 |         __x.__e_ = __e; | 
 | 3342 |         for (size_t __i = 0; __i < _K; ++__i) | 
 | 3343 |             __x._V_[__i] = _V[__i]; | 
 | 3344 |         __x._Y_ = _V[_K]; | 
 | 3345 |     } | 
 | 3346 |     return __is; | 
 | 3347 | } | 
 | 3348 |  | 
 | 3349 | typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b; | 
 | 3350 |  | 
 | 3351 | // random_device | 
 | 3352 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3353 | class _LIBCPP_VISIBLE random_device | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3354 | { | 
 | 3355 |     int __f_; | 
 | 3356 | public: | 
 | 3357 |     // types | 
 | 3358 |     typedef unsigned result_type; | 
 | 3359 |  | 
 | 3360 |     // generator characteristics | 
 | 3361 |     static const result_type _Min = 0; | 
 | 3362 |     static const result_type _Max = 0xFFFFFFFFu; | 
 | 3363 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3364 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3365 |     static const/*expr*/ result_type min() { return _Min;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3366 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3367 |     static const/*expr*/ result_type max() { return _Max;} | 
 | 3368 |  | 
 | 3369 |     // constructors | 
 | 3370 |     explicit random_device(const string& __token = "/dev/urandom"); | 
 | 3371 |     ~random_device(); | 
 | 3372 |  | 
 | 3373 |     // generating functions | 
 | 3374 |     result_type operator()(); | 
 | 3375 |  | 
 | 3376 |     // property functions | 
 | 3377 |     double entropy() const; | 
 | 3378 |  | 
 | 3379 | private: | 
 | 3380 |     // no copy functions | 
 | 3381 |     random_device(const random_device&); // = delete; | 
 | 3382 |     random_device& operator=(const random_device&); // = delete; | 
 | 3383 | }; | 
 | 3384 |  | 
 | 3385 | // seed_seq | 
 | 3386 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3387 | class _LIBCPP_VISIBLE seed_seq | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3388 | { | 
 | 3389 | public: | 
 | 3390 |     // types | 
 | 3391 |     typedef uint32_t result_type; | 
 | 3392 |  | 
 | 3393 | private: | 
 | 3394 |     vector<result_type> __v_; | 
 | 3395 |  | 
 | 3396 |     template<class _InputIterator> | 
 | 3397 |         void init(_InputIterator __first, _InputIterator __last); | 
 | 3398 | public: | 
 | 3399 |     // constructors | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3400 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3401 |     seed_seq() {} | 
 | 3402 |     template<class _Tp> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3403 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3404 |         seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3405 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3406 |     template<class _InputIterator> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3407 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 |         seed_seq(_InputIterator __first, _InputIterator __last) | 
 | 3409 |              {init(__first, __last);} | 
 | 3410 |  | 
 | 3411 |     // generating functions | 
 | 3412 |     template<class _RandomAccessIterator> | 
 | 3413 |         void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); | 
 | 3414 |  | 
 | 3415 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3416 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3417 |     size_t size() const {return __v_.size();} | 
 | 3418 |     template<class _OutputIterator> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3419 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3420 |         void param(_OutputIterator __dest) const | 
 | 3421 |             {_STD::copy(__v_.begin(), __v_.end(), __dest);} | 
 | 3422 |  | 
 | 3423 | private: | 
 | 3424 |     // no copy functions | 
 | 3425 |     seed_seq(const seed_seq&); // = delete; | 
 | 3426 |     void operator=(const seed_seq&); // = delete; | 
 | 3427 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3428 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3429 |     static result_type _T(result_type __x) {return __x ^ (__x >> 27);} | 
 | 3430 | }; | 
 | 3431 |  | 
 | 3432 | template<class _InputIterator> | 
 | 3433 | void | 
 | 3434 | seed_seq::init(_InputIterator __first, _InputIterator __last) | 
 | 3435 | { | 
 | 3436 |     for (_InputIterator __s = __first; __s != __last; ++__s) | 
 | 3437 |         __v_.push_back(*__s & 0xFFFFFFFF); | 
 | 3438 | } | 
 | 3439 |  | 
 | 3440 | template<class _RandomAccessIterator> | 
 | 3441 | void | 
 | 3442 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) | 
 | 3443 | { | 
 | 3444 |     if (__first != __last) | 
 | 3445 |     { | 
 | 3446 |         _STD::fill(__first, __last, 0x8b8b8b8b); | 
 | 3447 |         const size_t __n = static_cast<size_t>(__last - __first); | 
 | 3448 |         const size_t __s = __v_.size(); | 
 | 3449 |         const size_t __t = (__n >= 623) ? 11 | 
 | 3450 |                          : (__n >= 68) ? 7 | 
 | 3451 |                          : (__n >= 39) ? 5 | 
 | 3452 |                          : (__n >= 7)  ? 3 | 
 | 3453 |                          : (__n - 1) / 2; | 
 | 3454 |         const size_t __p = (__n - __t) / 2; | 
 | 3455 |         const size_t __q = __p + __t; | 
 | 3456 |         const size_t __m = _STD::max(__s + 1, __n); | 
 | 3457 |         // __k = 0; | 
 | 3458 |         { | 
 | 3459 |             result_type __r = 1664525 * _T(__first[0] ^ __first[__p] | 
 | 3460 |                                                       ^  __first[__n - 1]); | 
 | 3461 |             __first[__p] += __r; | 
 | 3462 |             __r += __s; | 
 | 3463 |             __first[__q] += __r; | 
 | 3464 |             __first[0] = __r; | 
 | 3465 |         } | 
 | 3466 |         for (size_t __k = 1; __k <= __s; ++__k) | 
 | 3467 |         { | 
 | 3468 |             const size_t __kmodn = __k % __n; | 
 | 3469 |             const size_t __kpmodn = (__k + __p) % __n; | 
 | 3470 |             result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn] | 
 | 3471 |                                            ^ __first[(__k - 1) % __n]); | 
 | 3472 |             __first[__kpmodn] += __r; | 
 | 3473 |             __r +=  __kmodn + __v_[__k-1]; | 
 | 3474 |             __first[(__k + __q) % __n] += __r; | 
 | 3475 |             __first[__kmodn] = __r; | 
 | 3476 |         } | 
 | 3477 |         for (size_t __k = __s + 1; __k < __m; ++__k) | 
 | 3478 |         { | 
 | 3479 |             const size_t __kmodn = __k % __n; | 
 | 3480 |             const size_t __kpmodn = (__k + __p) % __n; | 
 | 3481 |             result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn] | 
 | 3482 |                                            ^ __first[(__k - 1) % __n]); | 
 | 3483 |             __first[__kpmodn] += __r; | 
 | 3484 |             __r +=  __kmodn; | 
 | 3485 |             __first[(__k + __q) % __n] += __r; | 
 | 3486 |             __first[__kmodn] = __r; | 
 | 3487 |         } | 
 | 3488 |         for (size_t __k = __m; __k < __m + __n; ++__k) | 
 | 3489 |         { | 
 | 3490 |             const size_t __kmodn = __k % __n; | 
 | 3491 |             const size_t __kpmodn = (__k + __p) % __n; | 
 | 3492 |             result_type __r = 1566083941 * _T(__first[__kmodn] + | 
 | 3493 |                                               __first[__kpmodn] + | 
 | 3494 |                                               __first[(__k - 1) % __n]); | 
 | 3495 |             __first[__kpmodn] ^= __r; | 
 | 3496 |             __r -= __kmodn; | 
 | 3497 |             __first[(__k + __q) % __n] ^= __r; | 
 | 3498 |             __first[__kmodn] = __r; | 
 | 3499 |         } | 
 | 3500 |     } | 
 | 3501 | } | 
 | 3502 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3503 | // generate_canonical | 
 | 3504 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3505 | template<class _RealType, size_t __bits, class _URNG> | 
 | 3506 | _RealType | 
 | 3507 | generate_canonical(_URNG& __g) | 
 | 3508 | { | 
 | 3509 |     const size_t _Dt = numeric_limits<_RealType>::digits; | 
 | 3510 |     const size_t __b = _Dt < __bits ? _Dt : __bits; | 
 | 3511 |     const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; | 
 | 3512 |     const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); | 
 | 3513 |     const _RealType _R = _URNG::_Max - _URNG::_Min + _RealType(1); | 
 | 3514 |     _RealType __base = _R; | 
 | 3515 |     _RealType _S = __g() - _URNG::_Min; | 
 | 3516 |     for (size_t __i = 1; __i < __k; ++__i, __base *= _R) | 
 | 3517 |         _S += (__g() - _URNG::_Min) * __base; | 
 | 3518 |     return _S / __base; | 
 | 3519 | } | 
 | 3520 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3521 | // uniform_int_distribution | 
 | 3522 |  | 
| Howard Hinnant | c326721 | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3523 | // in <algorithm> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3524 |  | 
 | 3525 | template <class _CharT, class _Traits, class _IT> | 
 | 3526 | basic_ostream<_CharT, _Traits>& | 
 | 3527 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3528 |            const uniform_int_distribution<_IT>& __x) | 
 | 3529 | { | 
 | 3530 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 3531 |     __os.flags(ios_base::dec | ios_base::left); | 
 | 3532 |     _CharT __sp = __os.widen(' '); | 
 | 3533 |     __os.fill(__sp); | 
 | 3534 |     return __os << __x.a() << __sp << __x.b(); | 
 | 3535 | } | 
 | 3536 |  | 
 | 3537 | template <class _CharT, class _Traits, class _IT> | 
 | 3538 | basic_istream<_CharT, _Traits>& | 
 | 3539 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3540 |            uniform_int_distribution<_IT>& __x) | 
 | 3541 | { | 
 | 3542 |     typedef uniform_int_distribution<_IT> _Eng; | 
 | 3543 |     typedef typename _Eng::result_type result_type; | 
 | 3544 |     typedef typename _Eng::param_type param_type; | 
 | 3545 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 3546 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 3547 |     result_type __a; | 
 | 3548 |     result_type __b; | 
 | 3549 |     __is >> __a >> __b; | 
 | 3550 |     if (!__is.fail()) | 
 | 3551 |         __x.param(param_type(__a, __b)); | 
 | 3552 |     return __is; | 
 | 3553 | } | 
 | 3554 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3555 | // uniform_real_distribution | 
 | 3556 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3557 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3558 | class _LIBCPP_VISIBLE uniform_real_distribution | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3559 | { | 
 | 3560 | public: | 
 | 3561 |     // types | 
 | 3562 |     typedef _RealType result_type; | 
 | 3563 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3564 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3565 |     { | 
 | 3566 |         result_type __a_; | 
 | 3567 |         result_type __b_; | 
 | 3568 |     public: | 
 | 3569 |         typedef uniform_real_distribution distribution_type; | 
 | 3570 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3571 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3572 |         explicit param_type(result_type __a = 0, | 
 | 3573 |                             result_type __b = 1) | 
 | 3574 |             : __a_(__a), __b_(__b) {} | 
 | 3575 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3576 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3577 |         result_type a() const {return __a_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3578 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 |         result_type b() const {return __b_;} | 
 | 3580 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3581 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3582 |         bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3583 |             {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3584 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3585 |         bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3586 |             {return !(__x == __y);} | 
 | 3587 |     }; | 
 | 3588 |  | 
 | 3589 | private: | 
 | 3590 |     param_type __p_; | 
 | 3591 |  | 
 | 3592 | public: | 
 | 3593 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3594 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3595 |     explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) | 
 | 3596 |         : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3597 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3598 |     explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3599 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3600 |     void reset() {} | 
 | 3601 |  | 
 | 3602 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3603 |     template<class _URNG> | 
 | 3604 |         _LIBCPP_INLINE_VISIBILITY | 
 | 3605 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3606 |         {return (*this)(__g, __p_);} | 
 | 3607 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 3608 |  | 
 | 3609 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3610 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3611 |     result_type a() const {return __p_.a();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3612 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3613 |     result_type b() const {return __p_.b();} | 
 | 3614 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3615 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3616 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3617 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 3619 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3620 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3621 |     result_type min() const {return a();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3622 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3623 |     result_type max() const {return b();} | 
 | 3624 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3625 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3626 |         bool operator==(const uniform_real_distribution& __x, | 
 | 3627 |                         const uniform_real_distribution& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3628 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3629 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3630 |         bool operator!=(const uniform_real_distribution& __x, | 
 | 3631 |                         const uniform_real_distribution& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3632 |         {return !(__x == __y);} | 
 | 3633 | }; | 
 | 3634 |  | 
 | 3635 | template<class _RealType> | 
 | 3636 | template<class _URNG> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3637 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3638 | typename uniform_real_distribution<_RealType>::result_type | 
 | 3639 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 3640 | { | 
 | 3641 |     return (__p.b() - __p.a()) | 
 | 3642 |         * _STD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) | 
 | 3643 |         + __p.a(); | 
 | 3644 | } | 
 | 3645 |  | 
 | 3646 | template <class _CharT, class _Traits, class _RT> | 
 | 3647 | basic_ostream<_CharT, _Traits>& | 
 | 3648 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3649 |            const uniform_real_distribution<_RT>& __x) | 
 | 3650 | { | 
 | 3651 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3652 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 3653 |                ios_base::scientific); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 |     _CharT __sp = __os.widen(' '); | 
 | 3655 |     __os.fill(__sp); | 
 | 3656 |     return __os << __x.a() << __sp << __x.b(); | 
 | 3657 | } | 
 | 3658 |  | 
 | 3659 | template <class _CharT, class _Traits, class _RT> | 
 | 3660 | basic_istream<_CharT, _Traits>& | 
 | 3661 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3662 |            uniform_real_distribution<_RT>& __x) | 
 | 3663 | { | 
 | 3664 |     typedef uniform_real_distribution<_RT> _Eng; | 
 | 3665 |     typedef typename _Eng::result_type result_type; | 
 | 3666 |     typedef typename _Eng::param_type param_type; | 
 | 3667 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 3668 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 3669 |     result_type __a; | 
 | 3670 |     result_type __b; | 
 | 3671 |     __is >> __a >> __b; | 
 | 3672 |     if (!__is.fail()) | 
 | 3673 |         __x.param(param_type(__a, __b)); | 
 | 3674 |     return __is; | 
 | 3675 | } | 
 | 3676 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3677 | // bernoulli_distribution | 
 | 3678 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3679 | class _LIBCPP_VISIBLE bernoulli_distribution | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3680 | { | 
 | 3681 | public: | 
 | 3682 |     // types | 
 | 3683 |     typedef bool result_type; | 
 | 3684 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3685 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3686 |     { | 
 | 3687 |         double __p_; | 
 | 3688 |     public: | 
 | 3689 |         typedef bernoulli_distribution distribution_type; | 
 | 3690 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3691 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3692 |         explicit param_type(double __p = 0.5) : __p_(__p) {} | 
 | 3693 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3694 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3695 |         double p() const {return __p_;} | 
 | 3696 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3697 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3698 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3699 |             {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3700 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3701 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3702 |             {return !(__x == __y);} | 
 | 3703 |     }; | 
 | 3704 |  | 
 | 3705 | private: | 
 | 3706 |     param_type __p_; | 
 | 3707 |  | 
 | 3708 | public: | 
 | 3709 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3710 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 |     explicit bernoulli_distribution(double __p = 0.5) | 
 | 3712 |         : __p_(param_type(__p)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3713 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3714 |     explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3715 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3716 |     void reset() {} | 
 | 3717 |  | 
 | 3718 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3719 |     template<class _URNG> | 
 | 3720 |         _LIBCPP_INLINE_VISIBILITY | 
 | 3721 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3722 |         {return (*this)(__g, __p_);} | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3723 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3724 |  | 
 | 3725 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3726 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3727 |     double p() const {return __p_.p();} | 
 | 3728 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3729 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3730 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3731 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3732 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 3733 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3734 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3735 |     result_type min() const {return false;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3736 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3737 |     result_type max() const {return true;} | 
 | 3738 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3739 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3740 |         bool operator==(const bernoulli_distribution& __x, | 
 | 3741 |                         const bernoulli_distribution& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3742 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3743 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3744 |         bool operator!=(const bernoulli_distribution& __x, | 
 | 3745 |                         const bernoulli_distribution& __y) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3746 |         {return !(__x == __y);} | 
 | 3747 | }; | 
 | 3748 |  | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3749 | template<class _URNG> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3750 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3751 | bernoulli_distribution::result_type | 
 | 3752 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) | 
 | 3753 | { | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 3754 |     uniform_real_distribution<double> __gen; | 
 | 3755 |     return __gen(__g) < __p.p(); | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3756 | } | 
 | 3757 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3758 | template <class _CharT, class _Traits> | 
 | 3759 | basic_ostream<_CharT, _Traits>& | 
 | 3760 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) | 
 | 3761 | { | 
 | 3762 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3763 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 3764 |                ios_base::scientific); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3765 |     _CharT __sp = __os.widen(' '); | 
 | 3766 |     __os.fill(__sp); | 
 | 3767 |     return __os << __x.p(); | 
 | 3768 | } | 
 | 3769 |  | 
 | 3770 | template <class _CharT, class _Traits> | 
 | 3771 | basic_istream<_CharT, _Traits>& | 
 | 3772 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) | 
 | 3773 | { | 
 | 3774 |     typedef bernoulli_distribution _Eng; | 
 | 3775 |     typedef typename _Eng::param_type param_type; | 
 | 3776 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 3777 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 3778 |     double __p; | 
 | 3779 |     __is >> __p; | 
 | 3780 |     if (!__is.fail()) | 
 | 3781 |         __x.param(param_type(__p)); | 
 | 3782 |     return __is; | 
 | 3783 | } | 
 | 3784 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3785 | // binomial_distribution | 
 | 3786 |  | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3787 | template<class _IntType = int> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3788 | class _LIBCPP_VISIBLE binomial_distribution | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3789 | { | 
 | 3790 | public: | 
 | 3791 |     // types | 
 | 3792 |     typedef _IntType result_type; | 
 | 3793 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3794 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3795 |     { | 
 | 3796 |         result_type __t_; | 
 | 3797 |         double __p_; | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3798 |         double __pr_; | 
 | 3799 |         double __odds_ratio_; | 
 | 3800 |         result_type __r0_; | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3801 |     public: | 
 | 3802 |         typedef binomial_distribution distribution_type; | 
 | 3803 |  | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3804 |         explicit param_type(result_type __t = 1, double __p = 0.5); | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3805 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3806 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3807 |         result_type t() const {return __t_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3808 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3809 |         double p() const {return __p_;} | 
 | 3810 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3811 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3812 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3813 |             {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3814 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3815 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3816 |             {return !(__x == __y);} | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3817 |  | 
 | 3818 |         friend class binomial_distribution; | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3819 |     }; | 
 | 3820 |  | 
 | 3821 | private: | 
 | 3822 |     param_type __p_; | 
 | 3823 |  | 
 | 3824 | public: | 
 | 3825 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3826 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3827 |     explicit binomial_distribution(result_type __t = 1, double __p = 0.5) | 
 | 3828 |         : __p_(param_type(__t, __p)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3829 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3830 |     explicit binomial_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3831 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3832 |     void reset() {} | 
 | 3833 |  | 
 | 3834 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3835 |     template<class _URNG> | 
 | 3836 |         _LIBCPP_INLINE_VISIBILITY | 
 | 3837 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3838 |         {return (*this)(__g, __p_);} | 
 | 3839 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 3840 |  | 
 | 3841 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3842 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3843 |     result_type t() const {return __p_.t();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3844 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3845 |     double p() const {return __p_.p();} | 
 | 3846 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3847 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3848 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3849 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3850 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 3851 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3852 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3853 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3854 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3855 |     result_type max() const {return t();} | 
 | 3856 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3857 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3858 |         bool operator==(const binomial_distribution& __x, | 
 | 3859 |                         const binomial_distribution& __y) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3860 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3861 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 3862 |         bool operator!=(const binomial_distribution& __x, | 
 | 3863 |                         const binomial_distribution& __y) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3864 |         {return !(__x == __y);} | 
 | 3865 | }; | 
 | 3866 |  | 
 | 3867 | template<class _IntType> | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3868 | binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) | 
 | 3869 |     : __t_(__t), __p_(__p) | 
 | 3870 | { | 
 | 3871 |     if (0 < __p_ && __p_ < 1) | 
 | 3872 |     { | 
 | 3873 |         __r0_ = static_cast<result_type>((__t_ + 1) * __p_); | 
 | 3874 |         __pr_ = _STD::exp(_STD::lgamma(__t_ + 1.) - _STD::lgamma(__r0_ + 1.) - | 
 | 3875 |                           _STD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _STD::log(__p_) + | 
 | 3876 |                           (__t_ - __r0_) * _STD::log(1 - __p_)); | 
 | 3877 |         __odds_ratio_ = __p_ / (1 - __p_); | 
 | 3878 |     } | 
 | 3879 | } | 
 | 3880 |  | 
 | 3881 | template<class _IntType> | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3882 | template<class _URNG> | 
 | 3883 | _IntType | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3884 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3885 | { | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3886 |     if (__pr.__t_ == 0 || __pr.__p_ == 0) | 
 | 3887 |         return 0; | 
 | 3888 |     if (__pr.__p_ == 1) | 
 | 3889 |         return __pr.__t_; | 
 | 3890 |     uniform_real_distribution<double> __gen; | 
 | 3891 |     double __u = __gen(__g) - __pr.__pr_; | 
 | 3892 |     if (__u < 0) | 
 | 3893 |         return __pr.__r0_; | 
 | 3894 |     double __pu = __pr.__pr_; | 
 | 3895 |     double __pd = __pu; | 
 | 3896 |     result_type __ru = __pr.__r0_; | 
 | 3897 |     result_type __rd = __ru; | 
 | 3898 |     while (true) | 
 | 3899 |     { | 
 | 3900 |         if (__rd >= 1) | 
 | 3901 |         { | 
 | 3902 |             __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); | 
 | 3903 |             __u -= __pd; | 
 | 3904 |             if (__u < 0) | 
 | 3905 |                 return __rd - 1; | 
 | 3906 |         } | 
 | 3907 |         --__rd; | 
 | 3908 |         ++__ru; | 
 | 3909 |         if (__ru <= __pr.__t_) | 
 | 3910 |         { | 
 | 3911 |             __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; | 
 | 3912 |             __u -= __pu; | 
 | 3913 |             if (__u < 0) | 
 | 3914 |                 return __ru; | 
 | 3915 |         } | 
 | 3916 |     } | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3917 | } | 
 | 3918 |  | 
 | 3919 | template <class _CharT, class _Traits, class _IntType> | 
 | 3920 | basic_ostream<_CharT, _Traits>& | 
 | 3921 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 3922 |            const binomial_distribution<_IntType>& __x) | 
 | 3923 | { | 
 | 3924 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3925 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 3926 |                ios_base::scientific); | 
| Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3927 |     _CharT __sp = __os.widen(' '); | 
 | 3928 |     __os.fill(__sp); | 
 | 3929 |     return __os << __x.t() << __sp << __x.p(); | 
 | 3930 | } | 
 | 3931 |  | 
 | 3932 | template <class _CharT, class _Traits, class _IntType> | 
 | 3933 | basic_istream<_CharT, _Traits>& | 
 | 3934 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 3935 |            binomial_distribution<_IntType>& __x) | 
 | 3936 | { | 
 | 3937 |     typedef binomial_distribution<_IntType> _Eng; | 
 | 3938 |     typedef typename _Eng::result_type result_type; | 
 | 3939 |     typedef typename _Eng::param_type param_type; | 
 | 3940 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 3941 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 3942 |     result_type __t; | 
 | 3943 |     double __p; | 
 | 3944 |     __is >> __t >> __p; | 
 | 3945 |     if (!__is.fail()) | 
 | 3946 |         __x.param(param_type(__t, __p)); | 
 | 3947 |     return __is; | 
 | 3948 | } | 
 | 3949 |  | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3950 | // exponential_distribution | 
 | 3951 |  | 
 | 3952 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3953 | class _LIBCPP_VISIBLE exponential_distribution | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3954 | { | 
 | 3955 | public: | 
 | 3956 |     // types | 
 | 3957 |     typedef _RealType result_type; | 
 | 3958 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3959 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3960 |     { | 
 | 3961 |         result_type __lambda_; | 
 | 3962 |     public: | 
 | 3963 |         typedef exponential_distribution distribution_type; | 
 | 3964 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3965 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3966 |         explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} | 
 | 3967 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3968 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3969 |         result_type lambda() const {return __lambda_;} | 
 | 3970 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3971 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3972 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3973 |             {return __x.__lambda_ == __y.__lambda_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3974 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 3975 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3976 |             {return !(__x == __y);} | 
 | 3977 |     }; | 
 | 3978 |  | 
 | 3979 | private: | 
 | 3980 |     param_type __p_; | 
 | 3981 |  | 
 | 3982 | public: | 
 | 3983 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3984 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3985 |     explicit exponential_distribution(result_type __lambda = 1) | 
 | 3986 |         : __p_(param_type(__lambda)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3987 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3988 |     explicit exponential_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3989 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3990 |     void reset() {} | 
 | 3991 |  | 
 | 3992 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3993 |     template<class _URNG> | 
 | 3994 |         _LIBCPP_INLINE_VISIBILITY | 
 | 3995 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3996 |         {return (*this)(__g, __p_);} | 
 | 3997 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 3998 |  | 
 | 3999 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4000 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4001 |     result_type lambda() const {return __p_.lambda();} | 
 | 4002 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4003 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4004 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4005 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4006 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4007 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4008 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4009 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4010 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | df40dc6 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4011 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4012 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4013 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4014 |         bool operator==(const exponential_distribution& __x, | 
 | 4015 |                         const exponential_distribution& __y) | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4016 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4017 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4018 |         bool operator!=(const exponential_distribution& __x, | 
 | 4019 |                         const exponential_distribution& __y) | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4020 |         {return !(__x == __y);} | 
 | 4021 | }; | 
 | 4022 |  | 
 | 4023 | template <class _RealType> | 
 | 4024 | template<class _URNG> | 
 | 4025 | _RealType | 
 | 4026 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 4027 | { | 
 | 4028 |     return -_STD::log | 
 | 4029 |                   ( | 
 | 4030 |                       result_type(1) - | 
 | 4031 |                       _STD::generate_canonical<result_type, | 
 | 4032 |                                        numeric_limits<result_type>::digits>(__g) | 
 | 4033 |                   ) | 
 | 4034 |                   / __p.lambda(); | 
 | 4035 | } | 
 | 4036 |  | 
 | 4037 | template <class _CharT, class _Traits, class _RealType> | 
 | 4038 | basic_ostream<_CharT, _Traits>& | 
 | 4039 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4040 |            const exponential_distribution<_RealType>& __x) | 
 | 4041 | { | 
 | 4042 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4043 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4044 |                ios_base::scientific); | 
| Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4045 |     return __os << __x.lambda(); | 
 | 4046 | } | 
 | 4047 |  | 
 | 4048 | template <class _CharT, class _Traits, class _RealType> | 
 | 4049 | basic_istream<_CharT, _Traits>& | 
 | 4050 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4051 |            exponential_distribution<_RealType>& __x) | 
 | 4052 | { | 
 | 4053 |     typedef exponential_distribution<_RealType> _Eng; | 
 | 4054 |     typedef typename _Eng::result_type result_type; | 
 | 4055 |     typedef typename _Eng::param_type param_type; | 
 | 4056 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4057 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4058 |     result_type __lambda; | 
 | 4059 |     __is >> __lambda; | 
 | 4060 |     if (!__is.fail()) | 
 | 4061 |         __x.param(param_type(__lambda)); | 
 | 4062 |     return __is; | 
 | 4063 | } | 
 | 4064 |  | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4065 | // normal_distribution | 
 | 4066 |  | 
 | 4067 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4068 | class _LIBCPP_VISIBLE normal_distribution | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4069 | { | 
 | 4070 | public: | 
 | 4071 |     // types | 
 | 4072 |     typedef _RealType result_type; | 
 | 4073 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4074 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4075 |     { | 
 | 4076 |         result_type __mean_; | 
 | 4077 |         result_type __stddev_; | 
 | 4078 |     public: | 
 | 4079 |         typedef normal_distribution distribution_type; | 
 | 4080 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4081 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4082 |         explicit param_type(result_type __mean = 0, result_type __stddev = 1) | 
 | 4083 |             : __mean_(__mean), __stddev_(__stddev) {} | 
 | 4084 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4085 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4086 |         result_type mean() const {return __mean_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4087 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4088 |         result_type stddev() const {return __stddev_;} | 
 | 4089 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4090 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4091 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4092 |             {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4093 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4094 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4095 |             {return !(__x == __y);} | 
 | 4096 |     }; | 
 | 4097 |  | 
 | 4098 | private: | 
 | 4099 |     param_type __p_; | 
 | 4100 |     result_type _V_; | 
 | 4101 |     bool _V_hot_; | 
 | 4102 |  | 
 | 4103 | public: | 
 | 4104 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4105 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4106 |     explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) | 
 | 4107 |         : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4108 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4109 |     explicit normal_distribution(const param_type& __p) | 
 | 4110 |         : __p_(__p), _V_hot_(false) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4111 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4112 |     void reset() {_V_hot_ = false;} | 
 | 4113 |  | 
 | 4114 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4115 |     template<class _URNG> | 
 | 4116 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4117 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4118 |         {return (*this)(__g, __p_);} | 
 | 4119 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 4120 |  | 
 | 4121 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4122 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4123 |     result_type mean() const {return __p_.mean();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4124 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4125 |     result_type stddev() const {return __p_.stddev();} | 
 | 4126 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4127 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4128 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4129 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4130 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4131 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4132 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4133 |     result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4134 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4135 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
 | 4136 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4137 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4138 |         bool operator==(const normal_distribution& __x, | 
 | 4139 |                         const normal_distribution& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4140 |         {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && | 
 | 4141 |                 (!__x._V_hot_ || __x._V_ == __y._V_);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4142 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4143 |         bool operator!=(const normal_distribution& __x, | 
 | 4144 |                         const normal_distribution& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4145 |         {return !(__x == __y);} | 
 | 4146 |  | 
 | 4147 |     template <class _CharT, class _Traits, class _RT> | 
 | 4148 |     friend | 
 | 4149 |     basic_ostream<_CharT, _Traits>& | 
 | 4150 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4151 |                const normal_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4152 |  | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4153 |     template <class _CharT, class _Traits, class _RT> | 
 | 4154 |     friend | 
 | 4155 |     basic_istream<_CharT, _Traits>& | 
 | 4156 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4157 |                normal_distribution<_RT>& __x); | 
 | 4158 | }; | 
 | 4159 |  | 
 | 4160 | template <class _RealType> | 
 | 4161 | template<class _URNG> | 
 | 4162 | _RealType | 
 | 4163 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 4164 | { | 
 | 4165 |     result_type _U; | 
 | 4166 |     if (_V_hot_) | 
 | 4167 |     { | 
 | 4168 |         _V_hot_ = false; | 
 | 4169 |         _U = _V_; | 
 | 4170 |     } | 
 | 4171 |     else | 
 | 4172 |     { | 
 | 4173 |         uniform_real_distribution<result_type> _Uni(-1, 1); | 
 | 4174 |         result_type __u; | 
 | 4175 |         result_type __v; | 
 | 4176 |         result_type __s; | 
 | 4177 |         do | 
 | 4178 |         { | 
 | 4179 |             __u = _Uni(__g); | 
 | 4180 |             __v = _Uni(__g); | 
 | 4181 |             __s = __u * __u + __v * __v; | 
 | 4182 |         } while (__s > 1 || __s == 0); | 
 | 4183 |         result_type _F = _STD::sqrt(-2 * _STD::log(__s) / __s); | 
 | 4184 |         _V_ = __v * _F; | 
 | 4185 |         _V_hot_ = true; | 
 | 4186 |         _U = __u * _F; | 
 | 4187 |     } | 
 | 4188 |     return _U * __p.stddev() + __p.mean(); | 
 | 4189 | } | 
 | 4190 |  | 
 | 4191 | template <class _CharT, class _Traits, class _RT> | 
 | 4192 | basic_ostream<_CharT, _Traits>& | 
 | 4193 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4194 |            const normal_distribution<_RT>& __x) | 
 | 4195 | { | 
 | 4196 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4197 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4198 |                ios_base::scientific); | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4199 |     _CharT __sp = __os.widen(' '); | 
 | 4200 |     __os.fill(__sp); | 
 | 4201 |     __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; | 
 | 4202 |     if (__x._V_hot_) | 
 | 4203 |         __os << __sp << __x._V_; | 
 | 4204 |     return __os; | 
 | 4205 | } | 
 | 4206 |  | 
 | 4207 | template <class _CharT, class _Traits, class _RT> | 
 | 4208 | basic_istream<_CharT, _Traits>& | 
 | 4209 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4210 |            normal_distribution<_RT>& __x) | 
 | 4211 | { | 
 | 4212 |     typedef normal_distribution<_RT> _Eng; | 
 | 4213 |     typedef typename _Eng::result_type result_type; | 
 | 4214 |     typedef typename _Eng::param_type param_type; | 
 | 4215 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4216 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4217 |     result_type __mean; | 
 | 4218 |     result_type __stddev; | 
 | 4219 |     result_type _V = 0; | 
 | 4220 |     bool _V_hot = false; | 
 | 4221 |     __is >> __mean >> __stddev >> _V_hot; | 
 | 4222 |     if (_V_hot) | 
 | 4223 |         __is >> _V; | 
 | 4224 |     if (!__is.fail()) | 
 | 4225 |     { | 
 | 4226 |         __x.param(param_type(__mean, __stddev)); | 
 | 4227 |         __x._V_hot_ = _V_hot; | 
 | 4228 |         __x._V_ = _V; | 
 | 4229 |     } | 
 | 4230 |     return __is; | 
 | 4231 | } | 
 | 4232 |  | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4233 | // lognormal_distribution | 
 | 4234 |  | 
 | 4235 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4236 | class _LIBCPP_VISIBLE lognormal_distribution | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4237 | { | 
 | 4238 | public: | 
 | 4239 |     // types | 
 | 4240 |     typedef _RealType result_type; | 
 | 4241 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4242 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4243 |     { | 
 | 4244 |         normal_distribution<result_type> __nd_; | 
 | 4245 |     public: | 
 | 4246 |         typedef lognormal_distribution distribution_type; | 
 | 4247 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4248 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4249 |         explicit param_type(result_type __m = 0, result_type __s = 1) | 
 | 4250 |             : __nd_(__m, __s) {} | 
 | 4251 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4252 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4253 |         result_type m() const {return __nd_.mean();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4254 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4255 |         result_type s() const {return __nd_.stddev();} | 
 | 4256 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4257 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4258 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4259 |             {return __x.__nd_ == __y.__nd_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4260 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4261 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4262 |             {return !(__x == __y);} | 
 | 4263 |         friend class lognormal_distribution; | 
 | 4264 |  | 
 | 4265 |         template <class _CharT, class _Traits, class _RT> | 
 | 4266 |         friend | 
 | 4267 |         basic_ostream<_CharT, _Traits>& | 
 | 4268 |         operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4269 |                    const lognormal_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4270 |  | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4271 |         template <class _CharT, class _Traits, class _RT> | 
 | 4272 |         friend | 
 | 4273 |         basic_istream<_CharT, _Traits>& | 
 | 4274 |         operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4275 |                    lognormal_distribution<_RT>& __x); | 
 | 4276 |     }; | 
 | 4277 |  | 
 | 4278 | private: | 
 | 4279 |     param_type __p_; | 
 | 4280 |  | 
 | 4281 | public: | 
 | 4282 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4283 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4284 |     explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) | 
 | 4285 |         : __p_(param_type(__m, __s)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4286 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4287 |     explicit lognormal_distribution(const param_type& __p) | 
 | 4288 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4289 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4290 |     void reset() {__p_.__nd_.reset();} | 
 | 4291 |  | 
 | 4292 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4293 |     template<class _URNG> | 
 | 4294 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4295 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4296 |         {return (*this)(__g, __p_);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4297 |     template<class _URNG> | 
 | 4298 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4299 |         result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4300 |         {return _STD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} | 
 | 4301 |  | 
 | 4302 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4303 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4304 |     result_type m() const {return __p_.m();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4305 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4306 |     result_type s() const {return __p_.s();} | 
 | 4307 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4308 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4309 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4310 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4311 |     void param(const param_type& __p) {__p_ = __p;} | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4312 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4313 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4314 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4315 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4316 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
 | 4317 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4318 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4319 |         bool operator==(const lognormal_distribution& __x, | 
 | 4320 |                         const lognormal_distribution& __y) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4321 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4322 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4323 |         bool operator!=(const lognormal_distribution& __x, | 
 | 4324 |                         const lognormal_distribution& __y) | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4325 |         {return !(__x == __y);} | 
 | 4326 |  | 
 | 4327 |     template <class _CharT, class _Traits, class _RT> | 
 | 4328 |     friend | 
 | 4329 |     basic_ostream<_CharT, _Traits>& | 
 | 4330 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4331 |                const lognormal_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4332 |  | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4333 |     template <class _CharT, class _Traits, class _RT> | 
 | 4334 |     friend | 
 | 4335 |     basic_istream<_CharT, _Traits>& | 
 | 4336 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4337 |                lognormal_distribution<_RT>& __x); | 
 | 4338 | }; | 
 | 4339 |  | 
 | 4340 | template <class _CharT, class _Traits, class _RT> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4341 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4342 | basic_ostream<_CharT, _Traits>& | 
 | 4343 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4344 |            const lognormal_distribution<_RT>& __x) | 
 | 4345 | { | 
 | 4346 |     return __os << __x.__p_.__nd_; | 
 | 4347 | } | 
 | 4348 |  | 
 | 4349 | template <class _CharT, class _Traits, class _RT> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4350 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4351 | basic_istream<_CharT, _Traits>& | 
 | 4352 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4353 |            lognormal_distribution<_RT>& __x) | 
 | 4354 | { | 
 | 4355 |     return __is >> __x.__p_.__nd_; | 
 | 4356 | } | 
 | 4357 |  | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4358 | // poisson_distribution | 
 | 4359 |  | 
 | 4360 | template<class _IntType = int> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4361 | class _LIBCPP_VISIBLE poisson_distribution | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4362 | { | 
 | 4363 | public: | 
 | 4364 |     // types | 
 | 4365 |     typedef _IntType result_type; | 
 | 4366 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4367 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4368 |     { | 
 | 4369 |         double __mean_; | 
 | 4370 |         double __s_; | 
 | 4371 |         double __d_; | 
 | 4372 |         double __l_; | 
 | 4373 |         double __omega_; | 
 | 4374 |         double __c0_; | 
 | 4375 |         double __c1_; | 
 | 4376 |         double __c2_; | 
 | 4377 |         double __c3_; | 
 | 4378 |         double __c_; | 
 | 4379 |  | 
 | 4380 |     public: | 
 | 4381 |         typedef poisson_distribution distribution_type; | 
 | 4382 |  | 
 | 4383 |         explicit param_type(double __mean = 1.0); | 
 | 4384 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4385 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4386 |         double mean() const {return __mean_;} | 
 | 4387 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4388 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4389 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4390 |             {return __x.__mean_ == __y.__mean_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4391 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4392 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4393 |             {return !(__x == __y);} | 
 | 4394 |  | 
 | 4395 |         friend class poisson_distribution; | 
 | 4396 |     }; | 
 | 4397 |  | 
 | 4398 | private: | 
 | 4399 |     param_type __p_; | 
 | 4400 |  | 
 | 4401 | public: | 
 | 4402 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4403 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4404 |     explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4405 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4406 |     explicit poisson_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4407 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4408 |     void reset() {} | 
 | 4409 |  | 
 | 4410 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4411 |     template<class _URNG> | 
 | 4412 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4413 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4414 |         {return (*this)(__g, __p_);} | 
 | 4415 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 4416 |  | 
 | 4417 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4418 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4419 |     double mean() const {return __p_.mean();} | 
 | 4420 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4421 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4422 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4423 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4424 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4425 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4426 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4427 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4428 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4429 |     result_type max() const {return numeric_limits<result_type>::max();} | 
 | 4430 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4431 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4432 |         bool operator==(const poisson_distribution& __x, | 
 | 4433 |                         const poisson_distribution& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4434 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4435 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4436 |         bool operator!=(const poisson_distribution& __x, | 
 | 4437 |                         const poisson_distribution& __y) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4438 |         {return !(__x == __y);} | 
 | 4439 | }; | 
 | 4440 |  | 
 | 4441 | template<class _IntType> | 
 | 4442 | poisson_distribution<_IntType>::param_type::param_type(double __mean) | 
 | 4443 |     : __mean_(__mean) | 
 | 4444 | { | 
 | 4445 |     if (__mean_ < 10) | 
 | 4446 |     { | 
 | 4447 |         __s_ = 0; | 
 | 4448 |         __d_ = 0; | 
 | 4449 |         __l_ = _STD::exp(-__mean_); | 
 | 4450 |         __omega_ = 0; | 
 | 4451 |         __c3_ = 0; | 
 | 4452 |         __c2_ = 0; | 
 | 4453 |         __c1_ = 0; | 
 | 4454 |         __c0_ = 0; | 
 | 4455 |         __c_ = 0; | 
 | 4456 |     } | 
 | 4457 |     else | 
 | 4458 |     { | 
 | 4459 |         __s_ = _STD::sqrt(__mean_); | 
 | 4460 |         __d_ = 6 * __mean_ * __mean_; | 
 | 4461 |         __l_ = static_cast<result_type>(__mean_ - 1.1484); | 
 | 4462 |         __omega_ = .3989423 / __s_; | 
 | 4463 |         double __b1_ = .4166667E-1 / __mean_; | 
 | 4464 |         double __b2_ = .3 * __b1_ * __b1_; | 
 | 4465 |         __c3_ = .1428571 * __b1_ * __b2_; | 
 | 4466 |         __c2_ = __b2_ - 15. * __c3_; | 
 | 4467 |         __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; | 
 | 4468 |         __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; | 
 | 4469 |         __c_ = .1069 / __mean_; | 
 | 4470 |     } | 
 | 4471 | } | 
 | 4472 |  | 
 | 4473 | template <class _IntType> | 
 | 4474 | template<class _URNG> | 
 | 4475 | _IntType | 
 | 4476 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) | 
 | 4477 | { | 
 | 4478 |     result_type __x; | 
 | 4479 |     uniform_real_distribution<double> __urd; | 
| Howard Hinnant | 75f7695 | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4480 |     if (__pr.__mean_ < 10) | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4481 |     { | 
 | 4482 |          __x = 0; | 
 | 4483 |         for (double __p = __urd(__urng); __p > __pr.__l_; ++__x) | 
 | 4484 |             __p *= __urd(__urng); | 
 | 4485 |     } | 
 | 4486 |     else | 
 | 4487 |     { | 
 | 4488 |         double __difmuk; | 
 | 4489 |         double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); | 
 | 4490 |         double __u; | 
 | 4491 |         if (__g > 0) | 
 | 4492 |         { | 
 | 4493 |             __x = static_cast<result_type>(__g); | 
 | 4494 |             if (__x >= __pr.__l_) | 
 | 4495 |                 return __x; | 
 | 4496 |             __difmuk = __pr.__mean_ - __x; | 
 | 4497 |             __u = __urd(__urng); | 
 | 4498 |             if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) | 
 | 4499 |                 return __x; | 
 | 4500 |         } | 
 | 4501 |         exponential_distribution<double> __edist; | 
 | 4502 |         for (bool __using_exp_dist = false; true; __using_exp_dist = true) | 
 | 4503 |         { | 
 | 4504 |             double __e; | 
 | 4505 |             if (__using_exp_dist || __g < 0) | 
 | 4506 |             { | 
 | 4507 |                 double __t; | 
 | 4508 |                 do | 
 | 4509 |                 { | 
 | 4510 |                     __e = __edist(__urng); | 
 | 4511 |                     __u = __urd(__urng); | 
 | 4512 |                     __u += __u - 1; | 
 | 4513 |                     __t = 1.8 + (__u < 0 ? -__e : __e); | 
 | 4514 |                 } while (__t <= -.6744); | 
 | 4515 |                 __x = __pr.__mean_ + __pr.__s_ * __t; | 
 | 4516 |                 __difmuk = __pr.__mean_ - __x; | 
 | 4517 |                 __using_exp_dist = true; | 
 | 4518 |             } | 
 | 4519 |             double __px; | 
 | 4520 |             double __py; | 
 | 4521 |             if (__x < 10) | 
 | 4522 |             { | 
 | 4523 |                 const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, | 
 | 4524 |                                              40320, 362880}; | 
 | 4525 |                 __px = -__pr.__mean_; | 
 | 4526 |                 __py = _STD::pow(__pr.__mean_, (double)__x) / __fac[__x]; | 
 | 4527 |             } | 
 | 4528 |             else | 
 | 4529 |             { | 
 | 4530 |                 double __del = .8333333E-1 / __x; | 
 | 4531 |                 __del -= 4.8 * __del * __del * __del; | 
 | 4532 |                 double __v = __difmuk / __x; | 
 | 4533 |                 if (_STD::abs(__v) > 0.25) | 
 | 4534 |                     __px = __x * _STD::log(1 + __v) - __difmuk - __del; | 
 | 4535 |                 else | 
 | 4536 |                     __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) * | 
 | 4537 |                            __v + .1421878) * __v + -.1661269) * __v + .2000118) * | 
 | 4538 |                            __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; | 
 | 4539 |                 __py = .3989423 / _STD::sqrt(__x); | 
 | 4540 |             } | 
 | 4541 |             double __r = (0.5 - __difmuk) / __pr.__s_; | 
 | 4542 |             double __r2 = __r * __r; | 
 | 4543 |             double __fx = -0.5 * __r2; | 
 | 4544 |             double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * | 
 | 4545 |                                         __r2 + __pr.__c1_) * __r2 + __pr.__c0_); | 
 | 4546 |             if (__using_exp_dist) | 
 | 4547 |             { | 
 | 4548 |                 if (__pr.__c_ * _STD::abs(__u) <= __py * _STD::exp(__px + __e) - | 
 | 4549 |                                                    __fy * _STD::exp(__fx + __e)) | 
 | 4550 |                     break; | 
 | 4551 |             } | 
 | 4552 |             else | 
 | 4553 |             { | 
 | 4554 |                 if (__fy - __u * __fy <= __py * _STD::exp(__px - __fx)) | 
 | 4555 |                     break; | 
 | 4556 |             } | 
 | 4557 |         } | 
 | 4558 |     } | 
 | 4559 |     return __x; | 
 | 4560 | } | 
 | 4561 |  | 
 | 4562 | template <class _CharT, class _Traits, class _IntType> | 
 | 4563 | basic_ostream<_CharT, _Traits>& | 
 | 4564 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4565 |            const poisson_distribution<_IntType>& __x) | 
 | 4566 | { | 
 | 4567 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4568 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4569 |                ios_base::scientific); | 
| Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4570 |     return __os << __x.mean(); | 
 | 4571 | } | 
 | 4572 |  | 
 | 4573 | template <class _CharT, class _Traits, class _IntType> | 
 | 4574 | basic_istream<_CharT, _Traits>& | 
 | 4575 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4576 |            poisson_distribution<_IntType>& __x) | 
 | 4577 | { | 
 | 4578 |     typedef poisson_distribution<_IntType> _Eng; | 
 | 4579 |     typedef typename _Eng::param_type param_type; | 
 | 4580 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4581 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4582 |     double __mean; | 
 | 4583 |     __is >> __mean; | 
 | 4584 |     if (!__is.fail()) | 
 | 4585 |         __x.param(param_type(__mean)); | 
 | 4586 |     return __is; | 
 | 4587 | } | 
 | 4588 |  | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4589 | // weibull_distribution | 
 | 4590 |  | 
 | 4591 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4592 | class _LIBCPP_VISIBLE weibull_distribution | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4593 | { | 
 | 4594 | public: | 
 | 4595 |     // types | 
 | 4596 |     typedef _RealType result_type; | 
 | 4597 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4598 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4599 |     { | 
 | 4600 |         result_type __a_; | 
 | 4601 |         result_type __b_; | 
 | 4602 |     public: | 
 | 4603 |         typedef weibull_distribution distribution_type; | 
 | 4604 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4605 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4606 |         explicit param_type(result_type __a = 1, result_type __b = 1) | 
 | 4607 |             : __a_(__a), __b_(__b) {} | 
 | 4608 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4609 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4610 |         result_type a() const {return __a_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4611 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4612 |         result_type b() const {return __b_;} | 
 | 4613 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4614 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4615 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4616 |             {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4617 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4618 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4619 |             {return !(__x == __y);} | 
 | 4620 |     }; | 
 | 4621 |  | 
 | 4622 | private: | 
 | 4623 |     param_type __p_; | 
 | 4624 |  | 
 | 4625 | public: | 
 | 4626 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4627 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4628 |     explicit weibull_distribution(result_type __a = 1, result_type __b = 1) | 
 | 4629 |         : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4630 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4631 |     explicit weibull_distribution(const param_type& __p) | 
 | 4632 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4633 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4634 |     void reset() {} | 
 | 4635 |  | 
 | 4636 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4637 |     template<class _URNG> | 
 | 4638 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4639 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4640 |         {return (*this)(__g, __p_);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4641 |     template<class _URNG> | 
 | 4642 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4643 |         result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4644 |         {return __p.b() * | 
 | 4645 |             _STD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} | 
 | 4646 |  | 
 | 4647 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4648 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4649 |     result_type a() const {return __p_.a();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4650 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4651 |     result_type b() const {return __p_.b();} | 
 | 4652 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4653 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4654 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4655 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4656 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4657 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4658 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4659 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4660 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4661 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
 | 4662 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4663 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4664 |         bool operator==(const weibull_distribution& __x, | 
 | 4665 |                         const weibull_distribution& __y) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4666 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4667 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4668 |         bool operator!=(const weibull_distribution& __x, | 
 | 4669 |                         const weibull_distribution& __y) | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4670 |         {return !(__x == __y);} | 
 | 4671 | }; | 
 | 4672 |  | 
 | 4673 | template <class _CharT, class _Traits, class _RT> | 
 | 4674 | basic_ostream<_CharT, _Traits>& | 
 | 4675 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4676 |            const weibull_distribution<_RT>& __x) | 
 | 4677 | { | 
 | 4678 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4679 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4680 |                ios_base::scientific); | 
| Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4681 |     _CharT __sp = __os.widen(' '); | 
 | 4682 |     __os.fill(__sp); | 
 | 4683 |     __os << __x.a() << __sp << __x.b(); | 
 | 4684 |     return __os; | 
 | 4685 | } | 
 | 4686 |  | 
 | 4687 | template <class _CharT, class _Traits, class _RT> | 
 | 4688 | basic_istream<_CharT, _Traits>& | 
 | 4689 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4690 |            weibull_distribution<_RT>& __x) | 
 | 4691 | { | 
 | 4692 |     typedef weibull_distribution<_RT> _Eng; | 
 | 4693 |     typedef typename _Eng::result_type result_type; | 
 | 4694 |     typedef typename _Eng::param_type param_type; | 
 | 4695 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4696 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4697 |     result_type __a; | 
 | 4698 |     result_type __b; | 
 | 4699 |     __is >> __a >> __b; | 
 | 4700 |     if (!__is.fail()) | 
 | 4701 |         __x.param(param_type(__a, __b)); | 
 | 4702 |     return __is; | 
 | 4703 | } | 
 | 4704 |  | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4705 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4706 | class _LIBCPP_VISIBLE extreme_value_distribution | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4707 | { | 
 | 4708 | public: | 
 | 4709 |     // types | 
 | 4710 |     typedef _RealType result_type; | 
 | 4711 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4712 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4713 |     { | 
 | 4714 |         result_type __a_; | 
 | 4715 |         result_type __b_; | 
 | 4716 |     public: | 
 | 4717 |         typedef extreme_value_distribution distribution_type; | 
 | 4718 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4719 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4720 |         explicit param_type(result_type __a = 0, result_type __b = 1) | 
 | 4721 |             : __a_(__a), __b_(__b) {} | 
 | 4722 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4723 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4724 |         result_type a() const {return __a_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4725 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4726 |         result_type b() const {return __b_;} | 
 | 4727 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4728 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4729 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4730 |             {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4731 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4732 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4733 |             {return !(__x == __y);} | 
 | 4734 |     }; | 
 | 4735 |  | 
 | 4736 | private: | 
 | 4737 |     param_type __p_; | 
 | 4738 |  | 
 | 4739 | public: | 
 | 4740 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4741 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4742 |     explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) | 
 | 4743 |         : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4744 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4745 |     explicit extreme_value_distribution(const param_type& __p) | 
 | 4746 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4747 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4748 |     void reset() {} | 
 | 4749 |  | 
 | 4750 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4751 |     template<class _URNG> | 
 | 4752 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4753 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4754 |         {return (*this)(__g, __p_);} | 
 | 4755 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 4756 |  | 
 | 4757 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4758 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4759 |     result_type a() const {return __p_.a();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4760 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4761 |     result_type b() const {return __p_.b();} | 
 | 4762 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4763 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4764 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4765 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4766 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4767 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4768 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4769 |     result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4770 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4771 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
 | 4772 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4773 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4774 |         bool operator==(const extreme_value_distribution& __x, | 
 | 4775 |                         const extreme_value_distribution& __y) | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4776 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4777 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4778 |         bool operator!=(const extreme_value_distribution& __x, | 
 | 4779 |                         const extreme_value_distribution& __y) | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4780 |         {return !(__x == __y);} | 
 | 4781 | }; | 
 | 4782 |  | 
 | 4783 | template<class _RealType> | 
 | 4784 | template<class _URNG> | 
 | 4785 | _RealType | 
 | 4786 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 4787 | { | 
 | 4788 |     return __p.a() - __p.b() * | 
 | 4789 |          _STD::log(-_STD::log(1-uniform_real_distribution<result_type>()(__g))); | 
 | 4790 | } | 
 | 4791 |  | 
 | 4792 | template <class _CharT, class _Traits, class _RT> | 
 | 4793 | basic_ostream<_CharT, _Traits>& | 
 | 4794 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4795 |            const extreme_value_distribution<_RT>& __x) | 
 | 4796 | { | 
 | 4797 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4798 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4799 |                ios_base::scientific); | 
| Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4800 |     _CharT __sp = __os.widen(' '); | 
 | 4801 |     __os.fill(__sp); | 
 | 4802 |     __os << __x.a() << __sp << __x.b(); | 
 | 4803 |     return __os; | 
 | 4804 | } | 
 | 4805 |  | 
 | 4806 | template <class _CharT, class _Traits, class _RT> | 
 | 4807 | basic_istream<_CharT, _Traits>& | 
 | 4808 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4809 |            extreme_value_distribution<_RT>& __x) | 
 | 4810 | { | 
 | 4811 |     typedef extreme_value_distribution<_RT> _Eng; | 
 | 4812 |     typedef typename _Eng::result_type result_type; | 
 | 4813 |     typedef typename _Eng::param_type param_type; | 
 | 4814 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4815 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4816 |     result_type __a; | 
 | 4817 |     result_type __b; | 
 | 4818 |     __is >> __a >> __b; | 
 | 4819 |     if (!__is.fail()) | 
 | 4820 |         __x.param(param_type(__a, __b)); | 
 | 4821 |     return __is; | 
 | 4822 | } | 
 | 4823 |  | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4824 | // gamma_distribution | 
 | 4825 |  | 
 | 4826 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4827 | class _LIBCPP_VISIBLE gamma_distribution | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4828 | { | 
 | 4829 | public: | 
 | 4830 |     // types | 
 | 4831 |     typedef _RealType result_type; | 
 | 4832 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4833 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4834 |     { | 
 | 4835 |         result_type __alpha_; | 
 | 4836 |         result_type __beta_; | 
 | 4837 |     public: | 
 | 4838 |         typedef gamma_distribution distribution_type; | 
 | 4839 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4840 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4841 |         explicit param_type(result_type __alpha = 1, result_type __beta = 1) | 
 | 4842 |             : __alpha_(__alpha), __beta_(__beta) {} | 
 | 4843 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4844 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4845 |         result_type alpha() const {return __alpha_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4846 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4847 |         result_type beta() const {return __beta_;} | 
 | 4848 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4849 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4850 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4851 |             {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4852 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 4853 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4854 |             {return !(__x == __y);} | 
 | 4855 |     }; | 
 | 4856 |  | 
 | 4857 | private: | 
 | 4858 |     param_type __p_; | 
 | 4859 |  | 
 | 4860 | public: | 
 | 4861 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4862 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4863 |     explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) | 
 | 4864 |         : __p_(param_type(__alpha, __beta)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4865 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4866 |     explicit gamma_distribution(const param_type& __p) | 
 | 4867 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4868 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4869 |     void reset() {} | 
 | 4870 |  | 
 | 4871 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4872 |     template<class _URNG> | 
 | 4873 |         _LIBCPP_INLINE_VISIBILITY | 
 | 4874 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4875 |         {return (*this)(__g, __p_);} | 
 | 4876 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 4877 |  | 
 | 4878 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4879 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4880 |     result_type alpha() const {return __p_.alpha();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4881 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4882 |     result_type beta() const {return __p_.beta();} | 
 | 4883 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4884 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4885 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4886 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4887 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 4888 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4889 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4890 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4891 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4892 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4893 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4894 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4895 |         bool operator==(const gamma_distribution& __x, | 
 | 4896 |                         const gamma_distribution& __y) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4897 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4898 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 4899 |         bool operator!=(const gamma_distribution& __x, | 
 | 4900 |                         const gamma_distribution& __y) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4901 |         {return !(__x == __y);} | 
 | 4902 | }; | 
 | 4903 |  | 
 | 4904 | template <class _RealType> | 
 | 4905 | template<class _URNG> | 
 | 4906 | _RealType | 
 | 4907 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 4908 | { | 
| Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4909 |     result_type __a = __p.alpha(); | 
 | 4910 |     uniform_real_distribution<result_type> __gen(0, 1); | 
 | 4911 |     exponential_distribution<result_type> __egen; | 
 | 4912 |     result_type __x; | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4913 |     if (__a == 1) | 
| Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4914 |         __x = __egen(__g); | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4915 |     else if (__a > 1) | 
 | 4916 |     { | 
 | 4917 |         const result_type __b = __a - 1; | 
 | 4918 |         const result_type __c = 3 * __a - result_type(0.75); | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4919 |         while (true) | 
 | 4920 |         { | 
 | 4921 |             const result_type __u = __gen(__g); | 
 | 4922 |             const result_type __v = __gen(__g); | 
 | 4923 |             const result_type __w = __u * (1 - __u); | 
| Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4924 |             if (__w != 0) | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4925 |             { | 
 | 4926 |                 const result_type __y = _STD::sqrt(__c / __w) * | 
 | 4927 |                                         (__u - result_type(0.5)); | 
 | 4928 |                 __x = __b + __y; | 
 | 4929 |                 if (__x >= 0) | 
 | 4930 |                 { | 
 | 4931 |                     const result_type __z = 64 * __w * __w * __w * __v * __v; | 
 | 4932 |                     if (__z <= 1 - 2 * __y * __y / __x) | 
 | 4933 |                         break; | 
 | 4934 |                     if (_STD::log(__z) <= 2 * (__b * _STD::log(__x / __b) - __y)) | 
 | 4935 |                         break; | 
 | 4936 |                 } | 
 | 4937 |             } | 
 | 4938 |         } | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4939 |     } | 
| Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4940 |     else  // __a < 1 | 
 | 4941 |     { | 
 | 4942 |         while (true) | 
 | 4943 |         { | 
 | 4944 |             const result_type __u = __gen(__g); | 
 | 4945 |             const result_type __es = __egen(__g); | 
 | 4946 |             if (__u <= 1 - __a) | 
 | 4947 |             { | 
 | 4948 |                 __x = _STD::pow(__u, 1 / __a); | 
 | 4949 |                 if (__x <= __es) | 
 | 4950 |                     break; | 
 | 4951 |             } | 
 | 4952 |             else | 
 | 4953 |             { | 
 | 4954 |                 const result_type __e = -_STD::log((1-__u)/__a); | 
 | 4955 |                 __x = _STD::pow(1 - __a + __a * __e, 1 / __a); | 
 | 4956 |                 if (__x <= __e + __es) | 
 | 4957 |                     break; | 
 | 4958 |             } | 
 | 4959 |         } | 
 | 4960 |     } | 
 | 4961 |     return __x * __p.beta(); | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4962 | } | 
 | 4963 |  | 
 | 4964 | template <class _CharT, class _Traits, class _RT> | 
 | 4965 | basic_ostream<_CharT, _Traits>& | 
 | 4966 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 4967 |            const gamma_distribution<_RT>& __x) | 
 | 4968 | { | 
 | 4969 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4970 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 4971 |                ios_base::scientific); | 
| Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4972 |     _CharT __sp = __os.widen(' '); | 
 | 4973 |     __os.fill(__sp); | 
 | 4974 |     __os << __x.alpha() << __sp << __x.beta(); | 
 | 4975 |     return __os; | 
 | 4976 | } | 
 | 4977 |  | 
 | 4978 | template <class _CharT, class _Traits, class _RT> | 
 | 4979 | basic_istream<_CharT, _Traits>& | 
 | 4980 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 4981 |            gamma_distribution<_RT>& __x) | 
 | 4982 | { | 
 | 4983 |     typedef gamma_distribution<_RT> _Eng; | 
 | 4984 |     typedef typename _Eng::result_type result_type; | 
 | 4985 |     typedef typename _Eng::param_type param_type; | 
 | 4986 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 4987 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 4988 |     result_type __alpha; | 
 | 4989 |     result_type __beta; | 
 | 4990 |     __is >> __alpha >> __beta; | 
 | 4991 |     if (!__is.fail()) | 
 | 4992 |         __x.param(param_type(__alpha, __beta)); | 
 | 4993 |     return __is; | 
 | 4994 | } | 
| Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 4995 |  | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 4996 | // negative_binomial_distribution | 
 | 4997 |  | 
 | 4998 | template<class _IntType = int> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4999 | class _LIBCPP_VISIBLE negative_binomial_distribution | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5000 | { | 
 | 5001 | public: | 
 | 5002 |     // types | 
 | 5003 |     typedef _IntType result_type; | 
 | 5004 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5005 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5006 |     { | 
 | 5007 |         result_type __k_; | 
 | 5008 |         double __p_; | 
 | 5009 |     public: | 
 | 5010 |         typedef negative_binomial_distribution distribution_type; | 
 | 5011 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5012 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5013 |         explicit param_type(result_type __k = 1, double __p = 0.5) | 
 | 5014 |             : __k_(__k), __p_(__p) {} | 
 | 5015 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5016 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5017 |         result_type k() const {return __k_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5018 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5019 |         double p() const {return __p_;} | 
 | 5020 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5021 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5022 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5023 |             {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5024 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5025 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5026 |             {return !(__x == __y);} | 
 | 5027 |     }; | 
 | 5028 |  | 
 | 5029 | private: | 
 | 5030 |     param_type __p_; | 
 | 5031 |  | 
 | 5032 | public: | 
 | 5033 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5034 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5035 |     explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) | 
 | 5036 |         : __p_(__k, __p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5037 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5038 |     explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5039 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5040 |     void reset() {} | 
 | 5041 |  | 
 | 5042 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5043 |     template<class _URNG> | 
 | 5044 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5045 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5046 |         {return (*this)(__g, __p_);} | 
 | 5047 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 5048 |  | 
 | 5049 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5050 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5051 |     result_type k() const {return __p_.k();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5052 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5053 |     double p() const {return __p_.p();} | 
 | 5054 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5055 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5056 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5057 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5058 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5059 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5060 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5061 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5062 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5063 |     result_type max() const {return numeric_limits<result_type>::max();} | 
 | 5064 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5065 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5066 |         bool operator==(const negative_binomial_distribution& __x, | 
 | 5067 |                         const negative_binomial_distribution& __y) | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5068 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5069 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5070 |         bool operator!=(const negative_binomial_distribution& __x, | 
 | 5071 |                         const negative_binomial_distribution& __y) | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5072 |         {return !(__x == __y);} | 
 | 5073 | }; | 
 | 5074 |  | 
 | 5075 | template <class _IntType> | 
 | 5076 | template<class _URNG> | 
 | 5077 | _IntType | 
 | 5078 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) | 
 | 5079 | { | 
 | 5080 |     result_type __k = __pr.k(); | 
 | 5081 |     double __p = __pr.p(); | 
 | 5082 |     if (__k <= 21 * __p) | 
 | 5083 |     { | 
 | 5084 |         bernoulli_distribution __gen(__p); | 
 | 5085 |         result_type __f = 0; | 
 | 5086 |         result_type __s = 0; | 
 | 5087 |         while (__s < __k) | 
 | 5088 |         { | 
 | 5089 |             if (__gen(__urng)) | 
 | 5090 |                 ++__s; | 
 | 5091 |             else | 
 | 5092 |                 ++__f; | 
 | 5093 |         } | 
 | 5094 |         return __f; | 
 | 5095 |     } | 
 | 5096 |     return poisson_distribution<result_type>(gamma_distribution<double> | 
 | 5097 |                                             (__k, (1-__p)/__p)(__urng))(__urng); | 
 | 5098 | } | 
 | 5099 |  | 
 | 5100 | template <class _CharT, class _Traits, class _IntType> | 
 | 5101 | basic_ostream<_CharT, _Traits>& | 
 | 5102 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5103 |            const negative_binomial_distribution<_IntType>& __x) | 
 | 5104 | { | 
 | 5105 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5106 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5107 |                ios_base::scientific); | 
| Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5108 |     _CharT __sp = __os.widen(' '); | 
 | 5109 |     __os.fill(__sp); | 
 | 5110 |     return __os << __x.k() << __sp << __x.p(); | 
 | 5111 | } | 
 | 5112 |  | 
 | 5113 | template <class _CharT, class _Traits, class _IntType> | 
 | 5114 | basic_istream<_CharT, _Traits>& | 
 | 5115 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5116 |            negative_binomial_distribution<_IntType>& __x) | 
 | 5117 | { | 
 | 5118 |     typedef negative_binomial_distribution<_IntType> _Eng; | 
 | 5119 |     typedef typename _Eng::result_type result_type; | 
 | 5120 |     typedef typename _Eng::param_type param_type; | 
 | 5121 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5122 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5123 |     result_type __k; | 
 | 5124 |     double __p; | 
 | 5125 |     __is >> __k >> __p; | 
 | 5126 |     if (!__is.fail()) | 
 | 5127 |         __x.param(param_type(__k, __p)); | 
 | 5128 |     return __is; | 
 | 5129 | } | 
 | 5130 |  | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5131 | // geometric_distribution | 
 | 5132 |  | 
 | 5133 | template<class _IntType = int> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5134 | class _LIBCPP_VISIBLE geometric_distribution | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5135 | { | 
 | 5136 | public: | 
 | 5137 |     // types | 
 | 5138 |     typedef _IntType result_type; | 
 | 5139 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5140 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5141 |     { | 
 | 5142 |         double __p_; | 
 | 5143 |     public: | 
 | 5144 |         typedef geometric_distribution distribution_type; | 
 | 5145 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5146 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5147 |         explicit param_type(double __p = 0.5) : __p_(__p) {} | 
 | 5148 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5149 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5150 |         double p() const {return __p_;} | 
 | 5151 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5152 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5153 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5154 |             {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5155 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5156 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5157 |             {return !(__x == __y);} | 
 | 5158 |     }; | 
 | 5159 |  | 
 | 5160 | private: | 
 | 5161 |     param_type __p_; | 
 | 5162 |  | 
 | 5163 | public: | 
 | 5164 |     // constructors and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5165 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5166 |     explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5167 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5168 |     explicit geometric_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5169 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5170 |     void reset() {} | 
 | 5171 |  | 
 | 5172 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5173 |     template<class _URNG> | 
 | 5174 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5175 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5176 |         {return (*this)(__g, __p_);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5177 |     template<class _URNG> | 
 | 5178 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5179 |         result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5180 |         {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} | 
 | 5181 |  | 
 | 5182 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5183 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5184 |     double p() const {return __p_.p();} | 
 | 5185 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5186 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5187 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5188 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5189 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5190 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5191 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5192 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5193 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5194 |     result_type max() const {return numeric_limits<result_type>::max();} | 
 | 5195 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5196 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5197 |         bool operator==(const geometric_distribution& __x, | 
 | 5198 |                         const geometric_distribution& __y) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5199 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5200 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5201 |         bool operator!=(const geometric_distribution& __x, | 
 | 5202 |                         const geometric_distribution& __y) | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5203 |         {return !(__x == __y);} | 
 | 5204 | }; | 
 | 5205 |  | 
 | 5206 | template <class _CharT, class _Traits, class _IntType> | 
 | 5207 | basic_ostream<_CharT, _Traits>& | 
 | 5208 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5209 |            const geometric_distribution<_IntType>& __x) | 
 | 5210 | { | 
 | 5211 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5212 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5213 |                ios_base::scientific); | 
| Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5214 |     return __os << __x.p(); | 
 | 5215 | } | 
 | 5216 |  | 
 | 5217 | template <class _CharT, class _Traits, class _IntType> | 
 | 5218 | basic_istream<_CharT, _Traits>& | 
 | 5219 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5220 |            geometric_distribution<_IntType>& __x) | 
 | 5221 | { | 
 | 5222 |     typedef geometric_distribution<_IntType> _Eng; | 
 | 5223 |     typedef typename _Eng::param_type param_type; | 
 | 5224 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5225 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5226 |     double __p; | 
 | 5227 |     __is >> __p; | 
 | 5228 |     if (!__is.fail()) | 
 | 5229 |         __x.param(param_type(__p)); | 
 | 5230 |     return __is; | 
 | 5231 | } | 
 | 5232 |  | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5233 | // chi_squared_distribution | 
 | 5234 |  | 
 | 5235 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5236 | class _LIBCPP_VISIBLE chi_squared_distribution | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5237 | { | 
 | 5238 | public: | 
 | 5239 |     // types | 
 | 5240 |     typedef _RealType result_type; | 
 | 5241 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5242 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5243 |     { | 
 | 5244 |         result_type __n_; | 
 | 5245 |     public: | 
 | 5246 |         typedef chi_squared_distribution distribution_type; | 
 | 5247 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5248 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5249 |         explicit param_type(result_type __n = 1) : __n_(__n) {} | 
 | 5250 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5251 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5252 |         result_type n() const {return __n_;} | 
 | 5253 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5254 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5255 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5256 |             {return __x.__n_ == __y.__n_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5257 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5258 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5259 |             {return !(__x == __y);} | 
 | 5260 |     }; | 
 | 5261 |  | 
 | 5262 | private: | 
 | 5263 |     param_type __p_; | 
 | 5264 |  | 
 | 5265 | public: | 
 | 5266 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5267 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5268 |     explicit chi_squared_distribution(result_type __n = 1) | 
 | 5269 |         : __p_(param_type(__n)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5270 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5271 |     explicit chi_squared_distribution(const param_type& __p) | 
 | 5272 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5273 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5274 |     void reset() {} | 
 | 5275 |  | 
 | 5276 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5277 |     template<class _URNG> | 
 | 5278 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5279 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5280 |         {return (*this)(__g, __p_);} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5281 |     template<class _URNG> | 
 | 5282 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5283 |         result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5284 |         {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} | 
 | 5285 |  | 
 | 5286 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5287 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5288 |     result_type n() const {return __p_.n();} | 
 | 5289 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5290 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5291 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5292 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5293 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5294 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5295 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5296 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5297 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5298 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5299 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5300 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5301 |         bool operator==(const chi_squared_distribution& __x, | 
 | 5302 |                         const chi_squared_distribution& __y) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5303 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5304 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5305 |         bool operator!=(const chi_squared_distribution& __x, | 
 | 5306 |                         const chi_squared_distribution& __y) | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5307 |         {return !(__x == __y);} | 
 | 5308 | }; | 
 | 5309 |  | 
 | 5310 | template <class _CharT, class _Traits, class _RT> | 
 | 5311 | basic_ostream<_CharT, _Traits>& | 
 | 5312 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5313 |            const chi_squared_distribution<_RT>& __x) | 
 | 5314 | { | 
 | 5315 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5316 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5317 |                ios_base::scientific); | 
| Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5318 |     __os << __x.n(); | 
 | 5319 |     return __os; | 
 | 5320 | } | 
 | 5321 |  | 
 | 5322 | template <class _CharT, class _Traits, class _RT> | 
 | 5323 | basic_istream<_CharT, _Traits>& | 
 | 5324 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5325 |            chi_squared_distribution<_RT>& __x) | 
 | 5326 | { | 
 | 5327 |     typedef chi_squared_distribution<_RT> _Eng; | 
 | 5328 |     typedef typename _Eng::result_type result_type; | 
 | 5329 |     typedef typename _Eng::param_type param_type; | 
 | 5330 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5331 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5332 |     result_type __n; | 
 | 5333 |     __is >> __n; | 
 | 5334 |     if (!__is.fail()) | 
 | 5335 |         __x.param(param_type(__n)); | 
 | 5336 |     return __is; | 
 | 5337 | } | 
 | 5338 |  | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5339 | // cauchy_distribution | 
 | 5340 |  | 
 | 5341 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5342 | class _LIBCPP_VISIBLE cauchy_distribution | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5343 | { | 
 | 5344 | public: | 
 | 5345 |     // types | 
 | 5346 |     typedef _RealType result_type; | 
 | 5347 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5348 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5349 |     { | 
 | 5350 |         result_type __a_; | 
 | 5351 |         result_type __b_; | 
 | 5352 |     public: | 
 | 5353 |         typedef cauchy_distribution distribution_type; | 
 | 5354 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5355 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5356 |         explicit param_type(result_type __a = 0, result_type __b = 1) | 
 | 5357 |             : __a_(__a), __b_(__b) {} | 
 | 5358 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5359 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5360 |         result_type a() const {return __a_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5361 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5362 |         result_type b() const {return __b_;} | 
 | 5363 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5364 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5365 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5366 |             {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5367 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5368 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5369 |             {return !(__x == __y);} | 
 | 5370 |     }; | 
 | 5371 |  | 
 | 5372 | private: | 
 | 5373 |     param_type __p_; | 
 | 5374 |  | 
 | 5375 | public: | 
 | 5376 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5377 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5378 |     explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) | 
 | 5379 |         : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5380 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5381 |     explicit cauchy_distribution(const param_type& __p) | 
 | 5382 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5383 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5384 |     void reset() {} | 
 | 5385 |  | 
 | 5386 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5387 |     template<class _URNG> | 
 | 5388 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5389 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5390 |         {return (*this)(__g, __p_);} | 
 | 5391 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 5392 |  | 
 | 5393 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5394 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5395 |     result_type a() const {return __p_.a();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5396 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5397 |     result_type b() const {return __p_.b();} | 
 | 5398 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5399 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5400 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5401 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5402 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5403 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5404 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5405 |     result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5406 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5407 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5408 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5409 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5410 |         bool operator==(const cauchy_distribution& __x, | 
 | 5411 |                         const cauchy_distribution& __y) | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5412 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5413 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5414 |         bool operator!=(const cauchy_distribution& __x, | 
 | 5415 |                         const cauchy_distribution& __y) | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5416 |         {return !(__x == __y);} | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5417 | }; | 
 | 5418 |  | 
 | 5419 | template <class _RealType> | 
 | 5420 | template<class _URNG> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5421 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5422 | _RealType | 
 | 5423 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 5424 | { | 
 | 5425 |     uniform_real_distribution<result_type> __gen; | 
 | 5426 |     // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite | 
 | 5427 |     return __p.a() + __p.b() * _STD::tan(3.1415926535897932384626433832795 * __gen(__g)); | 
 | 5428 | } | 
 | 5429 |  | 
 | 5430 | template <class _CharT, class _Traits, class _RT> | 
 | 5431 | basic_ostream<_CharT, _Traits>& | 
 | 5432 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5433 |            const cauchy_distribution<_RT>& __x) | 
 | 5434 | { | 
 | 5435 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5436 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5437 |                ios_base::scientific); | 
| Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5438 |     _CharT __sp = __os.widen(' '); | 
 | 5439 |     __os.fill(__sp); | 
 | 5440 |     __os << __x.a() << __sp << __x.b(); | 
 | 5441 |     return __os; | 
 | 5442 | } | 
 | 5443 |  | 
 | 5444 | template <class _CharT, class _Traits, class _RT> | 
 | 5445 | basic_istream<_CharT, _Traits>& | 
 | 5446 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5447 |            cauchy_distribution<_RT>& __x) | 
 | 5448 | { | 
 | 5449 |     typedef cauchy_distribution<_RT> _Eng; | 
 | 5450 |     typedef typename _Eng::result_type result_type; | 
 | 5451 |     typedef typename _Eng::param_type param_type; | 
 | 5452 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5453 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5454 |     result_type __a; | 
 | 5455 |     result_type __b; | 
 | 5456 |     __is >> __a >> __b; | 
 | 5457 |     if (!__is.fail()) | 
 | 5458 |         __x.param(param_type(__a, __b)); | 
 | 5459 |     return __is; | 
 | 5460 | } | 
 | 5461 |  | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5462 | // fisher_f_distribution | 
 | 5463 |  | 
 | 5464 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5465 | class _LIBCPP_VISIBLE fisher_f_distribution | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5466 | { | 
 | 5467 | public: | 
 | 5468 |     // types | 
 | 5469 |     typedef _RealType result_type; | 
 | 5470 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5471 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5472 |     { | 
 | 5473 |         result_type __m_; | 
 | 5474 |         result_type __n_; | 
 | 5475 |     public: | 
 | 5476 |         typedef fisher_f_distribution distribution_type; | 
 | 5477 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5478 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5479 |         explicit param_type(result_type __m = 1, result_type __n = 1) | 
 | 5480 |             : __m_(__m), __n_(__n) {} | 
 | 5481 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5482 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5483 |         result_type m() const {return __m_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5484 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5485 |         result_type n() const {return __n_;} | 
 | 5486 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5487 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5488 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5489 |             {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5490 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5491 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5492 |             {return !(__x == __y);} | 
 | 5493 |     }; | 
 | 5494 |  | 
 | 5495 | private: | 
 | 5496 |     param_type __p_; | 
 | 5497 |  | 
 | 5498 | public: | 
 | 5499 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5500 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5501 |     explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) | 
 | 5502 |         : __p_(param_type(__m, __n)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5503 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5504 |     explicit fisher_f_distribution(const param_type& __p) | 
 | 5505 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5506 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5507 |     void reset() {} | 
 | 5508 |  | 
 | 5509 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5510 |     template<class _URNG> | 
 | 5511 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5512 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5513 |         {return (*this)(__g, __p_);} | 
 | 5514 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 5515 |  | 
 | 5516 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5517 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5518 |     result_type m() const {return __p_.m();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5519 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5520 |     result_type n() const {return __p_.n();} | 
 | 5521 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5522 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5523 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5524 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5525 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5526 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5527 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5528 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5529 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5530 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5531 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5532 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5533 |         bool operator==(const fisher_f_distribution& __x, | 
 | 5534 |                         const fisher_f_distribution& __y) | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5535 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5536 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5537 |         bool operator!=(const fisher_f_distribution& __x, | 
 | 5538 |                         const fisher_f_distribution& __y) | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5539 |         {return !(__x == __y);} | 
 | 5540 | }; | 
 | 5541 |  | 
 | 5542 | template <class _RealType> | 
 | 5543 | template<class _URNG> | 
 | 5544 | _RealType | 
 | 5545 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 5546 | { | 
 | 5547 |     gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); | 
 | 5548 |     gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); | 
 | 5549 |     return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); | 
 | 5550 | } | 
 | 5551 |  | 
 | 5552 | template <class _CharT, class _Traits, class _RT> | 
 | 5553 | basic_ostream<_CharT, _Traits>& | 
 | 5554 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5555 |            const fisher_f_distribution<_RT>& __x) | 
 | 5556 | { | 
 | 5557 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5558 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5559 |                ios_base::scientific); | 
| Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5560 |     _CharT __sp = __os.widen(' '); | 
 | 5561 |     __os.fill(__sp); | 
 | 5562 |     __os << __x.m() << __sp << __x.n(); | 
 | 5563 |     return __os; | 
 | 5564 | } | 
 | 5565 |  | 
 | 5566 | template <class _CharT, class _Traits, class _RT> | 
 | 5567 | basic_istream<_CharT, _Traits>& | 
 | 5568 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5569 |            fisher_f_distribution<_RT>& __x) | 
 | 5570 | { | 
 | 5571 |     typedef fisher_f_distribution<_RT> _Eng; | 
 | 5572 |     typedef typename _Eng::result_type result_type; | 
 | 5573 |     typedef typename _Eng::param_type param_type; | 
 | 5574 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5575 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5576 |     result_type __m; | 
 | 5577 |     result_type __n; | 
 | 5578 |     __is >> __m >> __n; | 
 | 5579 |     if (!__is.fail()) | 
 | 5580 |         __x.param(param_type(__m, __n)); | 
 | 5581 |     return __is; | 
 | 5582 | } | 
 | 5583 |  | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5584 | // student_t_distribution | 
 | 5585 |  | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5586 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5587 | class _LIBCPP_VISIBLE student_t_distribution | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5588 | { | 
 | 5589 | public: | 
 | 5590 |     // types | 
 | 5591 |     typedef _RealType result_type; | 
 | 5592 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5593 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5594 |     { | 
 | 5595 |         result_type __n_; | 
 | 5596 |     public: | 
 | 5597 |         typedef student_t_distribution distribution_type; | 
 | 5598 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5599 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5600 |         explicit param_type(result_type __n = 1) : __n_(__n) {} | 
 | 5601 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5602 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5603 |         result_type n() const {return __n_;} | 
 | 5604 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5605 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5606 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5607 |             {return __x.__n_ == __y.__n_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5608 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5609 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5610 |             {return !(__x == __y);} | 
 | 5611 |     }; | 
 | 5612 |  | 
 | 5613 | private: | 
 | 5614 |     param_type __p_; | 
 | 5615 |     normal_distribution<result_type> __nd_; | 
 | 5616 |  | 
 | 5617 | public: | 
 | 5618 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5619 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5620 |     explicit student_t_distribution(result_type __n = 1) | 
 | 5621 |         : __p_(param_type(__n)) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5622 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5623 |     explicit student_t_distribution(const param_type& __p) | 
 | 5624 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5625 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5626 |     void reset() {__nd_.reset();} | 
 | 5627 |  | 
 | 5628 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5629 |     template<class _URNG> | 
 | 5630 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5631 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5632 |         {return (*this)(__g, __p_);} | 
 | 5633 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 5634 |  | 
 | 5635 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5636 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5637 |     result_type n() const {return __p_.n();} | 
 | 5638 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5639 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5640 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5641 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5642 |     void param(const param_type& __p) {__p_ = __p;} | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5643 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5644 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5645 |     result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5646 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5647 |     result_type max() const {return numeric_limits<result_type>::infinity();} | 
 | 5648 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5649 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5650 |         bool operator==(const student_t_distribution& __x, | 
 | 5651 |                         const student_t_distribution& __y) | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5652 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5653 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5654 |         bool operator!=(const student_t_distribution& __x, | 
 | 5655 |                         const student_t_distribution& __y) | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5656 |         {return !(__x == __y);} | 
 | 5657 | }; | 
 | 5658 |  | 
 | 5659 | template <class _RealType> | 
 | 5660 | template<class _URNG> | 
 | 5661 | _RealType | 
 | 5662 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 5663 | { | 
 | 5664 |     gamma_distribution<result_type> __gd(__p.n() * .5, 2); | 
 | 5665 |     return __nd_(__g) * _STD::sqrt(__p.n()/__gd(__g)); | 
 | 5666 | } | 
 | 5667 |  | 
 | 5668 | template <class _CharT, class _Traits, class _RT> | 
 | 5669 | basic_ostream<_CharT, _Traits>& | 
 | 5670 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5671 |            const student_t_distribution<_RT>& __x) | 
 | 5672 | { | 
 | 5673 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5674 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5675 |                ios_base::scientific); | 
| Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5676 |     __os << __x.n(); | 
 | 5677 |     return __os; | 
 | 5678 | } | 
 | 5679 |  | 
 | 5680 | template <class _CharT, class _Traits, class _RT> | 
 | 5681 | basic_istream<_CharT, _Traits>& | 
 | 5682 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5683 |            student_t_distribution<_RT>& __x) | 
 | 5684 | { | 
 | 5685 |     typedef student_t_distribution<_RT> _Eng; | 
 | 5686 |     typedef typename _Eng::result_type result_type; | 
 | 5687 |     typedef typename _Eng::param_type param_type; | 
 | 5688 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5689 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5690 |     result_type __n; | 
 | 5691 |     __is >> __n; | 
 | 5692 |     if (!__is.fail()) | 
 | 5693 |         __x.param(param_type(__n)); | 
 | 5694 |     return __is; | 
 | 5695 | } | 
 | 5696 |  | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5697 | // discrete_distribution | 
 | 5698 |  | 
 | 5699 | template<class _IntType = int> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5700 | class _LIBCPP_VISIBLE discrete_distribution | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5701 | { | 
 | 5702 | public: | 
 | 5703 |     // types | 
 | 5704 |     typedef _IntType result_type; | 
 | 5705 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5706 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5707 |     { | 
 | 5708 |         vector<double> __p_; | 
 | 5709 |     public: | 
 | 5710 |         typedef discrete_distribution distribution_type; | 
 | 5711 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5712 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5713 |         param_type() {} | 
 | 5714 |         template<class _InputIterator> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5715 |             _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5716 |             param_type(_InputIterator __f, _InputIterator __l) | 
 | 5717 |             : __p_(__f, __l) {__init();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5718 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5719 |         param_type(initializer_list<double> __wl) | 
 | 5720 |             : __p_(__wl.begin(), __wl.end()) {__init();} | 
 | 5721 |         template<class _UnaryOperation> | 
 | 5722 |             param_type(size_t __nw, double __xmin, double __xmax, | 
 | 5723 |                        _UnaryOperation __fw); | 
 | 5724 |  | 
 | 5725 |         vector<double> probabilities() const; | 
 | 5726 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5727 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5728 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5729 |             {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5730 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5731 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5732 |             {return !(__x == __y);} | 
 | 5733 |  | 
 | 5734 |     private: | 
 | 5735 |         void __init(); | 
 | 5736 |  | 
 | 5737 |         friend class discrete_distribution; | 
 | 5738 |  | 
 | 5739 |         template <class _CharT, class _Traits, class _IT> | 
 | 5740 |         friend | 
 | 5741 |         basic_ostream<_CharT, _Traits>& | 
 | 5742 |         operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5743 |                    const discrete_distribution<_IT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5744 |  | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5745 |         template <class _CharT, class _Traits, class _IT> | 
 | 5746 |         friend | 
 | 5747 |         basic_istream<_CharT, _Traits>& | 
 | 5748 |         operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5749 |                    discrete_distribution<_IT>& __x); | 
 | 5750 |     }; | 
 | 5751 |  | 
 | 5752 | private: | 
 | 5753 |     param_type __p_; | 
 | 5754 |  | 
 | 5755 | public: | 
 | 5756 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5757 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5758 |     discrete_distribution() {} | 
 | 5759 |     template<class _InputIterator> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5760 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5761 |         discrete_distribution(_InputIterator __f, _InputIterator __l) | 
 | 5762 |             : __p_(__f, __l) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5763 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5764 |     discrete_distribution(initializer_list<double> __wl) | 
 | 5765 |         : __p_(__wl) {} | 
 | 5766 |     template<class _UnaryOperation> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5767 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5768 |         discrete_distribution(size_t __nw, double __xmin, double __xmax, | 
 | 5769 |                               _UnaryOperation __fw) | 
 | 5770 |         : __p_(__nw, __xmin, __xmax, __fw) {} | 
 | 5771 |     explicit discrete_distribution(const param_type& __p) | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5772 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5773 |         : __p_(__p) {} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5774 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5775 |     void reset() {} | 
 | 5776 |  | 
 | 5777 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5778 |     template<class _URNG> | 
 | 5779 |         _LIBCPP_INLINE_VISIBILITY | 
 | 5780 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5781 |         {return (*this)(__g, __p_);} | 
 | 5782 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 5783 |  | 
 | 5784 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5785 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5786 |     vector<double> probabilities() const {return __p_.probabilities();} | 
 | 5787 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5788 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5789 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5790 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5791 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 5792 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5793 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5794 |     result_type min() const {return 0;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5795 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5796 |     result_type max() const {return __p_.__p_.size();} | 
 | 5797 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5798 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5799 |         bool operator==(const discrete_distribution& __x, | 
 | 5800 |                         const discrete_distribution& __y) | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5801 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5802 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 5803 |         bool operator!=(const discrete_distribution& __x, | 
 | 5804 |                         const discrete_distribution& __y) | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5805 |         {return !(__x == __y);} | 
 | 5806 |  | 
 | 5807 |     template <class _CharT, class _Traits, class _IT> | 
 | 5808 |     friend | 
 | 5809 |     basic_ostream<_CharT, _Traits>& | 
 | 5810 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5811 |                const discrete_distribution<_IT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5812 |  | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5813 |     template <class _CharT, class _Traits, class _IT> | 
 | 5814 |     friend | 
 | 5815 |     basic_istream<_CharT, _Traits>& | 
 | 5816 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5817 |                discrete_distribution<_IT>& __x); | 
 | 5818 | }; | 
 | 5819 |  | 
 | 5820 | template<class _IntType> | 
 | 5821 | template<class _UnaryOperation> | 
 | 5822 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, | 
 | 5823 |                                                         double __xmin, | 
 | 5824 |                                                         double __xmax, | 
 | 5825 |                                                         _UnaryOperation __fw) | 
 | 5826 | { | 
 | 5827 |     if (__nw > 1) | 
 | 5828 |     { | 
 | 5829 |         __p_.reserve(__nw - 1); | 
 | 5830 |         double __d = (__xmax - __xmin) / __nw; | 
 | 5831 |         double __d2 = __d / 2; | 
 | 5832 |         for (size_t __k = 0; __k < __nw; ++__k) | 
 | 5833 |             __p_.push_back(__fw(__xmin + __k * __d + __d2)); | 
 | 5834 |         __init(); | 
 | 5835 |     } | 
 | 5836 | } | 
 | 5837 |  | 
 | 5838 | template<class _IntType> | 
 | 5839 | void | 
 | 5840 | discrete_distribution<_IntType>::param_type::__init() | 
 | 5841 | { | 
 | 5842 |     if (!__p_.empty()) | 
 | 5843 |     { | 
 | 5844 |         if (__p_.size() > 1) | 
 | 5845 |         { | 
 | 5846 |             double __s = _STD::accumulate(__p_.begin(), __p_.end(), 0.0); | 
 | 5847 |             for (_STD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); | 
 | 5848 |                                                                        __i < __e; ++__i) | 
 | 5849 |                 *__i /= __s; | 
 | 5850 |             vector<double> __t(__p_.size() - 1); | 
 | 5851 |             _STD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); | 
 | 5852 |             swap(__p_, __t); | 
 | 5853 |         } | 
 | 5854 |         else | 
 | 5855 |         { | 
 | 5856 |             __p_.clear(); | 
 | 5857 |             __p_.shrink_to_fit(); | 
 | 5858 |         } | 
 | 5859 |     } | 
 | 5860 | } | 
 | 5861 |  | 
 | 5862 | template<class _IntType> | 
 | 5863 | vector<double> | 
 | 5864 | discrete_distribution<_IntType>::param_type::probabilities() const | 
 | 5865 | { | 
 | 5866 |     size_t __n = __p_.size(); | 
 | 5867 |     _STD::vector<double> __p(__n+1); | 
 | 5868 |     _STD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); | 
 | 5869 |     if (__n > 0) | 
 | 5870 |         __p[__n] = 1 - __p_[__n-1]; | 
 | 5871 |     else | 
 | 5872 |         __p[0] = 1; | 
 | 5873 |     return __p; | 
 | 5874 | } | 
 | 5875 |  | 
 | 5876 | template<class _IntType> | 
 | 5877 | template<class _URNG> | 
 | 5878 | _IntType | 
 | 5879 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) | 
 | 5880 | { | 
 | 5881 |     uniform_real_distribution<double> __gen; | 
 | 5882 |     return static_cast<_IntType>( | 
 | 5883 |            _STD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - | 
 | 5884 |                                                               __p.__p_.begin()); | 
 | 5885 | } | 
 | 5886 |  | 
 | 5887 | template <class _CharT, class _Traits, class _IT> | 
 | 5888 | basic_ostream<_CharT, _Traits>& | 
 | 5889 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5890 |            const discrete_distribution<_IT>& __x) | 
 | 5891 | { | 
 | 5892 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5893 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 5894 |                ios_base::scientific); | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5895 |     _CharT __sp = __os.widen(' '); | 
 | 5896 |     __os.fill(__sp); | 
 | 5897 |     size_t __n = __x.__p_.__p_.size(); | 
 | 5898 |     __os << __n; | 
 | 5899 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 5900 |         __os << __sp << __x.__p_.__p_[__i]; | 
 | 5901 |     return __os; | 
 | 5902 | } | 
 | 5903 |  | 
 | 5904 | template <class _CharT, class _Traits, class _IT> | 
 | 5905 | basic_istream<_CharT, _Traits>& | 
 | 5906 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5907 |            discrete_distribution<_IT>& __x) | 
 | 5908 | { | 
 | 5909 |     typedef discrete_distribution<_IT> _Eng; | 
 | 5910 |     typedef typename _Eng::result_type result_type; | 
 | 5911 |     typedef typename _Eng::param_type param_type; | 
 | 5912 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 5913 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 5914 |     size_t __n; | 
 | 5915 |     __is >> __n; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5916 |     vector<double> __p(__n); | 
| Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5917 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 5918 |         __is >> __p[__i]; | 
 | 5919 |     if (!__is.fail()) | 
 | 5920 |         swap(__x.__p_.__p_, __p); | 
 | 5921 |     return __is; | 
 | 5922 | } | 
 | 5923 |  | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5924 | // piecewise_constant_distribution | 
 | 5925 |  | 
 | 5926 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5927 | class _LIBCPP_VISIBLE piecewise_constant_distribution | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5928 | { | 
 | 5929 | public: | 
 | 5930 |     // types | 
 | 5931 |     typedef _RealType result_type; | 
 | 5932 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5933 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5934 |     { | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5935 |         vector<result_type> __b_; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 5936 |         vector<result_type> __densities_; | 
 | 5937 |         vector<result_type> __areas_; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5938 |     public: | 
 | 5939 |         typedef piecewise_constant_distribution distribution_type; | 
 | 5940 |  | 
 | 5941 |         param_type(); | 
 | 5942 |         template<class _InputIteratorB, class _InputIteratorW> | 
 | 5943 |             param_type(_InputIteratorB __fB, _InputIteratorB __lB, | 
 | 5944 |                        _InputIteratorW __fW); | 
 | 5945 |         template<class _UnaryOperation> | 
 | 5946 |             param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); | 
 | 5947 |         template<class _UnaryOperation> | 
 | 5948 |             param_type(size_t __nw, result_type __xmin, result_type __xmax, | 
 | 5949 |                        _UnaryOperation __fw); | 
| Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 5950 |         param_type & operator=(const param_type& __rhs); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5951 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5952 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5953 |         vector<result_type> intervals() const {return __b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5954 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 5955 |         vector<result_type> densities() const {return __densities_;} | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5956 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5957 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5958 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5959 |             {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5960 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 5961 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5962 |             {return !(__x == __y);} | 
 | 5963 |  | 
 | 5964 |     private: | 
 | 5965 |         void __init(); | 
 | 5966 |  | 
 | 5967 |         friend class piecewise_constant_distribution; | 
 | 5968 |  | 
 | 5969 |         template <class _CharT, class _Traits, class _RT> | 
 | 5970 |         friend | 
 | 5971 |         basic_ostream<_CharT, _Traits>& | 
 | 5972 |         operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 5973 |                    const piecewise_constant_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5974 |  | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5975 |         template <class _CharT, class _Traits, class _RT> | 
 | 5976 |         friend | 
 | 5977 |         basic_istream<_CharT, _Traits>& | 
 | 5978 |         operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 5979 |                    piecewise_constant_distribution<_RT>& __x); | 
 | 5980 |     }; | 
 | 5981 |  | 
 | 5982 | private: | 
 | 5983 |     param_type __p_; | 
 | 5984 |  | 
 | 5985 | public: | 
 | 5986 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5987 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5988 |     piecewise_constant_distribution() {} | 
 | 5989 |     template<class _InputIteratorB, class _InputIteratorW> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5990 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5991 |         piecewise_constant_distribution(_InputIteratorB __fB, | 
 | 5992 |                                         _InputIteratorB __lB, | 
 | 5993 |                                         _InputIteratorW __fW) | 
 | 5994 |         : __p_(__fB, __lB, __fW) {} | 
 | 5995 |  | 
 | 5996 |     template<class _UnaryOperation> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5997 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5998 |         piecewise_constant_distribution(initializer_list<result_type> __bl, | 
 | 5999 |                                         _UnaryOperation __fw) | 
 | 6000 |         : __p_(__bl, __fw) {} | 
 | 6001 |  | 
 | 6002 |     template<class _UnaryOperation> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6003 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6004 |         piecewise_constant_distribution(size_t __nw, result_type __xmin, | 
 | 6005 |                                         result_type __xmax, _UnaryOperation __fw) | 
 | 6006 |         : __p_(__nw, __xmin, __xmax, __fw) {} | 
 | 6007 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6008 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6009 |     explicit piecewise_constant_distribution(const param_type& __p) | 
 | 6010 |         : __p_(__p) {} | 
 | 6011 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6012 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6013 |     void reset() {} | 
 | 6014 |  | 
 | 6015 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6016 |     template<class _URNG> | 
 | 6017 |         _LIBCPP_INLINE_VISIBILITY | 
 | 6018 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6019 |         {return (*this)(__g, __p_);} | 
 | 6020 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 6021 |  | 
 | 6022 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6023 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6024 |     vector<result_type> intervals() const {return __p_.intervals();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6025 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6026 |     vector<result_type> densities() const {return __p_.densities();} | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6027 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6028 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6029 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6030 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6031 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 6032 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6033 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6034 |     result_type min() const {return __p_.__b_.front();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6035 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6036 |     result_type max() const {return __p_.__b_.back();} | 
 | 6037 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6038 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 6039 |         bool operator==(const piecewise_constant_distribution& __x, | 
 | 6040 |                         const piecewise_constant_distribution& __y) | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6041 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6042 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 6043 |         bool operator!=(const piecewise_constant_distribution& __x, | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6044 |                            const piecewise_constant_distribution& __y) | 
 | 6045 |         {return !(__x == __y);} | 
 | 6046 |  | 
 | 6047 |     template <class _CharT, class _Traits, class _RT> | 
 | 6048 |     friend | 
 | 6049 |     basic_ostream<_CharT, _Traits>& | 
 | 6050 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 6051 |                const piecewise_constant_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6052 |  | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6053 |     template <class _CharT, class _Traits, class _RT> | 
 | 6054 |     friend | 
 | 6055 |     basic_istream<_CharT, _Traits>& | 
 | 6056 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 6057 |                piecewise_constant_distribution<_RT>& __x); | 
 | 6058 | }; | 
 | 6059 |  | 
 | 6060 | template<class _RealType> | 
| Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6061 | typename piecewise_constant_distribution<_RealType>::param_type & | 
 | 6062 | piecewise_constant_distribution<_RealType>::param_type::operator= | 
 | 6063 |                                                        (const param_type& __rhs) | 
 | 6064 | { | 
 | 6065 | //  These can throw | 
 | 6066 |     __b_.reserve        (__rhs.__b_.size ()); | 
 | 6067 |     __densities_.reserve(__rhs.__densities_.size()); | 
 | 6068 |     __areas_.reserve    (__rhs.__areas_.size()); | 
 | 6069 |  | 
 | 6070 | //  These can not throw | 
 | 6071 |     __b_         = __rhs.__b_; | 
 | 6072 |     __densities_ = __rhs.__densities_; | 
 | 6073 |     __areas_     =  __rhs.__areas_; | 
 | 6074 |     return *this; | 
 | 6075 | } | 
 | 6076 |  | 
 | 6077 | template<class _RealType> | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6078 | void | 
 | 6079 | piecewise_constant_distribution<_RealType>::param_type::__init() | 
 | 6080 | { | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6081 |     // __densities_ contains non-normalized areas | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6082 |     result_type __total_area = _STD::accumulate(__densities_.begin(), | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6083 |                                                 __densities_.end(), | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6084 |                                                 result_type()); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6085 |     for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
 | 6086 |         __densities_[__i] /= __total_area; | 
 | 6087 |     // __densities_ contains normalized areas | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6088 |     __areas_.assign(__densities_.size(), result_type()); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6089 |     _STD::partial_sum(__densities_.begin(), __densities_.end() - 1, | 
 | 6090 |                                                           __areas_.begin() + 1); | 
 | 6091 |     // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] | 
 | 6092 |     __densities_.back() = 1 - __areas_.back();  // correct round off error | 
 | 6093 |     for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
 | 6094 |         __densities_[__i] /= (__b_[__i+1] - __b_[__i]); | 
 | 6095 |     // __densities_ now contains __densities_ | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6096 | } | 
 | 6097 |  | 
 | 6098 | template<class _RealType> | 
 | 6099 | piecewise_constant_distribution<_RealType>::param_type::param_type() | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6100 |     : __b_(2), | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6101 |       __densities_(1, 1.0), | 
 | 6102 |       __areas_(1, 0.0) | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6103 | { | 
 | 6104 |     __b_[1] = 1; | 
 | 6105 | } | 
 | 6106 |  | 
 | 6107 | template<class _RealType> | 
 | 6108 | template<class _InputIteratorB, class _InputIteratorW> | 
 | 6109 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
 | 6110 |         _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) | 
 | 6111 |     : __b_(__fB, __lB) | 
 | 6112 | { | 
 | 6113 |     if (__b_.size() < 2) | 
 | 6114 |     { | 
 | 6115 |         __b_.resize(2); | 
 | 6116 |         __b_[0] = 0; | 
 | 6117 |         __b_[1] = 1; | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6118 |         __densities_.assign(1, 1.0); | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6119 |         __areas_.assign(1, 0.0); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6120 |     } | 
 | 6121 |     else | 
 | 6122 |     { | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6123 |         __densities_.reserve(__b_.size() - 1); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6124 |         for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6125 |             __densities_.push_back(*__fW); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6126 |         __init(); | 
 | 6127 |     } | 
 | 6128 | } | 
 | 6129 |  | 
 | 6130 | template<class _RealType> | 
 | 6131 | template<class _UnaryOperation> | 
 | 6132 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
 | 6133 |         initializer_list<result_type> __bl, _UnaryOperation __fw) | 
 | 6134 |     : __b_(__bl.begin(), __bl.end()) | 
 | 6135 | { | 
 | 6136 |     if (__b_.size() < 2) | 
 | 6137 |     { | 
 | 6138 |         __b_.resize(2); | 
 | 6139 |         __b_[0] = 0; | 
 | 6140 |         __b_[1] = 1; | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6141 |         __densities_.assign(1, 1.0); | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6142 |         __areas_.assign(1, 0.0); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6143 |     } | 
 | 6144 |     else | 
 | 6145 |     { | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6146 |         __densities_.reserve(__b_.size() - 1); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6147 |         for (size_t __i = 0; __i < __b_.size() - 1; ++__i) | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6148 |             __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6149 |         __init(); | 
 | 6150 |     } | 
 | 6151 | } | 
 | 6152 |  | 
 | 6153 | template<class _RealType> | 
 | 6154 | template<class _UnaryOperation> | 
 | 6155 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
 | 6156 |         size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) | 
 | 6157 |     : __b_(__nw == 0 ? 2 : __nw + 1) | 
 | 6158 | { | 
 | 6159 |     size_t __n = __b_.size() - 1; | 
 | 6160 |     result_type __d = (__xmax - __xmin) / __n; | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6161 |     __densities_.reserve(__n); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6162 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6163 |     { | 
 | 6164 |         __b_[__i] = __xmin + __i * __d; | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6165 |         __densities_.push_back(__fw(__b_[__i] + __d*.5)); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6166 |     } | 
 | 6167 |     __b_[__n] = __xmax; | 
 | 6168 |     __init(); | 
 | 6169 | } | 
 | 6170 |  | 
 | 6171 | template<class _RealType> | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6172 | template<class _URNG> | 
 | 6173 | _RealType | 
 | 6174 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 6175 | { | 
 | 6176 |     typedef uniform_real_distribution<result_type> _Gen; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6177 |     result_type __u = _Gen()(__g); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6178 |     ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6179 |                                       __u) - __p.__areas_.begin() - 1; | 
 | 6180 |     return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6181 | } | 
 | 6182 |  | 
 | 6183 | template <class _CharT, class _Traits, class _RT> | 
 | 6184 | basic_ostream<_CharT, _Traits>& | 
 | 6185 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 6186 |            const piecewise_constant_distribution<_RT>& __x) | 
 | 6187 | { | 
 | 6188 |     __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6189 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 6190 |                ios_base::scientific); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6191 |     _CharT __sp = __os.widen(' '); | 
 | 6192 |     __os.fill(__sp); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6193 |     size_t __n = __x.__p_.__b_.size(); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6194 |     __os << __n; | 
 | 6195 |     for (size_t __i = 0; __i < __n; ++__i) | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6196 |         __os << __sp << __x.__p_.__b_[__i]; | 
 | 6197 |     __n = __x.__p_.__densities_.size(); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6198 |     __os << __sp << __n; | 
 | 6199 |     for (size_t __i = 0; __i < __n; ++__i) | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6200 |         __os << __sp << __x.__p_.__densities_[__i]; | 
 | 6201 |     __n = __x.__p_.__areas_.size(); | 
 | 6202 |     __os << __sp << __n; | 
 | 6203 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6204 |         __os << __sp << __x.__p_.__areas_[__i]; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6205 |     return __os; | 
 | 6206 | } | 
 | 6207 |  | 
 | 6208 | template <class _CharT, class _Traits, class _RT> | 
 | 6209 | basic_istream<_CharT, _Traits>& | 
 | 6210 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 6211 |            piecewise_constant_distribution<_RT>& __x) | 
 | 6212 | { | 
 | 6213 |     typedef piecewise_constant_distribution<_RT> _Eng; | 
 | 6214 |     typedef typename _Eng::result_type result_type; | 
 | 6215 |     typedef typename _Eng::param_type param_type; | 
 | 6216 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 6217 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 6218 |     size_t __n; | 
 | 6219 |     __is >> __n; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6220 |     vector<result_type> __b(__n); | 
 | 6221 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6222 |         __is >> __b[__i]; | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6223 |     __is >> __n; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6224 |     vector<result_type> __densities(__n); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6225 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6226 |         __is >> __densities[__i]; | 
 | 6227 |     __is >> __n; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6228 |     vector<result_type> __areas(__n); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6229 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6230 |         __is >> __areas[__i]; | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6231 |     if (!__is.fail()) | 
 | 6232 |     { | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6233 |         swap(__x.__p_.__b_, __b); | 
| Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6234 |         swap(__x.__p_.__densities_, __densities); | 
 | 6235 |         swap(__x.__p_.__areas_, __areas); | 
| Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6236 |     } | 
 | 6237 |     return __is; | 
 | 6238 | } | 
 | 6239 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6240 | // piecewise_linear_distribution | 
 | 6241 |  | 
 | 6242 | template<class _RealType = double> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6243 | class _LIBCPP_VISIBLE piecewise_linear_distribution | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6244 | { | 
 | 6245 | public: | 
 | 6246 |     // types | 
 | 6247 |     typedef _RealType result_type; | 
 | 6248 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6249 |     class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6250 |     { | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6251 |         vector<result_type> __b_; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6252 |         vector<result_type> __densities_; | 
 | 6253 |         vector<result_type> __areas_; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6254 |     public: | 
 | 6255 |         typedef piecewise_linear_distribution distribution_type; | 
 | 6256 |  | 
 | 6257 |         param_type(); | 
 | 6258 |         template<class _InputIteratorB, class _InputIteratorW> | 
 | 6259 |             param_type(_InputIteratorB __fB, _InputIteratorB __lB, | 
 | 6260 |                        _InputIteratorW __fW); | 
 | 6261 |         template<class _UnaryOperation> | 
 | 6262 |             param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); | 
 | 6263 |         template<class _UnaryOperation> | 
 | 6264 |             param_type(size_t __nw, result_type __xmin, result_type __xmax, | 
 | 6265 |                        _UnaryOperation __fw); | 
| Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6266 |         param_type & operator=(const param_type& __rhs); | 
 | 6267 |          | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6268 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6269 |         vector<result_type> intervals() const {return __b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6270 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6271 |         vector<result_type> densities() const {return __densities_;} | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6272 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6273 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 6274 |             bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6275 |             {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6276 |         friend _LIBCPP_INLINE_VISIBILITY | 
 | 6277 |             bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6278 |             {return !(__x == __y);} | 
 | 6279 |  | 
 | 6280 |     private: | 
 | 6281 |         void __init(); | 
 | 6282 |  | 
 | 6283 |         friend class piecewise_linear_distribution; | 
 | 6284 |  | 
 | 6285 |         template <class _CharT, class _Traits, class _RT> | 
 | 6286 |         friend | 
 | 6287 |         basic_ostream<_CharT, _Traits>& | 
 | 6288 |         operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 6289 |                    const piecewise_linear_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6290 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6291 |         template <class _CharT, class _Traits, class _RT> | 
 | 6292 |         friend | 
 | 6293 |         basic_istream<_CharT, _Traits>& | 
 | 6294 |         operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 6295 |                    piecewise_linear_distribution<_RT>& __x); | 
 | 6296 |     }; | 
 | 6297 |  | 
 | 6298 | private: | 
 | 6299 |     param_type __p_; | 
 | 6300 |  | 
 | 6301 | public: | 
 | 6302 |     // constructor and reset functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6303 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6304 |     piecewise_linear_distribution() {} | 
 | 6305 |     template<class _InputIteratorB, class _InputIteratorW> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6306 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6307 |         piecewise_linear_distribution(_InputIteratorB __fB, | 
 | 6308 |                                       _InputIteratorB __lB, | 
 | 6309 |                                       _InputIteratorW __fW) | 
 | 6310 |         : __p_(__fB, __lB, __fW) {} | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6311 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6312 |     template<class _UnaryOperation> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6313 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6314 |         piecewise_linear_distribution(initializer_list<result_type> __bl, | 
 | 6315 |                                       _UnaryOperation __fw) | 
 | 6316 |         : __p_(__bl, __fw) {} | 
 | 6317 |  | 
 | 6318 |     template<class _UnaryOperation> | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6319 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6320 |         piecewise_linear_distribution(size_t __nw, result_type __xmin, | 
 | 6321 |                                       result_type __xmax, _UnaryOperation __fw) | 
 | 6322 |         : __p_(__nw, __xmin, __xmax, __fw) {} | 
 | 6323 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6324 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6325 |     explicit piecewise_linear_distribution(const param_type& __p) | 
 | 6326 |         : __p_(__p) {} | 
 | 6327 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6328 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6329 |     void reset() {} | 
 | 6330 |  | 
 | 6331 |     // generating functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6332 |     template<class _URNG> | 
 | 6333 |         _LIBCPP_INLINE_VISIBILITY | 
 | 6334 |         result_type operator()(_URNG& __g) | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6335 |         {return (*this)(__g, __p_);} | 
 | 6336 |     template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
 | 6337 |  | 
 | 6338 |     // property functions | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6339 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6340 |     vector<result_type> intervals() const {return __p_.intervals();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6341 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6342 |     vector<result_type> densities() const {return __p_.densities();} | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6343 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6344 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6345 |     param_type param() const {return __p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6346 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6347 |     void param(const param_type& __p) {__p_ = __p;} | 
 | 6348 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6349 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6350 |     result_type min() const {return __p_.__b_.front();} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6351 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6352 |     result_type max() const {return __p_.__b_.back();} | 
 | 6353 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6354 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 6355 |         bool operator==(const piecewise_linear_distribution& __x, | 
 | 6356 |                         const piecewise_linear_distribution& __y) | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6357 |         {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6358 |     friend _LIBCPP_INLINE_VISIBILITY | 
 | 6359 |         bool operator!=(const piecewise_linear_distribution& __x, | 
 | 6360 |                         const piecewise_linear_distribution& __y) | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6361 |         {return !(__x == __y);} | 
 | 6362 |  | 
 | 6363 |     template <class _CharT, class _Traits, class _RT> | 
 | 6364 |     friend | 
 | 6365 |     basic_ostream<_CharT, _Traits>& | 
 | 6366 |     operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 6367 |                const piecewise_linear_distribution<_RT>& __x); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6368 |  | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6369 |     template <class _CharT, class _Traits, class _RT> | 
 | 6370 |     friend | 
 | 6371 |     basic_istream<_CharT, _Traits>& | 
 | 6372 |     operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 6373 |                piecewise_linear_distribution<_RT>& __x); | 
 | 6374 | }; | 
 | 6375 |  | 
 | 6376 | template<class _RealType> | 
| Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6377 | typename piecewise_linear_distribution<_RealType>::param_type & | 
 | 6378 | piecewise_linear_distribution<_RealType>::param_type::operator= | 
 | 6379 |                                                        (const param_type& __rhs) | 
 | 6380 | { | 
 | 6381 | //  These can throw | 
 | 6382 |     __b_.reserve        (__rhs.__b_.size ()); | 
 | 6383 |     __densities_.reserve(__rhs.__densities_.size()); | 
 | 6384 |     __areas_.reserve    (__rhs.__areas_.size()); | 
 | 6385 |  | 
 | 6386 | //  These can not throw | 
 | 6387 |     __b_         = __rhs.__b_; | 
 | 6388 |     __densities_ = __rhs.__densities_; | 
 | 6389 |     __areas_     =  __rhs.__areas_; | 
 | 6390 |     return *this; | 
 | 6391 | } | 
 | 6392 |  | 
 | 6393 |  | 
 | 6394 | template<class _RealType> | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6395 | void | 
 | 6396 | piecewise_linear_distribution<_RealType>::param_type::__init() | 
 | 6397 | { | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6398 |     __areas_.assign(__densities_.size() - 1, result_type()); | 
 | 6399 |     result_type _S = 0; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6400 |     for (size_t __i = 0; __i < __areas_.size(); ++__i) | 
 | 6401 |     { | 
 | 6402 |         __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * | 
 | 6403 |                         (__b_[__i+1] - __b_[__i]) * .5; | 
 | 6404 |         _S += __areas_[__i]; | 
 | 6405 |     } | 
 | 6406 |     for (size_t __i = __areas_.size(); __i > 1;) | 
 | 6407 |     { | 
 | 6408 |         --__i; | 
 | 6409 |         __areas_[__i] = __areas_[__i-1] / _S; | 
 | 6410 |     } | 
 | 6411 |     __areas_[0] = 0; | 
 | 6412 |     for (size_t __i = 1; __i < __areas_.size(); ++__i) | 
 | 6413 |         __areas_[__i] += __areas_[__i-1]; | 
 | 6414 |     for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
 | 6415 |         __densities_[__i] /= _S; | 
 | 6416 | } | 
 | 6417 |  | 
 | 6418 | template<class _RealType> | 
 | 6419 | piecewise_linear_distribution<_RealType>::param_type::param_type() | 
 | 6420 |     : __b_(2), | 
 | 6421 |       __densities_(2, 1.0), | 
 | 6422 |       __areas_(1, 0.0) | 
 | 6423 | { | 
 | 6424 |     __b_[1] = 1; | 
 | 6425 | } | 
 | 6426 |  | 
 | 6427 | template<class _RealType> | 
 | 6428 | template<class _InputIteratorB, class _InputIteratorW> | 
 | 6429 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
 | 6430 |         _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) | 
 | 6431 |     : __b_(__fB, __lB) | 
 | 6432 | { | 
 | 6433 |     if (__b_.size() < 2) | 
 | 6434 |     { | 
 | 6435 |         __b_.resize(2); | 
 | 6436 |         __b_[0] = 0; | 
 | 6437 |         __b_[1] = 1; | 
 | 6438 |         __densities_.assign(2, 1.0); | 
 | 6439 |         __areas_.assign(1, 0.0); | 
 | 6440 |     } | 
 | 6441 |     else | 
 | 6442 |     { | 
 | 6443 |         __densities_.reserve(__b_.size()); | 
 | 6444 |         for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) | 
 | 6445 |             __densities_.push_back(*__fW); | 
 | 6446 |         __init(); | 
 | 6447 |     } | 
 | 6448 | } | 
 | 6449 |  | 
 | 6450 | template<class _RealType> | 
 | 6451 | template<class _UnaryOperation> | 
 | 6452 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
 | 6453 |         initializer_list<result_type> __bl, _UnaryOperation __fw) | 
 | 6454 |     : __b_(__bl.begin(), __bl.end()) | 
 | 6455 | { | 
 | 6456 |     if (__b_.size() < 2) | 
 | 6457 |     { | 
 | 6458 |         __b_.resize(2); | 
 | 6459 |         __b_[0] = 0; | 
 | 6460 |         __b_[1] = 1; | 
 | 6461 |         __densities_.assign(2, 1.0); | 
 | 6462 |         __areas_.assign(1, 0.0); | 
 | 6463 |     } | 
 | 6464 |     else | 
 | 6465 |     { | 
 | 6466 |         __densities_.reserve(__b_.size()); | 
 | 6467 |         for (size_t __i = 0; __i < __b_.size(); ++__i) | 
 | 6468 |             __densities_.push_back(__fw(__b_[__i])); | 
 | 6469 |         __init(); | 
 | 6470 |     } | 
 | 6471 | } | 
 | 6472 |  | 
 | 6473 | template<class _RealType> | 
 | 6474 | template<class _UnaryOperation> | 
 | 6475 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
 | 6476 |         size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) | 
 | 6477 |     : __b_(__nw == 0 ? 2 : __nw + 1) | 
 | 6478 | { | 
 | 6479 |     size_t __n = __b_.size() - 1; | 
 | 6480 |     result_type __d = (__xmax - __xmin) / __n; | 
 | 6481 |     __densities_.reserve(__b_.size()); | 
 | 6482 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6483 |     { | 
 | 6484 |         __b_[__i] = __xmin + __i * __d; | 
 | 6485 |         __densities_.push_back(__fw(__b_[__i])); | 
 | 6486 |     } | 
 | 6487 |     __b_[__n] = __xmax; | 
 | 6488 |     __densities_.push_back(__fw(__b_[__n])); | 
 | 6489 |     __init(); | 
 | 6490 | } | 
 | 6491 |  | 
 | 6492 | template<class _RealType> | 
 | 6493 | template<class _URNG> | 
 | 6494 | _RealType | 
 | 6495 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
 | 6496 | { | 
 | 6497 |     typedef uniform_real_distribution<result_type> _Gen; | 
 | 6498 |     result_type __u = _Gen()(__g); | 
 | 6499 |     ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6500 |                                       __u) - __p.__areas_.begin() - 1; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6501 |     __u -= __p.__areas_[__k]; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6502 |     const result_type __dk = __p.__densities_[__k]; | 
 | 6503 |     const result_type __dk1 = __p.__densities_[__k+1]; | 
 | 6504 |     const result_type __deltad = __dk1 - __dk; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6505 |     const result_type __bk = __p.__b_[__k]; | 
 | 6506 |     if (__deltad == 0) | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6507 |         return __u / __dk + __bk; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6508 |     const result_type __bk1 = __p.__b_[__k+1]; | 
 | 6509 |     const result_type __deltab = __bk1 - __bk; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6510 |     return (__bk * __dk1 - __bk1 * __dk + | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6511 |         _STD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6512 |         __deltad; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6513 | } | 
 | 6514 |  | 
 | 6515 | template <class _CharT, class _Traits, class _RT> | 
 | 6516 | basic_ostream<_CharT, _Traits>& | 
 | 6517 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
 | 6518 |            const piecewise_linear_distribution<_RT>& __x) | 
 | 6519 | { | 
 | 6520 |     __save_flags<_CharT, _Traits> _(__os); | 
 | 6521 |     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
 | 6522 |                ios_base::scientific); | 
 | 6523 |     _CharT __sp = __os.widen(' '); | 
 | 6524 |     __os.fill(__sp); | 
 | 6525 |     size_t __n = __x.__p_.__b_.size(); | 
 | 6526 |     __os << __n; | 
 | 6527 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6528 |         __os << __sp << __x.__p_.__b_[__i]; | 
 | 6529 |     __n = __x.__p_.__densities_.size(); | 
 | 6530 |     __os << __sp << __n; | 
 | 6531 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6532 |         __os << __sp << __x.__p_.__densities_[__i]; | 
 | 6533 |     __n = __x.__p_.__areas_.size(); | 
 | 6534 |     __os << __sp << __n; | 
 | 6535 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6536 |         __os << __sp << __x.__p_.__areas_[__i]; | 
 | 6537 |     return __os; | 
 | 6538 | } | 
 | 6539 |  | 
 | 6540 | template <class _CharT, class _Traits, class _RT> | 
 | 6541 | basic_istream<_CharT, _Traits>& | 
 | 6542 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
 | 6543 |            piecewise_linear_distribution<_RT>& __x) | 
 | 6544 | { | 
 | 6545 |     typedef piecewise_linear_distribution<_RT> _Eng; | 
 | 6546 |     typedef typename _Eng::result_type result_type; | 
 | 6547 |     typedef typename _Eng::param_type param_type; | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6548 |     __save_flags<_CharT, _Traits> _(__is); | 
 | 6549 |     __is.flags(ios_base::dec | ios_base::skipws); | 
 | 6550 |     size_t __n; | 
 | 6551 |     __is >> __n; | 
 | 6552 |     vector<result_type> __b(__n); | 
 | 6553 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6554 |         __is >> __b[__i]; | 
 | 6555 |     __is >> __n; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6556 |     vector<result_type> __densities(__n); | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6557 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6558 |         __is >> __densities[__i]; | 
 | 6559 |     __is >> __n; | 
| Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6560 |     vector<result_type> __areas(__n); | 
| Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6561 |     for (size_t __i = 0; __i < __n; ++__i) | 
 | 6562 |         __is >> __areas[__i]; | 
 | 6563 |     if (!__is.fail()) | 
 | 6564 |     { | 
 | 6565 |         swap(__x.__p_.__b_, __b); | 
 | 6566 |         swap(__x.__p_.__densities_, __densities); | 
 | 6567 |         swap(__x.__p_.__areas_, __areas); | 
 | 6568 |     } | 
 | 6569 |     return __is; | 
 | 6570 | } | 
 | 6571 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6572 | _LIBCPP_END_NAMESPACE_STD | 
 | 6573 |  | 
 | 6574 | #endif  // _LIBCPP_RANDOM |