| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===--------------------------- random -----------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
| Howard Hinnant | 412dbeb | 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 | 3e51952 | 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 | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 374 | typedef minstd_rand                                       default_random_engine; | 
| Howard Hinnant | 3e51952 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 488 |  | 
| Howard Hinnant | 3e51952 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 547 |  | 
| Howard Hinnant | 3e51952 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 602 |  | 
| Howard Hinnant | 3e51952 | 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 | deb23ec | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 660 |  | 
| Howard Hinnant | deb23ec | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 |  | 
|  | 668 | template<class IntType = int> | 
| Howard Hinnant | 05fa30d | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 716 |  | 
| Howard Hinnant | 05fa30d | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 |  | 
|  | 724 | template<class IntType = int> | 
| Howard Hinnant | 89eaea2 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 774 |  | 
| Howard Hinnant | 89eaea2 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 781 |  | 
|  | 782 | template<class IntType = int> | 
| Howard Hinnant | 0e67581 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 830 |  | 
| Howard Hinnant | 0e67581 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 |  | 
|  | 838 | template<class RealType = double> | 
| Howard Hinnant | bcc4ff0 | 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 | 6f97c4e | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 850 | explicit param_type(result_type lambda = 1.0); | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 851 |  | 
| Howard Hinnant | 6f97c4e | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 852 | result_type lambda() const; | 
| Howard Hinnant | bcc4ff0 | 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 | 6f97c4e | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 859 | explicit exponential_distribution(result_type lambda = 1.0); | 
| Howard Hinnant | bcc4ff0 | 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 | 6f97c4e | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 868 | result_type lambda() const; | 
| Howard Hinnant | bcc4ff0 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 886 |  | 
| Howard Hinnant | bcc4ff0 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 |  | 
|  | 894 | template<class RealType = double> | 
| Howard Hinnant | f8bfb45 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 944 |  | 
| Howard Hinnant | f8bfb45 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 951 |  | 
|  | 952 | template<class RealType = double> | 
| Howard Hinnant | b882982 | 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 | b882982 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1002 |  | 
| Howard Hinnant | b882982 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 |  | 
|  | 1010 | template<class RealType = double> | 
| Howard Hinnant | c675d98 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1060 |  | 
| Howard Hinnant | c675d98 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 |  | 
|  | 1068 | template<class RealType = double> | 
| Howard Hinnant | 6f97c4e | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1118 |  | 
| Howard Hinnant | 6f97c4e | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 |  | 
|  | 1126 | template<class RealType = double> | 
| Howard Hinnant | fd5c3a3 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 |  | 
| Howard Hinnant | fd5c3a3 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 |  | 
|  | 1184 | template<class RealType = double> | 
| Howard Hinnant | e390073 | 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 | e390073 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1232 |  | 
| Howard Hinnant | e390073 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 |  | 
|  | 1240 | template<class RealType = double> | 
| Howard Hinnant | 6692b26 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1290 |  | 
| Howard Hinnant | 6692b26 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 |  | 
|  | 1298 | template<class RealType = double> | 
| Howard Hinnant | e31e36f | 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 | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1308 | typedef fisher_f_distribution distribution_type; | 
| Howard Hinnant | e31e36f | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1348 |  | 
| Howard Hinnant | e31e36f | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 |  | 
|  | 1356 | template<class RealType = double> | 
| Howard Hinnant | ecbb921 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1404 |  | 
| Howard Hinnant | ecbb921 | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 |  | 
|  | 1412 | template<class IntType = int> | 
| Howard Hinnant | fb0e5ec | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1471 |  | 
| Howard Hinnant | fb0e5ec | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 |  | 
|  | 1479 | template<class RealType = double> | 
| Howard Hinnant | e302eab | 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 | d518d1c | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1501 | vector<result_type> densities() const; | 
| Howard Hinnant | e302eab | 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 | d518d1c | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1528 | vector<result_type> densities() const; | 
| Howard Hinnant | e302eab | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1546 |  | 
| Howard Hinnant | e302eab | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1553 |  | 
|  | 1554 | template<class RealType = double> | 
| Howard Hinnant | b4d2fd2 | 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 | d518d1c | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1576 | vector<result_type> densities() const; | 
| Howard Hinnant | b4d2fd2 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1588 |  | 
| Howard Hinnant | b4d2fd2 | 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 | d518d1c | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1606 | vector<result_type> densities() const; | 
| Howard Hinnant | b4d2fd2 | 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 | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1624 |  | 
| Howard Hinnant | b4d2fd2 | 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 | 3e51952 | 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 | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1642 | #include <numeric> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | #include <vector> | 
|  | 1644 | #include <string> | 
|  | 1645 | #include <istream> | 
|  | 1646 | #include <ostream> | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 1647 | #include <cmath> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1648 |  | 
| Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame^] | 1649 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | #pragma GCC system_header | 
| Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame^] | 1651 | #endif | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 |  | 
|  | 1653 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 1654 |  | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1655 | // __is_seed_sequence | 
|  | 1656 |  | 
|  | 1657 | template <class _Sseq, class _Engine> | 
|  | 1658 | struct __is_seed_sequence | 
|  | 1659 | { | 
|  | 1660 | static const bool value = | 
|  | 1661 | !is_convertible<_Sseq, typename _Engine::result_type>::value && | 
|  | 1662 | !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; | 
|  | 1663 | }; | 
|  | 1664 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | // linear_congruential_engine | 
|  | 1666 |  | 
|  | 1667 | template <unsigned long long __a, unsigned long long __c, | 
|  | 1668 | unsigned long long __m, unsigned long long _M, | 
|  | 1669 | bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_M-__c)/__a)> | 
|  | 1670 | struct __lce_ta; | 
|  | 1671 |  | 
|  | 1672 | // 64 | 
|  | 1673 |  | 
|  | 1674 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> | 
|  | 1675 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> | 
|  | 1676 | { | 
|  | 1677 | typedef unsigned long long result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1678 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1679 | static result_type next(result_type __x) | 
|  | 1680 | { | 
|  | 1681 | // Schrage's algorithm | 
|  | 1682 | const result_type __q = __m / __a; | 
|  | 1683 | const result_type __r = __m % __a; | 
|  | 1684 | const result_type __t0 = __a * (__x % __q); | 
|  | 1685 | const result_type __t1 = __r * (__x / __q); | 
|  | 1686 | __x = __t0 + (__t0 < __t1) * __m - __t1; | 
|  | 1687 | __x += __c - (__x >= __m - __c) * __m; | 
|  | 1688 | return __x; | 
|  | 1689 | } | 
|  | 1690 | }; | 
|  | 1691 |  | 
|  | 1692 | template <unsigned long long __a, unsigned long long __m> | 
|  | 1693 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> | 
|  | 1694 | { | 
|  | 1695 | typedef unsigned long long result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1696 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | static result_type next(result_type __x) | 
|  | 1698 | { | 
|  | 1699 | // Schrage's algorithm | 
|  | 1700 | const result_type __q = __m / __a; | 
|  | 1701 | const result_type __r = __m % __a; | 
|  | 1702 | const result_type __t0 = __a * (__x % __q); | 
|  | 1703 | const result_type __t1 = __r * (__x / __q); | 
|  | 1704 | __x = __t0 + (__t0 < __t1) * __m - __t1; | 
|  | 1705 | return __x; | 
|  | 1706 | } | 
|  | 1707 | }; | 
|  | 1708 |  | 
|  | 1709 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> | 
|  | 1710 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> | 
|  | 1711 | { | 
|  | 1712 | typedef unsigned long long result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1713 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1714 | static result_type next(result_type __x) | 
|  | 1715 | { | 
|  | 1716 | return (__a * __x + __c) % __m; | 
|  | 1717 | } | 
|  | 1718 | }; | 
|  | 1719 |  | 
|  | 1720 | template <unsigned long long __a, unsigned long long __c> | 
|  | 1721 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> | 
|  | 1722 | { | 
|  | 1723 | typedef unsigned long long result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1724 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | static result_type next(result_type __x) | 
|  | 1726 | { | 
|  | 1727 | return __a * __x + __c; | 
|  | 1728 | } | 
|  | 1729 | }; | 
|  | 1730 |  | 
|  | 1731 | // 32 | 
|  | 1732 |  | 
|  | 1733 | template <unsigned long long _A, unsigned long long _C, unsigned long long _M> | 
|  | 1734 | struct __lce_ta<_A, _C, _M, unsigned(~0), true> | 
|  | 1735 | { | 
|  | 1736 | typedef unsigned result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1737 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | static result_type next(result_type __x) | 
|  | 1739 | { | 
|  | 1740 | const result_type __a = static_cast<result_type>(_A); | 
|  | 1741 | const result_type __c = static_cast<result_type>(_C); | 
|  | 1742 | const result_type __m = static_cast<result_type>(_M); | 
|  | 1743 | // Schrage's algorithm | 
|  | 1744 | const result_type __q = __m / __a; | 
|  | 1745 | const result_type __r = __m % __a; | 
|  | 1746 | const result_type __t0 = __a * (__x % __q); | 
|  | 1747 | const result_type __t1 = __r * (__x / __q); | 
|  | 1748 | __x = __t0 + (__t0 < __t1) * __m - __t1; | 
|  | 1749 | __x += __c - (__x >= __m - __c) * __m; | 
|  | 1750 | return __x; | 
|  | 1751 | } | 
|  | 1752 | }; | 
|  | 1753 |  | 
|  | 1754 | template <unsigned long long _A, unsigned long long _M> | 
|  | 1755 | struct __lce_ta<_A, 0, _M, unsigned(~0), true> | 
|  | 1756 | { | 
|  | 1757 | typedef unsigned result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1758 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1759 | static result_type next(result_type __x) | 
|  | 1760 | { | 
|  | 1761 | const result_type __a = static_cast<result_type>(_A); | 
|  | 1762 | const result_type __m = static_cast<result_type>(_M); | 
|  | 1763 | // Schrage's algorithm | 
|  | 1764 | const result_type __q = __m / __a; | 
|  | 1765 | const result_type __r = __m % __a; | 
|  | 1766 | const result_type __t0 = __a * (__x % __q); | 
|  | 1767 | const result_type __t1 = __r * (__x / __q); | 
|  | 1768 | __x = __t0 + (__t0 < __t1) * __m - __t1; | 
|  | 1769 | return __x; | 
|  | 1770 | } | 
|  | 1771 | }; | 
|  | 1772 |  | 
|  | 1773 | template <unsigned long long _A, unsigned long long _C, unsigned long long _M> | 
|  | 1774 | struct __lce_ta<_A, _C, _M, unsigned(~0), false> | 
|  | 1775 | { | 
|  | 1776 | typedef unsigned result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1777 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1778 | static result_type next(result_type __x) | 
|  | 1779 | { | 
|  | 1780 | const result_type __a = static_cast<result_type>(_A); | 
|  | 1781 | const result_type __c = static_cast<result_type>(_C); | 
|  | 1782 | const result_type __m = static_cast<result_type>(_M); | 
|  | 1783 | return (__a * __x + __c) % __m; | 
|  | 1784 | } | 
|  | 1785 | }; | 
|  | 1786 |  | 
|  | 1787 | template <unsigned long long _A, unsigned long long _C> | 
|  | 1788 | struct __lce_ta<_A, _C, 0, unsigned(~0), false> | 
|  | 1789 | { | 
|  | 1790 | typedef unsigned result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1791 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1792 | static result_type next(result_type __x) | 
|  | 1793 | { | 
|  | 1794 | const result_type __a = static_cast<result_type>(_A); | 
|  | 1795 | const result_type __c = static_cast<result_type>(_C); | 
|  | 1796 | return __a * __x + __c; | 
|  | 1797 | } | 
|  | 1798 | }; | 
|  | 1799 |  | 
|  | 1800 | // 16 | 
|  | 1801 |  | 
|  | 1802 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> | 
|  | 1803 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> | 
|  | 1804 | { | 
|  | 1805 | typedef unsigned short result_type; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1806 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | static result_type next(result_type __x) | 
|  | 1808 | { | 
|  | 1809 | return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); | 
|  | 1810 | } | 
|  | 1811 | }; | 
|  | 1812 |  | 
|  | 1813 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
|  | 1814 | class linear_congruential_engine; | 
|  | 1815 |  | 
|  | 1816 | template <class _CharT, class _Traits, | 
|  | 1817 | class _U, _U _A, _U _C, _U _N> | 
|  | 1818 | basic_ostream<_CharT, _Traits>& | 
|  | 1819 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 1820 | const linear_congruential_engine<_U, _A, _C, _N>&); | 
|  | 1821 |  | 
|  | 1822 | template <class _CharT, class _Traits, | 
|  | 1823 | class _U, _U _A, _U _C, _U _N> | 
|  | 1824 | basic_istream<_CharT, _Traits>& | 
|  | 1825 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 1826 | linear_congruential_engine<_U, _A, _C, _N>& __x); | 
|  | 1827 |  | 
|  | 1828 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1829 | class _LIBCPP_VISIBLE linear_congruential_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | { | 
|  | 1831 | public: | 
|  | 1832 | // types | 
|  | 1833 | typedef _UIntType result_type; | 
|  | 1834 |  | 
|  | 1835 | private: | 
|  | 1836 | result_type __x_; | 
|  | 1837 |  | 
|  | 1838 | static const result_type _M = result_type(~0); | 
|  | 1839 |  | 
|  | 1840 | static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); | 
|  | 1841 | static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); | 
|  | 1842 | public: | 
|  | 1843 | static const result_type _Min = __c == 0u ? 1u: 0u; | 
|  | 1844 | static const result_type _Max = __m - 1u; | 
|  | 1845 | static_assert(_Min < _Max,           "linear_congruential_engine invalid parameters"); | 
|  | 1846 |  | 
|  | 1847 | // engine characteristics | 
|  | 1848 | static const/*expr*/ result_type multiplier = __a; | 
|  | 1849 | static const/*expr*/ result_type increment = __c; | 
|  | 1850 | static const/*expr*/ result_type modulus = __m; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1851 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 | static const/*expr*/ result_type min() {return _Min;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1853 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | static const/*expr*/ result_type max() {return _Max;} | 
|  | 1855 | static const/*expr*/ result_type default_seed = 1u; | 
|  | 1856 |  | 
|  | 1857 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1858 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | explicit linear_congruential_engine(result_type __s = default_seed) | 
|  | 1860 | {seed(__s);} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 1861 | template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q, | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1862 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1863 | typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1864 | {seed(__q);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1865 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1866 | void seed(result_type __s = default_seed) | 
|  | 1867 | {seed(integral_constant<bool, __m == 0>(), | 
|  | 1868 | integral_constant<bool, __c == 0>(), __s);} | 
|  | 1869 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1870 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1871 | typename enable_if | 
|  | 1872 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1873 | __is_seed_sequence<_Sseq, linear_congruential_engine>::value, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | void | 
|  | 1875 | >::type | 
|  | 1876 | seed(_Sseq& __q) | 
|  | 1877 | {__seed(__q, integral_constant<unsigned, | 
|  | 1878 | 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 | 
|  | 1879 | :  (__m-1) / 0x100000000ull)>());} | 
|  | 1880 |  | 
|  | 1881 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1882 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1883 | result_type operator()() | 
|  | 1884 | {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _M>::next(__x_));} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1885 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 1887 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1888 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 1889 | bool operator==(const linear_congruential_engine& __x, | 
|  | 1890 | const linear_congruential_engine& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1891 | {return __x.__x_ == __y.__x_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1892 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 1893 | bool operator!=(const linear_congruential_engine& __x, | 
|  | 1894 | const linear_congruential_engine& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | {return !(__x == __y);} | 
|  | 1896 |  | 
|  | 1897 | private: | 
|  | 1898 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1899 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 | void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1901 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1902 | void seed(true_type, false_type, result_type __s) {__x_ = __s;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1903 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? | 
|  | 1905 | 1 : __s % __m;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1906 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1907 | void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} | 
|  | 1908 |  | 
|  | 1909 | template<class _Sseq> | 
|  | 1910 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
|  | 1911 | template<class _Sseq> | 
|  | 1912 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
|  | 1913 |  | 
|  | 1914 | template <class _CharT, class _Traits, | 
|  | 1915 | class _U, _U _A, _U _C, _U _N> | 
|  | 1916 | friend | 
|  | 1917 | basic_ostream<_CharT, _Traits>& | 
|  | 1918 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 1919 | const linear_congruential_engine<_U, _A, _C, _N>&); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1920 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1921 | template <class _CharT, class _Traits, | 
|  | 1922 | class _U, _U _A, _U _C, _U _N> | 
|  | 1923 | friend | 
|  | 1924 | basic_istream<_CharT, _Traits>& | 
|  | 1925 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 1926 | linear_congruential_engine<_U, _A, _C, _N>& __x); | 
|  | 1927 | }; | 
|  | 1928 |  | 
|  | 1929 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
|  | 1930 | template<class _Sseq> | 
|  | 1931 | void | 
|  | 1932 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, | 
|  | 1933 | integral_constant<unsigned, 1>) | 
|  | 1934 | { | 
|  | 1935 | const unsigned __k = 1; | 
|  | 1936 | uint32_t __ar[__k+3]; | 
|  | 1937 | __q.generate(__ar, __ar + __k + 3); | 
|  | 1938 | result_type __s = static_cast<result_type>(__ar[3] % __m); | 
|  | 1939 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; | 
|  | 1940 | } | 
|  | 1941 |  | 
|  | 1942 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
|  | 1943 | template<class _Sseq> | 
|  | 1944 | void | 
|  | 1945 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, | 
|  | 1946 | integral_constant<unsigned, 2>) | 
|  | 1947 | { | 
|  | 1948 | const unsigned __k = 2; | 
|  | 1949 | uint32_t __ar[__k+3]; | 
|  | 1950 | __q.generate(__ar, __ar + __k + 3); | 
|  | 1951 | result_type __s = static_cast<result_type>((__ar[3] + | 
|  | 1952 | (uint64_t)__ar[4] << 32) % __m); | 
|  | 1953 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; | 
|  | 1954 | } | 
|  | 1955 |  | 
|  | 1956 | template <class _CharT, class _Traits> | 
|  | 1957 | class __save_flags | 
|  | 1958 | { | 
|  | 1959 | typedef basic_ios<_CharT, _Traits> __stream_type; | 
|  | 1960 | typedef typename __stream_type::fmtflags fmtflags; | 
|  | 1961 |  | 
|  | 1962 | __stream_type& __stream_; | 
|  | 1963 | fmtflags       __fmtflags_; | 
|  | 1964 | _CharT         __fill_; | 
|  | 1965 |  | 
|  | 1966 | __save_flags(const __save_flags&); | 
|  | 1967 | __save_flags& operator=(const __save_flags&); | 
|  | 1968 | public: | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1969 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1970 | explicit __save_flags(__stream_type& __stream) | 
|  | 1971 | : __stream_(__stream), | 
|  | 1972 | __fmtflags_(__stream.flags()), | 
|  | 1973 | __fill_(__stream.fill()) | 
|  | 1974 | {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1975 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1976 | ~__save_flags() | 
|  | 1977 | { | 
|  | 1978 | __stream_.flags(__fmtflags_); | 
|  | 1979 | __stream_.fill(__fill_); | 
|  | 1980 | } | 
|  | 1981 | }; | 
|  | 1982 |  | 
|  | 1983 | template <class _CharT, class _Traits, | 
|  | 1984 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1985 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | basic_ostream<_CharT, _Traits>& | 
|  | 1987 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 1988 | const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) | 
|  | 1989 | { | 
|  | 1990 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 1991 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 1992 | __os.fill(__os.widen(' ')); | 
|  | 1993 | return __os << __x.__x_; | 
|  | 1994 | } | 
|  | 1995 |  | 
|  | 1996 | template <class _CharT, class _Traits, | 
|  | 1997 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> | 
|  | 1998 | basic_istream<_CharT, _Traits>& | 
|  | 1999 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2000 | linear_congruential_engine<_UIntType, __a, __c, __m>& __x) | 
|  | 2001 | { | 
|  | 2002 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 2003 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 2004 | _UIntType __t; | 
|  | 2005 | __is >> __t; | 
|  | 2006 | if (!__is.fail()) | 
|  | 2007 | __x.__x_ = __t; | 
|  | 2008 | return __is; | 
|  | 2009 | } | 
|  | 2010 |  | 
|  | 2011 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> | 
|  | 2012 | minstd_rand0; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2013 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> | 
|  | 2014 | minstd_rand; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2015 | typedef minstd_rand                                       default_random_engine; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2016 | // mersenne_twister_engine | 
|  | 2017 |  | 
|  | 2018 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2019 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2020 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
|  | 2021 | class mersenne_twister_engine; | 
|  | 2022 |  | 
|  | 2023 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2024 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2025 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2026 | bool | 
|  | 2027 | operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2028 | _B, _T, _C, _L, _F>& __x, | 
|  | 2029 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2030 | _B, _T, _C, _L, _F>& __y); | 
|  | 2031 |  | 
|  | 2032 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2033 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2034 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2035 | bool | 
|  | 2036 | operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2037 | _B, _T, _C, _L, _F>& __x, | 
|  | 2038 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2039 | _B, _T, _C, _L, _F>& __y); | 
|  | 2040 |  | 
|  | 2041 | template <class _CharT, class _Traits, | 
|  | 2042 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2043 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2044 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2045 | basic_ostream<_CharT, _Traits>& | 
|  | 2046 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2047 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2048 | _B, _T, _C, _L, _F>& __x); | 
|  | 2049 |  | 
|  | 2050 | template <class _CharT, class _Traits, | 
|  | 2051 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2052 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2053 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2054 | basic_istream<_CharT, _Traits>& | 
|  | 2055 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2056 | mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2057 | _B, _T, _C, _L, _F>& __x); | 
|  | 2058 |  | 
|  | 2059 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2060 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2061 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2062 | class _LIBCPP_VISIBLE mersenne_twister_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2063 | { | 
|  | 2064 | public: | 
|  | 2065 | // types | 
|  | 2066 | typedef _UIntType result_type; | 
|  | 2067 |  | 
|  | 2068 | private: | 
|  | 2069 | result_type __x_[__n]; | 
|  | 2070 | size_t      __i_; | 
|  | 2071 |  | 
|  | 2072 | static_assert(  0 <  __m, "mersenne_twister_engine invalid parameters"); | 
|  | 2073 | static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); | 
|  | 2074 | static const result_type _Dt = numeric_limits<result_type>::digits; | 
|  | 2075 | static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); | 
|  | 2076 | static_assert(  2 <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2077 | static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2078 | static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2079 | static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2080 | static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2081 | static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); | 
|  | 2082 | public: | 
|  | 2083 | static const result_type _Min = 0; | 
|  | 2084 | static const result_type _Max = __w == _Dt ? result_type(~0) : | 
|  | 2085 | (result_type(1) << __w) - result_type(1); | 
|  | 2086 | static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2087 | static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2088 | static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2089 | static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2090 | static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2091 | static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); | 
|  | 2092 |  | 
|  | 2093 | // engine characteristics | 
|  | 2094 | static const/*expr*/ size_t word_size = __w; | 
|  | 2095 | static const/*expr*/ size_t state_size = __n; | 
|  | 2096 | static const/*expr*/ size_t shift_size = __m; | 
|  | 2097 | static const/*expr*/ size_t mask_bits = __r; | 
|  | 2098 | static const/*expr*/ result_type xor_mask = __a; | 
|  | 2099 | static const/*expr*/ size_t tempering_u = __u; | 
|  | 2100 | static const/*expr*/ result_type tempering_d = __d; | 
|  | 2101 | static const/*expr*/ size_t tempering_s = __s; | 
|  | 2102 | static const/*expr*/ result_type tempering_b = __b; | 
|  | 2103 | static const/*expr*/ size_t tempering_t = __t; | 
|  | 2104 | static const/*expr*/ result_type tempering_c = __c; | 
|  | 2105 | static const/*expr*/ size_t tempering_l = __l; | 
|  | 2106 | static const/*expr*/ result_type initialization_multiplier = __f; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2107 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2108 | static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2109 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | static const/*expr*/ result_type max() { return _Max; } | 
|  | 2111 | static const/*expr*/ result_type default_seed = 5489u; | 
|  | 2112 |  | 
|  | 2113 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2114 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2115 | explicit mersenne_twister_engine(result_type __sd = default_seed) | 
|  | 2116 | {seed(__sd);} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2117 | template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q, | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2118 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2119 | typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2120 | {seed(__q);} | 
|  | 2121 | void seed(result_type __sd = default_seed); | 
|  | 2122 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2123 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2124 | typename enable_if | 
|  | 2125 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2126 | __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2127 | void | 
|  | 2128 | >::type | 
|  | 2129 | seed(_Sseq& __q) | 
|  | 2130 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
|  | 2131 |  | 
|  | 2132 | // generating functions | 
|  | 2133 | result_type operator()(); | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2134 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2135 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 2136 |  | 
|  | 2137 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2138 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2139 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2140 | friend | 
|  | 2141 | bool | 
|  | 2142 | operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2143 | _B, _T, _C, _L, _F>& __x, | 
|  | 2144 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2145 | _B, _T, _C, _L, _F>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2146 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2147 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2148 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2149 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2150 | friend | 
|  | 2151 | bool | 
|  | 2152 | operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2153 | _B, _T, _C, _L, _F>& __x, | 
|  | 2154 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2155 | _B, _T, _C, _L, _F>& __y); | 
|  | 2156 |  | 
|  | 2157 | template <class _CharT, class _Traits, | 
|  | 2158 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2159 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2160 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2161 | friend | 
|  | 2162 | basic_ostream<_CharT, _Traits>& | 
|  | 2163 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2164 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2165 | _B, _T, _C, _L, _F>& __x); | 
|  | 2166 |  | 
|  | 2167 | template <class _CharT, class _Traits, | 
|  | 2168 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2169 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2170 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2171 | friend | 
|  | 2172 | basic_istream<_CharT, _Traits>& | 
|  | 2173 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2174 | mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2175 | _B, _T, _C, _L, _F>& __x); | 
|  | 2176 | private: | 
|  | 2177 |  | 
|  | 2178 | template<class _Sseq> | 
|  | 2179 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
|  | 2180 | template<class _Sseq> | 
|  | 2181 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
|  | 2182 |  | 
|  | 2183 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2184 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2185 | static | 
|  | 2186 | typename enable_if | 
|  | 2187 | < | 
|  | 2188 | __count < __w, | 
|  | 2189 | result_type | 
|  | 2190 | >::type | 
|  | 2191 | __lshift(result_type __x) {return (__x << __count) & _Max;} | 
|  | 2192 |  | 
|  | 2193 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2194 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | static | 
|  | 2196 | typename enable_if | 
|  | 2197 | < | 
|  | 2198 | (__count >= __w), | 
|  | 2199 | result_type | 
|  | 2200 | >::type | 
|  | 2201 | __lshift(result_type __x) {return result_type(0);} | 
|  | 2202 |  | 
|  | 2203 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2204 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2205 | static | 
|  | 2206 | typename enable_if | 
|  | 2207 | < | 
|  | 2208 | __count < _Dt, | 
|  | 2209 | result_type | 
|  | 2210 | >::type | 
|  | 2211 | __rshift(result_type __x) {return __x >> __count;} | 
|  | 2212 |  | 
|  | 2213 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2214 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2215 | static | 
|  | 2216 | typename enable_if | 
|  | 2217 | < | 
|  | 2218 | (__count >= _Dt), | 
|  | 2219 | result_type | 
|  | 2220 | >::type | 
|  | 2221 | __rshift(result_type __x) {return result_type(0);} | 
|  | 2222 | }; | 
|  | 2223 |  | 
|  | 2224 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2225 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2226 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
|  | 2227 | void | 
|  | 2228 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
|  | 2229 | __t, __c, __l, __f>::seed(result_type __sd) | 
|  | 2230 | {   // __w >= 2 | 
|  | 2231 | __x_[0] = __sd & _Max; | 
|  | 2232 | for (size_t __i = 1; __i < __n; ++__i) | 
|  | 2233 | __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; | 
|  | 2234 | __i_ = 0; | 
|  | 2235 | } | 
|  | 2236 |  | 
|  | 2237 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2238 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2239 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
|  | 2240 | template<class _Sseq> | 
|  | 2241 | void | 
|  | 2242 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
|  | 2243 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) | 
|  | 2244 | { | 
|  | 2245 | const unsigned __k = 1; | 
|  | 2246 | uint32_t __ar[__n * __k]; | 
|  | 2247 | __q.generate(__ar, __ar + __n * __k); | 
|  | 2248 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 2249 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); | 
|  | 2250 | const result_type __mask = __r == _Dt ? result_type(~0) : | 
|  | 2251 | (result_type(1) << __r) - result_type(1); | 
|  | 2252 | __i_ = 0; | 
|  | 2253 | if ((__x_[0] & ~__mask) == 0) | 
|  | 2254 | { | 
|  | 2255 | for (size_t __i = 1; __i < __n; ++__i) | 
|  | 2256 | if (__x_[__i] != 0) | 
|  | 2257 | return; | 
|  | 2258 | __x_[0] = _Max; | 
|  | 2259 | } | 
|  | 2260 | } | 
|  | 2261 |  | 
|  | 2262 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2263 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2264 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
|  | 2265 | template<class _Sseq> | 
|  | 2266 | void | 
|  | 2267 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
|  | 2268 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) | 
|  | 2269 | { | 
|  | 2270 | const unsigned __k = 2; | 
|  | 2271 | uint32_t __ar[__n * __k]; | 
|  | 2272 | __q.generate(__ar, __ar + __n * __k); | 
|  | 2273 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 2274 | __x_[__i] = static_cast<result_type>( | 
|  | 2275 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); | 
|  | 2276 | const result_type __mask = __r == _Dt ? result_type(~0) : | 
|  | 2277 | (result_type(1) << __r) - result_type(1); | 
|  | 2278 | __i_ = 0; | 
|  | 2279 | if ((__x_[0] & ~__mask) == 0) | 
|  | 2280 | { | 
|  | 2281 | for (size_t __i = 1; __i < __n; ++__i) | 
|  | 2282 | if (__x_[__i] != 0) | 
|  | 2283 | return; | 
|  | 2284 | __x_[0] = _Max; | 
|  | 2285 | } | 
|  | 2286 | } | 
|  | 2287 |  | 
|  | 2288 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, | 
|  | 2289 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, | 
|  | 2290 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> | 
|  | 2291 | _UIntType | 
|  | 2292 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, | 
|  | 2293 | __t, __c, __l, __f>::operator()() | 
|  | 2294 | { | 
|  | 2295 | const size_t __j = (__i_ + 1) % __n; | 
|  | 2296 | const result_type __mask = __r == _Dt ? result_type(~0) : | 
|  | 2297 | (result_type(1) << __r) - result_type(1); | 
|  | 2298 | const result_type _Y = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); | 
|  | 2299 | const size_t __k = (__i_ + __m) % __n; | 
|  | 2300 | __x_[__i_] = __x_[__k] ^ __rshift<1>(_Y) ^ (__a * (_Y & 1)); | 
|  | 2301 | result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); | 
|  | 2302 | __i_ = __j; | 
|  | 2303 | __z ^= __lshift<__s>(__z) & __b; | 
|  | 2304 | __z ^= __lshift<__t>(__z) & __c; | 
|  | 2305 | return __z ^ __rshift<__l>(__z); | 
|  | 2306 | } | 
|  | 2307 |  | 
|  | 2308 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2309 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2310 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2311 | bool | 
|  | 2312 | operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2313 | _B, _T, _C, _L, _F>& __x, | 
|  | 2314 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2315 | _B, _T, _C, _L, _F>& __y) | 
|  | 2316 | { | 
|  | 2317 | if (__x.__i_ == __y.__i_) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2318 | return _VSTD::equal(__x.__x_, __x.__x_ + _N, __y.__x_); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2319 | if (__x.__i_ == 0 || __y.__i_ == 0) | 
|  | 2320 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2321 | size_t __j = _VSTD::min(_N - __x.__i_, _N - __y.__i_); | 
|  | 2322 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2323 | __y.__x_ + __y.__i_)) | 
|  | 2324 | return false; | 
|  | 2325 | if (__x.__i_ == 0) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2326 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _N, __y.__x_); | 
|  | 2327 | return _VSTD::equal(__x.__x_, __x.__x_ + (_N - __j), __y.__x_ + __j); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2328 | } | 
|  | 2329 | if (__x.__i_ < __y.__i_) | 
|  | 2330 | { | 
|  | 2331 | size_t __j = _N - __y.__i_; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2332 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2333 | __y.__x_ + __y.__i_)) | 
|  | 2334 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2335 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _N, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2336 | __y.__x_)) | 
|  | 2337 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2338 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2339 | __y.__x_ + (_N - (__x.__i_ + __j))); | 
|  | 2340 | } | 
|  | 2341 | size_t __j = _N - __x.__i_; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2342 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | __x.__x_ + __x.__i_)) | 
|  | 2344 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2345 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _N, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2346 | __x.__x_)) | 
|  | 2347 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2348 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2349 | __x.__x_ + (_N - (__y.__i_ + __j))); | 
|  | 2350 | } | 
|  | 2351 |  | 
|  | 2352 | template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2353 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2354 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2355 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2356 | bool | 
|  | 2357 | operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2358 | _B, _T, _C, _L, _F>& __x, | 
|  | 2359 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2360 | _B, _T, _C, _L, _F>& __y) | 
|  | 2361 | { | 
|  | 2362 | return !(__x == __y); | 
|  | 2363 | } | 
|  | 2364 |  | 
|  | 2365 | template <class _CharT, class _Traits, | 
|  | 2366 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2367 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2368 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2369 | basic_ostream<_CharT, _Traits>& | 
|  | 2370 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2371 | const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2372 | _B, _T, _C, _L, _F>& __x) | 
|  | 2373 | { | 
|  | 2374 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 2375 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 2376 | _CharT __sp = __os.widen(' '); | 
|  | 2377 | __os.fill(__sp); | 
|  | 2378 | __os << __x.__x_[__x.__i_]; | 
|  | 2379 | for (size_t __j = __x.__i_ + 1; __j < _N; ++__j) | 
|  | 2380 | __os << __sp << __x.__x_[__j]; | 
|  | 2381 | for (size_t __j = 0; __j < __x.__i_; ++__j) | 
|  | 2382 | __os << __sp << __x.__x_[__j]; | 
|  | 2383 | return __os; | 
|  | 2384 | } | 
|  | 2385 |  | 
|  | 2386 | template <class _CharT, class _Traits, | 
|  | 2387 | class _UI, size_t _W, size_t _N, size_t _M, size_t _R, | 
|  | 2388 | _UI _A, size_t _U, _UI _D, size_t _S, | 
|  | 2389 | _UI _B, size_t _T, _UI _C, size_t _L, _UI _F> | 
|  | 2390 | basic_istream<_CharT, _Traits>& | 
|  | 2391 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2392 | mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S, | 
|  | 2393 | _B, _T, _C, _L, _F>& __x) | 
|  | 2394 | { | 
|  | 2395 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 2396 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 2397 | _UI __t[_N]; | 
|  | 2398 | for (size_t __i = 0; __i < _N; ++__i) | 
|  | 2399 | __is >> __t[__i]; | 
|  | 2400 | if (!__is.fail()) | 
|  | 2401 | { | 
|  | 2402 | for (size_t __i = 0; __i < _N; ++__i) | 
|  | 2403 | __x.__x_[__i] = __t[__i]; | 
|  | 2404 | __x.__i_ = 0; | 
|  | 2405 | } | 
|  | 2406 | return __is; | 
|  | 2407 | } | 
|  | 2408 |  | 
|  | 2409 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, | 
|  | 2410 | 0x9908b0df, 11, 0xffffffff, | 
|  | 2411 | 7,  0x9d2c5680, | 
|  | 2412 | 15, 0xefc60000, | 
|  | 2413 | 18, 1812433253>                         mt19937; | 
|  | 2414 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, | 
|  | 2415 | 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, | 
|  | 2416 | 17, 0x71d67fffeda60000ULL, | 
|  | 2417 | 37, 0xfff7eee000000000ULL, | 
|  | 2418 | 43, 6364136223846793005ULL>          mt19937_64; | 
|  | 2419 |  | 
|  | 2420 | // subtract_with_carry_engine | 
|  | 2421 |  | 
|  | 2422 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2423 | class subtract_with_carry_engine; | 
|  | 2424 |  | 
|  | 2425 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2426 | bool | 
|  | 2427 | operator==( | 
|  | 2428 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2429 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
|  | 2430 |  | 
|  | 2431 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2432 | bool | 
|  | 2433 | operator!=( | 
|  | 2434 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2435 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
|  | 2436 |  | 
|  | 2437 | template <class _CharT, class _Traits, | 
|  | 2438 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2439 | basic_ostream<_CharT, _Traits>& | 
|  | 2440 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2441 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
|  | 2442 |  | 
|  | 2443 | template <class _CharT, class _Traits, | 
|  | 2444 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2445 | basic_istream<_CharT, _Traits>& | 
|  | 2446 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2447 | subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
|  | 2448 |  | 
|  | 2449 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2450 | class _LIBCPP_VISIBLE subtract_with_carry_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2451 | { | 
|  | 2452 | public: | 
|  | 2453 | // types | 
|  | 2454 | typedef _UIntType result_type; | 
|  | 2455 |  | 
|  | 2456 | private: | 
|  | 2457 | result_type __x_[__r]; | 
|  | 2458 | result_type  __c_; | 
|  | 2459 | size_t      __i_; | 
|  | 2460 |  | 
|  | 2461 | static const result_type _Dt = numeric_limits<result_type>::digits; | 
|  | 2462 | static_assert(  0 <  __w, "subtract_with_carry_engine invalid parameters"); | 
|  | 2463 | static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); | 
|  | 2464 | static_assert(  0 <  __s, "subtract_with_carry_engine invalid parameters"); | 
|  | 2465 | static_assert(__s <  __r, "subtract_with_carry_engine invalid parameters"); | 
|  | 2466 | public: | 
|  | 2467 | static const result_type _Min = 0; | 
|  | 2468 | static const result_type _Max = __w == _Dt ? result_type(~0) : | 
|  | 2469 | (result_type(1) << __w) - result_type(1); | 
|  | 2470 | static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); | 
|  | 2471 |  | 
|  | 2472 | // engine characteristics | 
|  | 2473 | static const/*expr*/ size_t word_size = __w; | 
|  | 2474 | static const/*expr*/ size_t short_lag = __s; | 
|  | 2475 | static const/*expr*/ size_t long_lag = __r; | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2476 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2477 | static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2478 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2479 | static const/*expr*/ result_type max() { return _Max; } | 
|  | 2480 | static const/*expr*/ result_type default_seed = 19780503u; | 
|  | 2481 |  | 
|  | 2482 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2483 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2484 | explicit subtract_with_carry_engine(result_type __sd = default_seed) | 
|  | 2485 | {seed(__sd);} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2486 | template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q, | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2487 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2488 | typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2489 | {seed(__q);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2490 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2491 | void seed(result_type __sd = default_seed) | 
|  | 2492 | {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
|  | 2493 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2494 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2495 | typename enable_if | 
|  | 2496 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2497 | __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2498 | void | 
|  | 2499 | >::type | 
|  | 2500 | seed(_Sseq& __q) | 
|  | 2501 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} | 
|  | 2502 |  | 
|  | 2503 | // generating functions | 
|  | 2504 | result_type operator()(); | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2505 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2506 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 2507 |  | 
|  | 2508 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2509 | friend | 
|  | 2510 | bool | 
|  | 2511 | operator==( | 
|  | 2512 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2513 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2514 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2515 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2516 | friend | 
|  | 2517 | bool | 
|  | 2518 | operator!=( | 
|  | 2519 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2520 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2521 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2522 | template <class _CharT, class _Traits, | 
|  | 2523 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2524 | friend | 
|  | 2525 | basic_ostream<_CharT, _Traits>& | 
|  | 2526 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2527 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2528 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2529 | template <class _CharT, class _Traits, | 
|  | 2530 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2531 | friend | 
|  | 2532 | basic_istream<_CharT, _Traits>& | 
|  | 2533 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2534 | subtract_with_carry_engine<_UI, _W, _S, _R>& __x); | 
|  | 2535 |  | 
|  | 2536 | private: | 
|  | 2537 |  | 
|  | 2538 | void seed(result_type __sd, integral_constant<unsigned, 1>); | 
|  | 2539 | void seed(result_type __sd, integral_constant<unsigned, 2>); | 
|  | 2540 | template<class _Sseq> | 
|  | 2541 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); | 
|  | 2542 | template<class _Sseq> | 
|  | 2543 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); | 
|  | 2544 | }; | 
|  | 2545 |  | 
|  | 2546 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2547 | void | 
|  | 2548 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, | 
|  | 2549 | integral_constant<unsigned, 1>) | 
|  | 2550 | { | 
|  | 2551 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> | 
|  | 2552 | __e(__sd == 0u ? default_seed : __sd); | 
|  | 2553 | for (size_t __i = 0; __i < __r; ++__i) | 
|  | 2554 | __x_[__i] = static_cast<result_type>(__e() & _Max); | 
|  | 2555 | __c_ = __x_[__r-1] == 0; | 
|  | 2556 | __i_ = 0; | 
|  | 2557 | } | 
|  | 2558 |  | 
|  | 2559 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2560 | void | 
|  | 2561 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, | 
|  | 2562 | integral_constant<unsigned, 2>) | 
|  | 2563 | { | 
|  | 2564 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> | 
|  | 2565 | __e(__sd == 0u ? default_seed : __sd); | 
|  | 2566 | for (size_t __i = 0; __i < __r; ++__i) | 
| Howard Hinnant | 052fd93 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2567 | { | 
|  | 2568 | result_type __e0 = __e(); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2569 | __x_[__i] = static_cast<result_type>( | 
| Howard Hinnant | 052fd93 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2570 | (__e0 + ((uint64_t)__e() << 32)) & _Max); | 
|  | 2571 | } | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2572 | __c_ = __x_[__r-1] == 0; | 
|  | 2573 | __i_ = 0; | 
|  | 2574 | } | 
|  | 2575 |  | 
|  | 2576 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2577 | template<class _Sseq> | 
|  | 2578 | void | 
|  | 2579 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, | 
|  | 2580 | integral_constant<unsigned, 1>) | 
|  | 2581 | { | 
|  | 2582 | const unsigned __k = 1; | 
|  | 2583 | uint32_t __ar[__r * __k]; | 
|  | 2584 | __q.generate(__ar, __ar + __r * __k); | 
|  | 2585 | for (size_t __i = 0; __i < __r; ++__i) | 
|  | 2586 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); | 
|  | 2587 | __c_ = __x_[__r-1] == 0; | 
|  | 2588 | __i_ = 0; | 
|  | 2589 | } | 
|  | 2590 |  | 
|  | 2591 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2592 | template<class _Sseq> | 
|  | 2593 | void | 
|  | 2594 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, | 
|  | 2595 | integral_constant<unsigned, 2>) | 
|  | 2596 | { | 
|  | 2597 | const unsigned __k = 2; | 
|  | 2598 | uint32_t __ar[__r * __k]; | 
|  | 2599 | __q.generate(__ar, __ar + __r * __k); | 
|  | 2600 | for (size_t __i = 0; __i < __r; ++__i) | 
|  | 2601 | __x_[__i] = static_cast<result_type>( | 
|  | 2602 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); | 
|  | 2603 | __c_ = __x_[__r-1] == 0; | 
|  | 2604 | __i_ = 0; | 
|  | 2605 | } | 
|  | 2606 |  | 
|  | 2607 | template<class _UIntType, size_t __w, size_t __s, size_t __r> | 
|  | 2608 | _UIntType | 
|  | 2609 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() | 
|  | 2610 | { | 
|  | 2611 | const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; | 
|  | 2612 | result_type& __xr = __x_[__i_]; | 
|  | 2613 | result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; | 
|  | 2614 | __xr = (__xs - __xr - __c_) & _Max; | 
|  | 2615 | __c_ = __new_c; | 
|  | 2616 | __i_ = (__i_ + 1) % __r; | 
|  | 2617 | return __xr; | 
|  | 2618 | } | 
|  | 2619 |  | 
|  | 2620 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2621 | bool | 
|  | 2622 | operator==( | 
|  | 2623 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2624 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y) | 
|  | 2625 | { | 
|  | 2626 | if (__x.__c_ != __y.__c_) | 
|  | 2627 | return false; | 
|  | 2628 | if (__x.__i_ == __y.__i_) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2629 | return _VSTD::equal(__x.__x_, __x.__x_ + _R, __y.__x_); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2630 | if (__x.__i_ == 0 || __y.__i_ == 0) | 
|  | 2631 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2632 | size_t __j = _VSTD::min(_R - __x.__i_, _R - __y.__i_); | 
|  | 2633 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2634 | __y.__x_ + __y.__i_)) | 
|  | 2635 | return false; | 
|  | 2636 | if (__x.__i_ == 0) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2637 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _R, __y.__x_); | 
|  | 2638 | return _VSTD::equal(__x.__x_, __x.__x_ + (_R - __j), __y.__x_ + __j); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2639 | } | 
|  | 2640 | if (__x.__i_ < __y.__i_) | 
|  | 2641 | { | 
|  | 2642 | size_t __j = _R - __y.__i_; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2643 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2644 | __y.__x_ + __y.__i_)) | 
|  | 2645 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2646 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _R, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | __y.__x_)) | 
|  | 2648 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2649 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2650 | __y.__x_ + (_R - (__x.__i_ + __j))); | 
|  | 2651 | } | 
|  | 2652 | size_t __j = _R - __x.__i_; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2653 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2654 | __x.__x_ + __x.__i_)) | 
|  | 2655 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2656 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _R, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2657 | __x.__x_)) | 
|  | 2658 | return false; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2659 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | __x.__x_ + (_R - (__y.__i_ + __j))); | 
|  | 2661 | } | 
|  | 2662 |  | 
|  | 2663 | template<class _UI, size_t _W, size_t _S, size_t _R> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2664 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2665 | bool | 
|  | 2666 | operator!=( | 
|  | 2667 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x, | 
|  | 2668 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __y) | 
|  | 2669 | { | 
|  | 2670 | return !(__x == __y); | 
|  | 2671 | } | 
|  | 2672 |  | 
|  | 2673 | template <class _CharT, class _Traits, | 
|  | 2674 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2675 | basic_ostream<_CharT, _Traits>& | 
|  | 2676 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2677 | const subtract_with_carry_engine<_UI, _W, _S, _R>& __x) | 
|  | 2678 | { | 
|  | 2679 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 2680 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 2681 | _CharT __sp = __os.widen(' '); | 
|  | 2682 | __os.fill(__sp); | 
|  | 2683 | __os << __x.__x_[__x.__i_]; | 
|  | 2684 | for (size_t __j = __x.__i_ + 1; __j < _R; ++__j) | 
|  | 2685 | __os << __sp << __x.__x_[__j]; | 
|  | 2686 | for (size_t __j = 0; __j < __x.__i_; ++__j) | 
|  | 2687 | __os << __sp << __x.__x_[__j]; | 
|  | 2688 | __os << __sp << __x.__c_; | 
|  | 2689 | return __os; | 
|  | 2690 | } | 
|  | 2691 |  | 
|  | 2692 | template <class _CharT, class _Traits, | 
|  | 2693 | class _UI, size_t _W, size_t _S, size_t _R> | 
|  | 2694 | basic_istream<_CharT, _Traits>& | 
|  | 2695 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2696 | subtract_with_carry_engine<_UI, _W, _S, _R>& __x) | 
|  | 2697 | { | 
|  | 2698 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 2699 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 2700 | _UI __t[_R+1]; | 
|  | 2701 | for (size_t __i = 0; __i < _R+1; ++__i) | 
|  | 2702 | __is >> __t[__i]; | 
|  | 2703 | if (!__is.fail()) | 
|  | 2704 | { | 
|  | 2705 | for (size_t __i = 0; __i < _R; ++__i) | 
|  | 2706 | __x.__x_[__i] = __t[__i]; | 
|  | 2707 | __x.__c_ = __t[_R]; | 
|  | 2708 | __x.__i_ = 0; | 
|  | 2709 | } | 
|  | 2710 | return __is; | 
|  | 2711 | } | 
|  | 2712 |  | 
|  | 2713 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base; | 
|  | 2714 | typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base; | 
|  | 2715 |  | 
|  | 2716 | // discard_block_engine | 
|  | 2717 |  | 
|  | 2718 | template<class _Engine, size_t __p, size_t __r> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2719 | class _LIBCPP_VISIBLE discard_block_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | { | 
|  | 2721 | _Engine __e_; | 
|  | 2722 | int     __n_; | 
|  | 2723 |  | 
|  | 2724 | static_assert(  0 <  __r, "discard_block_engine invalid parameters"); | 
|  | 2725 | static_assert(__r <= __p, "discard_block_engine invalid parameters"); | 
|  | 2726 | public: | 
|  | 2727 | // types | 
|  | 2728 | typedef typename _Engine::result_type result_type; | 
|  | 2729 |  | 
|  | 2730 | // engine characteristics | 
|  | 2731 | static const/*expr*/ size_t block_size = __p; | 
|  | 2732 | static const/*expr*/ size_t used_block = __r; | 
|  | 2733 |  | 
|  | 2734 | // Temporary work around for lack of constexpr | 
|  | 2735 | static const result_type _Min = _Engine::_Min; | 
|  | 2736 | static const result_type _Max = _Engine::_Max; | 
|  | 2737 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2738 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2739 | static const/*expr*/ result_type min() { return _Engine::min(); } | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2740 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2741 | static const/*expr*/ result_type max() { return _Engine::max(); } | 
|  | 2742 |  | 
|  | 2743 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2744 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2745 | discard_block_engine() : __n_(0) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2746 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2747 | explicit discard_block_engine(const _Engine& __e) | 
|  | 2748 | : __e_(__e), __n_(0) {} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2749 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2750 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2751 | explicit discard_block_engine(_Engine&& __e) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2752 | : __e_(_VSTD::move(__e)), __n_(0) {} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2753 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2754 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2755 | explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2756 | template<class _Sseq> | 
|  | 2757 | _LIBCPP_INLINE_VISIBILITY | 
|  | 2758 | explicit discard_block_engine(_Sseq& __q, | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2759 | typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2760 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2761 | : __e_(__q), __n_(0) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2762 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | void seed() {__e_.seed(); __n_ = 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2764 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2765 | void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2766 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2767 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2768 | typename enable_if | 
|  | 2769 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2770 | __is_seed_sequence<_Sseq, discard_block_engine>::value, | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2771 | void | 
|  | 2772 | >::type | 
|  | 2773 | seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2774 |  | 
|  | 2775 | // generating functions | 
|  | 2776 | result_type operator()(); | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2777 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2778 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 2779 |  | 
|  | 2780 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2781 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | const _Engine& base() const {return __e_;} | 
|  | 2783 |  | 
|  | 2784 | template<class _Eng, size_t _P, size_t _R> | 
|  | 2785 | friend | 
|  | 2786 | bool | 
|  | 2787 | operator==( | 
|  | 2788 | const discard_block_engine<_Eng, _P, _R>& __x, | 
|  | 2789 | const discard_block_engine<_Eng, _P, _R>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2790 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2791 | template<class _Eng, size_t _P, size_t _R> | 
|  | 2792 | friend | 
|  | 2793 | bool | 
|  | 2794 | operator!=( | 
|  | 2795 | const discard_block_engine<_Eng, _P, _R>& __x, | 
|  | 2796 | const discard_block_engine<_Eng, _P, _R>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2797 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2798 | template <class _CharT, class _Traits, | 
|  | 2799 | class _Eng, size_t _P, size_t _R> | 
|  | 2800 | friend | 
|  | 2801 | basic_ostream<_CharT, _Traits>& | 
|  | 2802 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2803 | const discard_block_engine<_Eng, _P, _R>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2804 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2805 | template <class _CharT, class _Traits, | 
|  | 2806 | class _Eng, size_t _P, size_t _R> | 
|  | 2807 | friend | 
|  | 2808 | basic_istream<_CharT, _Traits>& | 
|  | 2809 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2810 | discard_block_engine<_Eng, _P, _R>& __x); | 
|  | 2811 | }; | 
|  | 2812 |  | 
|  | 2813 | template<class _Engine, size_t __p, size_t __r> | 
|  | 2814 | typename discard_block_engine<_Engine, __p, __r>::result_type | 
|  | 2815 | discard_block_engine<_Engine, __p, __r>::operator()() | 
|  | 2816 | { | 
|  | 2817 | if (__n_ >= __r) | 
|  | 2818 | { | 
|  | 2819 | __e_.discard(__p - __r); | 
|  | 2820 | __n_ = 0; | 
|  | 2821 | } | 
|  | 2822 | ++__n_; | 
|  | 2823 | return __e_(); | 
|  | 2824 | } | 
|  | 2825 |  | 
|  | 2826 | template<class _Eng, size_t _P, size_t _R> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2827 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2828 | bool | 
|  | 2829 | operator==(const discard_block_engine<_Eng, _P, _R>& __x, | 
|  | 2830 | const discard_block_engine<_Eng, _P, _R>& __y) | 
|  | 2831 | { | 
|  | 2832 | return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; | 
|  | 2833 | } | 
|  | 2834 |  | 
|  | 2835 | template<class _Eng, size_t _P, size_t _R> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2836 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2837 | bool | 
|  | 2838 | operator!=(const discard_block_engine<_Eng, _P, _R>& __x, | 
|  | 2839 | const discard_block_engine<_Eng, _P, _R>& __y) | 
|  | 2840 | { | 
|  | 2841 | return !(__x == __y); | 
|  | 2842 | } | 
|  | 2843 |  | 
|  | 2844 | template <class _CharT, class _Traits, | 
|  | 2845 | class _Eng, size_t _P, size_t _R> | 
|  | 2846 | basic_ostream<_CharT, _Traits>& | 
|  | 2847 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 2848 | const discard_block_engine<_Eng, _P, _R>& __x) | 
|  | 2849 | { | 
|  | 2850 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 2851 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 2852 | _CharT __sp = __os.widen(' '); | 
|  | 2853 | __os.fill(__sp); | 
|  | 2854 | return __os << __x.__e_ << __sp << __x.__n_; | 
|  | 2855 | } | 
|  | 2856 |  | 
|  | 2857 | template <class _CharT, class _Traits, | 
|  | 2858 | class _Eng, size_t _P, size_t _R> | 
|  | 2859 | basic_istream<_CharT, _Traits>& | 
|  | 2860 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 2861 | discard_block_engine<_Eng, _P, _R>& __x) | 
|  | 2862 | { | 
|  | 2863 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 2864 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 2865 | _Eng __e; | 
|  | 2866 | int __n; | 
|  | 2867 | __is >> __e >> __n; | 
|  | 2868 | if (!__is.fail()) | 
|  | 2869 | { | 
|  | 2870 | __x.__e_ = __e; | 
|  | 2871 | __x.__n_ = __n; | 
|  | 2872 | } | 
|  | 2873 | return __is; | 
|  | 2874 | } | 
|  | 2875 |  | 
|  | 2876 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; | 
|  | 2877 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; | 
|  | 2878 |  | 
|  | 2879 | // independent_bits_engine | 
|  | 2880 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2881 | template<class _Engine, size_t __w, class _UIntType> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2882 | class _LIBCPP_VISIBLE independent_bits_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2883 | { | 
|  | 2884 | template <class _UI, _UI _R0, size_t _W, size_t _M> | 
|  | 2885 | class __get_n | 
|  | 2886 | { | 
|  | 2887 | static const size_t _Dt = numeric_limits<_UI>::digits; | 
|  | 2888 | static const size_t _N = _W / _M + (_W % _M != 0); | 
|  | 2889 | static const size_t _W0 = _W / _N; | 
|  | 2890 | static const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; | 
|  | 2891 | public: | 
|  | 2892 | static const size_t value = _R0 - _Y0 > _Y0 / _N ? _N + 1 : _N; | 
|  | 2893 | }; | 
|  | 2894 | public: | 
|  | 2895 | // types | 
|  | 2896 | typedef _UIntType result_type; | 
|  | 2897 |  | 
|  | 2898 | private: | 
|  | 2899 | _Engine __e_; | 
|  | 2900 |  | 
|  | 2901 | static const result_type _Dt = numeric_limits<result_type>::digits; | 
|  | 2902 | static_assert(  0 <  __w, "independent_bits_engine invalid parameters"); | 
|  | 2903 | static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); | 
|  | 2904 |  | 
|  | 2905 | typedef typename _Engine::result_type _Engine_result_type; | 
|  | 2906 | typedef typename conditional | 
|  | 2907 | < | 
|  | 2908 | sizeof(_Engine_result_type) <= sizeof(result_type), | 
|  | 2909 | result_type, | 
|  | 2910 | _Engine_result_type | 
|  | 2911 | >::type _Working_result_type; | 
|  | 2912 | // Temporary work around for lack of constexpr | 
|  | 2913 | static const _Working_result_type _R = _Engine::_Max - _Engine::_Min | 
|  | 2914 | + _Working_result_type(1); | 
|  | 2915 | static const size_t __m = __log2<_Working_result_type, _R>::value; | 
|  | 2916 | static const size_t __n = __get_n<_Working_result_type, _R, __w, __m>::value; | 
|  | 2917 | static const size_t __w0 = __w / __n; | 
|  | 2918 | static const size_t __n0 = __n - __w % __n; | 
|  | 2919 | static const size_t _WDt = numeric_limits<_Working_result_type>::digits; | 
|  | 2920 | static const size_t _EDt = numeric_limits<_Engine_result_type>::digits; | 
|  | 2921 | static const _Working_result_type __y0 = __w0 >= _WDt ? 0 : | 
|  | 2922 | (_R >> __w0) << __w0; | 
|  | 2923 | static const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : | 
|  | 2924 | (_R >> (__w0+1)) << (__w0+1); | 
|  | 2925 | static const _Engine_result_type __mask0 = __w0 > 0 ? | 
|  | 2926 | _Engine_result_type(~0) >> (_EDt - __w0) : | 
|  | 2927 | _Engine_result_type(0); | 
|  | 2928 | static const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? | 
|  | 2929 | _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : | 
|  | 2930 | _Engine_result_type(~0); | 
|  | 2931 | public: | 
|  | 2932 | static const result_type _Min = 0; | 
|  | 2933 | static const result_type _Max = __w == _Dt ? result_type(~0) : | 
|  | 2934 | (result_type(1) << __w) - result_type(1); | 
|  | 2935 | static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); | 
|  | 2936 |  | 
|  | 2937 | // engine characteristics | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2938 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2940 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2941 | static const/*expr*/ result_type max() { return _Max; } | 
|  | 2942 |  | 
|  | 2943 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2944 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2945 | independent_bits_engine() {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2946 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2947 | explicit independent_bits_engine(const _Engine& __e) | 
|  | 2948 | : __e_(__e) {} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2949 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2950 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2951 | explicit independent_bits_engine(_Engine&& __e) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2952 | : __e_(_VSTD::move(__e)) {} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2953 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2954 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2955 | explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2956 | template<class _Sseq> explicit independent_bits_engine(_Sseq& __q, | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2957 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2958 | typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2959 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2960 | : __e_(__q) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2961 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2962 | void seed() {__e_.seed();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2963 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2964 | void seed(result_type __sd) {__e_.seed(__sd);} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2965 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2966 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2967 | typename enable_if | 
|  | 2968 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2969 | __is_seed_sequence<_Sseq, independent_bits_engine>::value, | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2970 | void | 
|  | 2971 | >::type | 
|  | 2972 | seed(_Sseq& __q) {__e_.seed(__q);} | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2973 |  | 
|  | 2974 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2975 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2976 | result_type operator()() {return __eval(integral_constant<bool, _R != 0>());} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2977 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2978 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 2979 |  | 
|  | 2980 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2981 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2982 | const _Engine& base() const {return __e_;} | 
|  | 2983 |  | 
|  | 2984 | template<class _Eng, size_t _W, class _UI> | 
|  | 2985 | friend | 
|  | 2986 | bool | 
|  | 2987 | operator==( | 
|  | 2988 | const independent_bits_engine<_Eng, _W, _UI>& __x, | 
|  | 2989 | const independent_bits_engine<_Eng, _W, _UI>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2990 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | template<class _Eng, size_t _W, class _UI> | 
|  | 2992 | friend | 
|  | 2993 | bool | 
|  | 2994 | operator!=( | 
|  | 2995 | const independent_bits_engine<_Eng, _W, _UI>& __x, | 
|  | 2996 | const independent_bits_engine<_Eng, _W, _UI>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2997 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2998 | template <class _CharT, class _Traits, | 
|  | 2999 | class _Eng, size_t _W, class _UI> | 
|  | 3000 | friend | 
|  | 3001 | basic_ostream<_CharT, _Traits>& | 
|  | 3002 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3003 | const independent_bits_engine<_Eng, _W, _UI>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3004 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3005 | template <class _CharT, class _Traits, | 
|  | 3006 | class _Eng, size_t _W, class _UI> | 
|  | 3007 | friend | 
|  | 3008 | basic_istream<_CharT, _Traits>& | 
|  | 3009 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3010 | independent_bits_engine<_Eng, _W, _UI>& __x); | 
|  | 3011 |  | 
|  | 3012 | private: | 
|  | 3013 | result_type __eval(false_type); | 
|  | 3014 | result_type __eval(true_type); | 
|  | 3015 |  | 
|  | 3016 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3017 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3018 | static | 
|  | 3019 | typename enable_if | 
|  | 3020 | < | 
|  | 3021 | __count < _Dt, | 
|  | 3022 | result_type | 
|  | 3023 | >::type | 
|  | 3024 | __lshift(result_type __x) {return __x << __count;} | 
|  | 3025 |  | 
|  | 3026 | template <size_t __count> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3027 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | static | 
|  | 3029 | typename enable_if | 
|  | 3030 | < | 
|  | 3031 | (__count >= _Dt), | 
|  | 3032 | result_type | 
|  | 3033 | >::type | 
|  | 3034 | __lshift(result_type __x) {return result_type(0);} | 
|  | 3035 | }; | 
|  | 3036 |  | 
|  | 3037 | template<class _Engine, size_t __w, class _UIntType> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3038 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3039 | _UIntType | 
|  | 3040 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) | 
|  | 3041 | { | 
|  | 3042 | return static_cast<result_type>(__e_() & __mask0); | 
|  | 3043 | } | 
|  | 3044 |  | 
|  | 3045 | template<class _Engine, size_t __w, class _UIntType> | 
|  | 3046 | _UIntType | 
|  | 3047 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) | 
|  | 3048 | { | 
|  | 3049 | result_type _S = 0; | 
|  | 3050 | for (size_t __k = 0; __k < __n0; ++__k) | 
|  | 3051 | { | 
|  | 3052 | _Engine_result_type __u; | 
|  | 3053 | do | 
|  | 3054 | { | 
|  | 3055 | __u = __e_() - _Engine::min(); | 
|  | 3056 | } while (__u >= __y0); | 
|  | 3057 | _S = static_cast<result_type>(__lshift<__w0>(_S) + (__u & __mask0)); | 
|  | 3058 | } | 
|  | 3059 | for (size_t __k = __n0; __k < __n; ++__k) | 
|  | 3060 | { | 
|  | 3061 | _Engine_result_type __u; | 
|  | 3062 | do | 
|  | 3063 | { | 
|  | 3064 | __u = __e_() - _Engine::min(); | 
|  | 3065 | } while (__u >= __y1); | 
|  | 3066 | _S = static_cast<result_type>(__lshift<__w0+1>(_S) + (__u & __mask1)); | 
|  | 3067 | } | 
|  | 3068 | return _S; | 
|  | 3069 | } | 
|  | 3070 |  | 
|  | 3071 | template<class _Eng, size_t _W, class _UI> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3072 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3073 | bool | 
|  | 3074 | operator==( | 
|  | 3075 | const independent_bits_engine<_Eng, _W, _UI>& __x, | 
|  | 3076 | const independent_bits_engine<_Eng, _W, _UI>& __y) | 
|  | 3077 | { | 
|  | 3078 | return __x.base() == __y.base(); | 
|  | 3079 | } | 
|  | 3080 |  | 
|  | 3081 | template<class _Eng, size_t _W, class _UI> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3082 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3083 | bool | 
|  | 3084 | operator!=( | 
|  | 3085 | const independent_bits_engine<_Eng, _W, _UI>& __x, | 
|  | 3086 | const independent_bits_engine<_Eng, _W, _UI>& __y) | 
|  | 3087 | { | 
|  | 3088 | return !(__x == __y); | 
|  | 3089 | } | 
|  | 3090 |  | 
|  | 3091 | template <class _CharT, class _Traits, | 
|  | 3092 | class _Eng, size_t _W, class _UI> | 
|  | 3093 | basic_ostream<_CharT, _Traits>& | 
|  | 3094 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3095 | const independent_bits_engine<_Eng, _W, _UI>& __x) | 
|  | 3096 | { | 
|  | 3097 | return __os << __x.base(); | 
|  | 3098 | } | 
|  | 3099 |  | 
|  | 3100 | template <class _CharT, class _Traits, | 
|  | 3101 | class _Eng, size_t _W, class _UI> | 
|  | 3102 | basic_istream<_CharT, _Traits>& | 
|  | 3103 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3104 | independent_bits_engine<_Eng, _W, _UI>& __x) | 
|  | 3105 | { | 
|  | 3106 | _Eng __e; | 
|  | 3107 | __is >> __e; | 
|  | 3108 | if (!__is.fail()) | 
|  | 3109 | __x.__e_ = __e; | 
|  | 3110 | return __is; | 
|  | 3111 | } | 
|  | 3112 |  | 
|  | 3113 | // shuffle_order_engine | 
|  | 3114 |  | 
|  | 3115 | template <uint64_t _Xp, uint64_t _Yp> | 
|  | 3116 | struct __ugcd | 
|  | 3117 | { | 
|  | 3118 | static const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; | 
|  | 3119 | }; | 
|  | 3120 |  | 
|  | 3121 | template <uint64_t _Xp> | 
|  | 3122 | struct __ugcd<_Xp, 0> | 
|  | 3123 | { | 
|  | 3124 | static const uint64_t value = _Xp; | 
|  | 3125 | }; | 
|  | 3126 |  | 
|  | 3127 | template <uint64_t _N, uint64_t _D> | 
|  | 3128 | class __uratio | 
|  | 3129 | { | 
|  | 3130 | static_assert(_D != 0, "__uratio divide by 0"); | 
|  | 3131 | static const uint64_t __gcd = __ugcd<_N, _D>::value; | 
|  | 3132 | public: | 
|  | 3133 | static const uint64_t num = _N / __gcd; | 
|  | 3134 | static const uint64_t den = _D / __gcd; | 
|  | 3135 |  | 
|  | 3136 | typedef __uratio<num, den> type; | 
|  | 3137 | }; | 
|  | 3138 |  | 
|  | 3139 | template<class _Engine, size_t __k> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3140 | class _LIBCPP_VISIBLE shuffle_order_engine | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3141 | { | 
|  | 3142 | static_assert(0 < __k, "shuffle_order_engine invalid parameters"); | 
|  | 3143 | public: | 
|  | 3144 | // types | 
|  | 3145 | typedef typename _Engine::result_type result_type; | 
|  | 3146 |  | 
|  | 3147 | private: | 
|  | 3148 | _Engine __e_; | 
|  | 3149 | result_type _V_[__k]; | 
|  | 3150 | result_type _Y_; | 
|  | 3151 |  | 
|  | 3152 | public: | 
|  | 3153 | // engine characteristics | 
|  | 3154 | static const/*expr*/ size_t table_size = __k; | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3155 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3156 | static const result_type _Min = _Engine::_Min; | 
|  | 3157 | static const result_type _Max = _Engine::_Max; | 
|  | 3158 | static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3159 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3160 | static const/*expr*/ result_type min() { return _Min; } | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3161 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | static const/*expr*/ result_type max() { return _Max; } | 
|  | 3163 |  | 
|  | 3164 | static const unsigned long long _R = _Max - _Min + 1ull; | 
|  | 3165 |  | 
|  | 3166 | // constructors and seeding functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3167 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | shuffle_order_engine() {__init();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3169 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3170 | explicit shuffle_order_engine(const _Engine& __e) | 
|  | 3171 | : __e_(__e) {__init();} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3172 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3173 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3174 | explicit shuffle_order_engine(_Engine&& __e) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3175 | : __e_(_VSTD::move(__e)) {__init();} | 
| Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3176 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3177 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3179 | template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q, | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3180 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3181 | typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3182 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3183 | : __e_(__q) {__init();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3184 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3185 | void seed() {__e_.seed(); __init();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3186 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | void seed(result_type __sd) {__e_.seed(__sd); __init();} | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3188 | template<class _Sseq> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3189 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3190 | typename enable_if | 
|  | 3191 | < | 
| Howard Hinnant | a23551c | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3192 | __is_seed_sequence<_Sseq, shuffle_order_engine>::value, | 
| Howard Hinnant | 03ec83e | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3193 | void | 
|  | 3194 | >::type | 
|  | 3195 | seed(_Sseq& __q) {__e_.seed(__q); __init();} | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3196 |  | 
|  | 3197 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3198 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3199 | result_type operator()() {return __eval(integral_constant<bool, _R != 0>());} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3200 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3201 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} | 
|  | 3202 |  | 
|  | 3203 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3204 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3205 | const _Engine& base() const {return __e_;} | 
|  | 3206 |  | 
|  | 3207 | private: | 
|  | 3208 | template<class _Eng, size_t _K> | 
|  | 3209 | friend | 
|  | 3210 | bool | 
|  | 3211 | operator==( | 
|  | 3212 | const shuffle_order_engine<_Eng, _K>& __x, | 
|  | 3213 | const shuffle_order_engine<_Eng, _K>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3214 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3215 | template<class _Eng, size_t _K> | 
|  | 3216 | friend | 
|  | 3217 | bool | 
|  | 3218 | operator!=( | 
|  | 3219 | const shuffle_order_engine<_Eng, _K>& __x, | 
|  | 3220 | const shuffle_order_engine<_Eng, _K>& __y); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3221 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3222 | template <class _CharT, class _Traits, | 
|  | 3223 | class _Eng, size_t _K> | 
|  | 3224 | friend | 
|  | 3225 | basic_ostream<_CharT, _Traits>& | 
|  | 3226 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3227 | const shuffle_order_engine<_Eng, _K>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3228 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3229 | template <class _CharT, class _Traits, | 
|  | 3230 | class _Eng, size_t _K> | 
|  | 3231 | friend | 
|  | 3232 | basic_istream<_CharT, _Traits>& | 
|  | 3233 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3234 | shuffle_order_engine<_Eng, _K>& __x); | 
|  | 3235 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3236 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | void __init() | 
|  | 3238 | { | 
|  | 3239 | for (size_t __i = 0; __i < __k; ++__i) | 
|  | 3240 | _V_[__i] = __e_(); | 
|  | 3241 | _Y_ = __e_(); | 
|  | 3242 | } | 
|  | 3243 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3244 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3245 | result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3246 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3247 | result_type __eval(true_type) {return __eval(__uratio<__k, _R>());} | 
|  | 3248 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3249 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3250 | result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3251 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3252 | result_type __eval2(true_type) {return __evalf<__k, 0>();} | 
|  | 3253 |  | 
|  | 3254 | template <uint64_t _N, uint64_t _D> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3255 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3256 | typename enable_if | 
|  | 3257 | < | 
|  | 3258 | (__uratio<_N, _D>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), | 
|  | 3259 | result_type | 
|  | 3260 | >::type | 
|  | 3261 | __eval(__uratio<_N, _D>) | 
|  | 3262 | {return __evalf<__uratio<_N, _D>::num, __uratio<_N, _D>::den>();} | 
|  | 3263 |  | 
|  | 3264 | template <uint64_t _N, uint64_t _D> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3265 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3266 | typename enable_if | 
|  | 3267 | < | 
|  | 3268 | __uratio<_N, _D>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), | 
|  | 3269 | result_type | 
|  | 3270 | >::type | 
|  | 3271 | __eval(__uratio<_N, _D>) | 
|  | 3272 | { | 
|  | 3273 | const size_t __j = static_cast<size_t>(__uratio<_N, _D>::num * (_Y_ - _Min) | 
|  | 3274 | / __uratio<_N, _D>::den); | 
|  | 3275 | _Y_ = _V_[__j]; | 
|  | 3276 | _V_[__j] = __e_(); | 
|  | 3277 | return _Y_; | 
|  | 3278 | } | 
|  | 3279 |  | 
|  | 3280 | template <uint64_t __n, uint64_t __d> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3281 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3282 | result_type __evalf() | 
|  | 3283 | { | 
|  | 3284 | const double _F = __d == 0 ? | 
|  | 3285 | __n / (2. * 0x8000000000000000ull) : | 
|  | 3286 | __n / (double)__d; | 
|  | 3287 | const size_t __j = static_cast<size_t>(_F * (_Y_ - _Min)); | 
|  | 3288 | _Y_ = _V_[__j]; | 
|  | 3289 | _V_[__j] = __e_(); | 
|  | 3290 | return _Y_; | 
|  | 3291 | } | 
|  | 3292 | }; | 
|  | 3293 |  | 
|  | 3294 | template<class _Eng, size_t _K> | 
|  | 3295 | bool | 
|  | 3296 | operator==( | 
|  | 3297 | const shuffle_order_engine<_Eng, _K>& __x, | 
|  | 3298 | const shuffle_order_engine<_Eng, _K>& __y) | 
|  | 3299 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3300 | return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _K, __y._V_) && | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3301 | __x.__e_ == __y.__e_; | 
|  | 3302 | } | 
|  | 3303 |  | 
|  | 3304 | template<class _Eng, size_t _K> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3305 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3306 | bool | 
|  | 3307 | operator!=( | 
|  | 3308 | const shuffle_order_engine<_Eng, _K>& __x, | 
|  | 3309 | const shuffle_order_engine<_Eng, _K>& __y) | 
|  | 3310 | { | 
|  | 3311 | return !(__x == __y); | 
|  | 3312 | } | 
|  | 3313 |  | 
|  | 3314 | template <class _CharT, class _Traits, | 
|  | 3315 | class _Eng, size_t _K> | 
|  | 3316 | basic_ostream<_CharT, _Traits>& | 
|  | 3317 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3318 | const shuffle_order_engine<_Eng, _K>& __x) | 
|  | 3319 | { | 
|  | 3320 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 3321 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 3322 | _CharT __sp = __os.widen(' '); | 
|  | 3323 | __os.fill(__sp); | 
|  | 3324 | __os << __x.__e_ << __sp << __x._V_[0]; | 
|  | 3325 | for (size_t __i = 1; __i < _K; ++__i) | 
|  | 3326 | __os << __sp << __x._V_[__i]; | 
|  | 3327 | return __os << __sp << __x._Y_; | 
|  | 3328 | } | 
|  | 3329 |  | 
|  | 3330 | template <class _CharT, class _Traits, | 
|  | 3331 | class _Eng, size_t _K> | 
|  | 3332 | basic_istream<_CharT, _Traits>& | 
|  | 3333 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3334 | shuffle_order_engine<_Eng, _K>& __x) | 
|  | 3335 | { | 
|  | 3336 | typedef typename shuffle_order_engine<_Eng, _K>::result_type result_type; | 
|  | 3337 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 3338 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 3339 | _Eng __e; | 
|  | 3340 | result_type _V[_K+1]; | 
|  | 3341 | __is >> __e; | 
|  | 3342 | for (size_t __i = 0; __i < _K+1; ++__i) | 
|  | 3343 | __is >> _V[__i]; | 
|  | 3344 | if (!__is.fail()) | 
|  | 3345 | { | 
|  | 3346 | __x.__e_ = __e; | 
|  | 3347 | for (size_t __i = 0; __i < _K; ++__i) | 
|  | 3348 | __x._V_[__i] = _V[__i]; | 
|  | 3349 | __x._Y_ = _V[_K]; | 
|  | 3350 | } | 
|  | 3351 | return __is; | 
|  | 3352 | } | 
|  | 3353 |  | 
|  | 3354 | typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b; | 
|  | 3355 |  | 
|  | 3356 | // random_device | 
|  | 3357 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3358 | class _LIBCPP_VISIBLE random_device | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3359 | { | 
|  | 3360 | int __f_; | 
|  | 3361 | public: | 
|  | 3362 | // types | 
|  | 3363 | typedef unsigned result_type; | 
|  | 3364 |  | 
|  | 3365 | // generator characteristics | 
|  | 3366 | static const result_type _Min = 0; | 
|  | 3367 | static const result_type _Max = 0xFFFFFFFFu; | 
|  | 3368 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3369 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3370 | static const/*expr*/ result_type min() { return _Min;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3371 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3372 | static const/*expr*/ result_type max() { return _Max;} | 
|  | 3373 |  | 
|  | 3374 | // constructors | 
|  | 3375 | explicit random_device(const string& __token = "/dev/urandom"); | 
|  | 3376 | ~random_device(); | 
|  | 3377 |  | 
|  | 3378 | // generating functions | 
|  | 3379 | result_type operator()(); | 
|  | 3380 |  | 
|  | 3381 | // property functions | 
|  | 3382 | double entropy() const; | 
|  | 3383 |  | 
|  | 3384 | private: | 
|  | 3385 | // no copy functions | 
|  | 3386 | random_device(const random_device&); // = delete; | 
|  | 3387 | random_device& operator=(const random_device&); // = delete; | 
|  | 3388 | }; | 
|  | 3389 |  | 
|  | 3390 | // seed_seq | 
|  | 3391 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3392 | class _LIBCPP_VISIBLE seed_seq | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3393 | { | 
|  | 3394 | public: | 
|  | 3395 | // types | 
|  | 3396 | typedef uint32_t result_type; | 
|  | 3397 |  | 
|  | 3398 | private: | 
|  | 3399 | vector<result_type> __v_; | 
|  | 3400 |  | 
|  | 3401 | template<class _InputIterator> | 
|  | 3402 | void init(_InputIterator __first, _InputIterator __last); | 
|  | 3403 | public: | 
|  | 3404 | // constructors | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3405 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3406 | seed_seq() {} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 3407 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 | template<class _Tp> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3409 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3410 | seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 3411 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3412 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3413 | template<class _InputIterator> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3414 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3415 | seed_seq(_InputIterator __first, _InputIterator __last) | 
|  | 3416 | {init(__first, __last);} | 
|  | 3417 |  | 
|  | 3418 | // generating functions | 
|  | 3419 | template<class _RandomAccessIterator> | 
|  | 3420 | void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); | 
|  | 3421 |  | 
|  | 3422 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3423 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3424 | size_t size() const {return __v_.size();} | 
|  | 3425 | template<class _OutputIterator> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3426 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3427 | void param(_OutputIterator __dest) const | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3428 | {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3429 |  | 
|  | 3430 | private: | 
|  | 3431 | // no copy functions | 
|  | 3432 | seed_seq(const seed_seq&); // = delete; | 
|  | 3433 | void operator=(const seed_seq&); // = delete; | 
|  | 3434 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3435 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3436 | static result_type _T(result_type __x) {return __x ^ (__x >> 27);} | 
|  | 3437 | }; | 
|  | 3438 |  | 
|  | 3439 | template<class _InputIterator> | 
|  | 3440 | void | 
|  | 3441 | seed_seq::init(_InputIterator __first, _InputIterator __last) | 
|  | 3442 | { | 
|  | 3443 | for (_InputIterator __s = __first; __s != __last; ++__s) | 
|  | 3444 | __v_.push_back(*__s & 0xFFFFFFFF); | 
|  | 3445 | } | 
|  | 3446 |  | 
|  | 3447 | template<class _RandomAccessIterator> | 
|  | 3448 | void | 
|  | 3449 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) | 
|  | 3450 | { | 
|  | 3451 | if (__first != __last) | 
|  | 3452 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3453 | _VSTD::fill(__first, __last, 0x8b8b8b8b); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3454 | const size_t __n = static_cast<size_t>(__last - __first); | 
|  | 3455 | const size_t __s = __v_.size(); | 
|  | 3456 | const size_t __t = (__n >= 623) ? 11 | 
|  | 3457 | : (__n >= 68) ? 7 | 
|  | 3458 | : (__n >= 39) ? 5 | 
|  | 3459 | : (__n >= 7)  ? 3 | 
|  | 3460 | : (__n - 1) / 2; | 
|  | 3461 | const size_t __p = (__n - __t) / 2; | 
|  | 3462 | const size_t __q = __p + __t; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3463 | const size_t __m = _VSTD::max(__s + 1, __n); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3464 | // __k = 0; | 
|  | 3465 | { | 
|  | 3466 | result_type __r = 1664525 * _T(__first[0] ^ __first[__p] | 
|  | 3467 | ^  __first[__n - 1]); | 
|  | 3468 | __first[__p] += __r; | 
|  | 3469 | __r += __s; | 
|  | 3470 | __first[__q] += __r; | 
|  | 3471 | __first[0] = __r; | 
|  | 3472 | } | 
|  | 3473 | for (size_t __k = 1; __k <= __s; ++__k) | 
|  | 3474 | { | 
|  | 3475 | const size_t __kmodn = __k % __n; | 
|  | 3476 | const size_t __kpmodn = (__k + __p) % __n; | 
|  | 3477 | result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn] | 
|  | 3478 | ^ __first[(__k - 1) % __n]); | 
|  | 3479 | __first[__kpmodn] += __r; | 
|  | 3480 | __r +=  __kmodn + __v_[__k-1]; | 
|  | 3481 | __first[(__k + __q) % __n] += __r; | 
|  | 3482 | __first[__kmodn] = __r; | 
|  | 3483 | } | 
|  | 3484 | for (size_t __k = __s + 1; __k < __m; ++__k) | 
|  | 3485 | { | 
|  | 3486 | const size_t __kmodn = __k % __n; | 
|  | 3487 | const size_t __kpmodn = (__k + __p) % __n; | 
|  | 3488 | result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn] | 
|  | 3489 | ^ __first[(__k - 1) % __n]); | 
|  | 3490 | __first[__kpmodn] += __r; | 
|  | 3491 | __r +=  __kmodn; | 
|  | 3492 | __first[(__k + __q) % __n] += __r; | 
|  | 3493 | __first[__kmodn] = __r; | 
|  | 3494 | } | 
|  | 3495 | for (size_t __k = __m; __k < __m + __n; ++__k) | 
|  | 3496 | { | 
|  | 3497 | const size_t __kmodn = __k % __n; | 
|  | 3498 | const size_t __kpmodn = (__k + __p) % __n; | 
|  | 3499 | result_type __r = 1566083941 * _T(__first[__kmodn] + | 
|  | 3500 | __first[__kpmodn] + | 
|  | 3501 | __first[(__k - 1) % __n]); | 
|  | 3502 | __first[__kpmodn] ^= __r; | 
|  | 3503 | __r -= __kmodn; | 
|  | 3504 | __first[(__k + __q) % __n] ^= __r; | 
|  | 3505 | __first[__kmodn] = __r; | 
|  | 3506 | } | 
|  | 3507 | } | 
|  | 3508 | } | 
|  | 3509 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3510 | // generate_canonical | 
|  | 3511 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3512 | template<class _RealType, size_t __bits, class _URNG> | 
|  | 3513 | _RealType | 
|  | 3514 | generate_canonical(_URNG& __g) | 
|  | 3515 | { | 
|  | 3516 | const size_t _Dt = numeric_limits<_RealType>::digits; | 
|  | 3517 | const size_t __b = _Dt < __bits ? _Dt : __bits; | 
|  | 3518 | const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; | 
|  | 3519 | const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); | 
|  | 3520 | const _RealType _R = _URNG::_Max - _URNG::_Min + _RealType(1); | 
|  | 3521 | _RealType __base = _R; | 
|  | 3522 | _RealType _S = __g() - _URNG::_Min; | 
|  | 3523 | for (size_t __i = 1; __i < __k; ++__i, __base *= _R) | 
|  | 3524 | _S += (__g() - _URNG::_Min) * __base; | 
|  | 3525 | return _S / __base; | 
|  | 3526 | } | 
|  | 3527 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3528 | // uniform_int_distribution | 
|  | 3529 |  | 
| Howard Hinnant | f9d540b | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3530 | // in <algorithm> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3531 |  | 
|  | 3532 | template <class _CharT, class _Traits, class _IT> | 
|  | 3533 | basic_ostream<_CharT, _Traits>& | 
|  | 3534 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3535 | const uniform_int_distribution<_IT>& __x) | 
|  | 3536 | { | 
|  | 3537 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 3538 | __os.flags(ios_base::dec | ios_base::left); | 
|  | 3539 | _CharT __sp = __os.widen(' '); | 
|  | 3540 | __os.fill(__sp); | 
|  | 3541 | return __os << __x.a() << __sp << __x.b(); | 
|  | 3542 | } | 
|  | 3543 |  | 
|  | 3544 | template <class _CharT, class _Traits, class _IT> | 
|  | 3545 | basic_istream<_CharT, _Traits>& | 
|  | 3546 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3547 | uniform_int_distribution<_IT>& __x) | 
|  | 3548 | { | 
|  | 3549 | typedef uniform_int_distribution<_IT> _Eng; | 
|  | 3550 | typedef typename _Eng::result_type result_type; | 
|  | 3551 | typedef typename _Eng::param_type param_type; | 
|  | 3552 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 3553 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 3554 | result_type __a; | 
|  | 3555 | result_type __b; | 
|  | 3556 | __is >> __a >> __b; | 
|  | 3557 | if (!__is.fail()) | 
|  | 3558 | __x.param(param_type(__a, __b)); | 
|  | 3559 | return __is; | 
|  | 3560 | } | 
|  | 3561 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3562 | // uniform_real_distribution | 
|  | 3563 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3565 | class _LIBCPP_VISIBLE uniform_real_distribution | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3566 | { | 
|  | 3567 | public: | 
|  | 3568 | // types | 
|  | 3569 | typedef _RealType result_type; | 
|  | 3570 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3571 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3572 | { | 
|  | 3573 | result_type __a_; | 
|  | 3574 | result_type __b_; | 
|  | 3575 | public: | 
|  | 3576 | typedef uniform_real_distribution distribution_type; | 
|  | 3577 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3578 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | explicit param_type(result_type __a = 0, | 
|  | 3580 | result_type __b = 1) | 
|  | 3581 | : __a_(__a), __b_(__b) {} | 
|  | 3582 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3583 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3584 | result_type a() const {return __a_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3585 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3586 | result_type b() const {return __b_;} | 
|  | 3587 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3588 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3589 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3591 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3592 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3593 | {return !(__x == __y);} | 
|  | 3594 | }; | 
|  | 3595 |  | 
|  | 3596 | private: | 
|  | 3597 | param_type __p_; | 
|  | 3598 |  | 
|  | 3599 | public: | 
|  | 3600 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3601 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3602 | explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) | 
|  | 3603 | : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3604 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3606 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3607 | void reset() {} | 
|  | 3608 |  | 
|  | 3609 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3610 | template<class _URNG> | 
|  | 3611 | _LIBCPP_INLINE_VISIBILITY | 
|  | 3612 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3613 | {return (*this)(__g, __p_);} | 
|  | 3614 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 3615 |  | 
|  | 3616 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3617 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 | result_type a() const {return __p_.a();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3619 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3620 | result_type b() const {return __p_.b();} | 
|  | 3621 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3622 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3623 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3624 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 3626 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3627 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3628 | result_type min() const {return a();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3629 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3630 | result_type max() const {return b();} | 
|  | 3631 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3632 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3633 | bool operator==(const uniform_real_distribution& __x, | 
|  | 3634 | const uniform_real_distribution& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3635 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3636 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3637 | bool operator!=(const uniform_real_distribution& __x, | 
|  | 3638 | const uniform_real_distribution& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3639 | {return !(__x == __y);} | 
|  | 3640 | }; | 
|  | 3641 |  | 
|  | 3642 | template<class _RealType> | 
|  | 3643 | template<class _URNG> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3644 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3645 | typename uniform_real_distribution<_RealType>::result_type | 
|  | 3646 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 3647 | { | 
|  | 3648 | return (__p.b() - __p.a()) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3649 | * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3650 | + __p.a(); | 
|  | 3651 | } | 
|  | 3652 |  | 
|  | 3653 | template <class _CharT, class _Traits, class _RT> | 
|  | 3654 | basic_ostream<_CharT, _Traits>& | 
|  | 3655 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3656 | const uniform_real_distribution<_RT>& __x) | 
|  | 3657 | { | 
|  | 3658 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3659 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 3660 | ios_base::scientific); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3661 | _CharT __sp = __os.widen(' '); | 
|  | 3662 | __os.fill(__sp); | 
|  | 3663 | return __os << __x.a() << __sp << __x.b(); | 
|  | 3664 | } | 
|  | 3665 |  | 
|  | 3666 | template <class _CharT, class _Traits, class _RT> | 
|  | 3667 | basic_istream<_CharT, _Traits>& | 
|  | 3668 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3669 | uniform_real_distribution<_RT>& __x) | 
|  | 3670 | { | 
|  | 3671 | typedef uniform_real_distribution<_RT> _Eng; | 
|  | 3672 | typedef typename _Eng::result_type result_type; | 
|  | 3673 | typedef typename _Eng::param_type param_type; | 
|  | 3674 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 3675 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 3676 | result_type __a; | 
|  | 3677 | result_type __b; | 
|  | 3678 | __is >> __a >> __b; | 
|  | 3679 | if (!__is.fail()) | 
|  | 3680 | __x.param(param_type(__a, __b)); | 
|  | 3681 | return __is; | 
|  | 3682 | } | 
|  | 3683 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3684 | // bernoulli_distribution | 
|  | 3685 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3686 | class _LIBCPP_VISIBLE bernoulli_distribution | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3687 | { | 
|  | 3688 | public: | 
|  | 3689 | // types | 
|  | 3690 | typedef bool result_type; | 
|  | 3691 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3692 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3693 | { | 
|  | 3694 | double __p_; | 
|  | 3695 | public: | 
|  | 3696 | typedef bernoulli_distribution distribution_type; | 
|  | 3697 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3698 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3699 | explicit param_type(double __p = 0.5) : __p_(__p) {} | 
|  | 3700 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3701 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3702 | double p() const {return __p_;} | 
|  | 3703 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3704 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3705 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3706 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3707 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3708 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3709 | {return !(__x == __y);} | 
|  | 3710 | }; | 
|  | 3711 |  | 
|  | 3712 | private: | 
|  | 3713 | param_type __p_; | 
|  | 3714 |  | 
|  | 3715 | public: | 
|  | 3716 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3717 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3718 | explicit bernoulli_distribution(double __p = 0.5) | 
|  | 3719 | : __p_(param_type(__p)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3720 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3721 | explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3722 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3723 | void reset() {} | 
|  | 3724 |  | 
|  | 3725 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3726 | template<class _URNG> | 
|  | 3727 | _LIBCPP_INLINE_VISIBILITY | 
|  | 3728 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3729 | {return (*this)(__g, __p_);} | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3730 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3731 |  | 
|  | 3732 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3733 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | double p() const {return __p_.p();} | 
|  | 3735 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3736 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3737 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3738 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3739 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 3740 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3741 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3742 | result_type min() const {return false;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3743 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | result_type max() const {return true;} | 
|  | 3745 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3746 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3747 | bool operator==(const bernoulli_distribution& __x, | 
|  | 3748 | const bernoulli_distribution& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3749 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3750 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3751 | bool operator!=(const bernoulli_distribution& __x, | 
|  | 3752 | const bernoulli_distribution& __y) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3753 | {return !(__x == __y);} | 
|  | 3754 | }; | 
|  | 3755 |  | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3756 | template<class _URNG> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3757 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3758 | bernoulli_distribution::result_type | 
|  | 3759 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) | 
|  | 3760 | { | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 3761 | uniform_real_distribution<double> __gen; | 
|  | 3762 | return __gen(__g) < __p.p(); | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3763 | } | 
|  | 3764 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3765 | template <class _CharT, class _Traits> | 
|  | 3766 | basic_ostream<_CharT, _Traits>& | 
|  | 3767 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) | 
|  | 3768 | { | 
|  | 3769 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3770 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 3771 | ios_base::scientific); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3772 | _CharT __sp = __os.widen(' '); | 
|  | 3773 | __os.fill(__sp); | 
|  | 3774 | return __os << __x.p(); | 
|  | 3775 | } | 
|  | 3776 |  | 
|  | 3777 | template <class _CharT, class _Traits> | 
|  | 3778 | basic_istream<_CharT, _Traits>& | 
|  | 3779 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) | 
|  | 3780 | { | 
|  | 3781 | typedef bernoulli_distribution _Eng; | 
|  | 3782 | typedef typename _Eng::param_type param_type; | 
|  | 3783 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 3784 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 3785 | double __p; | 
|  | 3786 | __is >> __p; | 
|  | 3787 | if (!__is.fail()) | 
|  | 3788 | __x.param(param_type(__p)); | 
|  | 3789 | return __is; | 
|  | 3790 | } | 
|  | 3791 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3792 | // binomial_distribution | 
|  | 3793 |  | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3794 | template<class _IntType = int> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3795 | class _LIBCPP_VISIBLE binomial_distribution | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3796 | { | 
|  | 3797 | public: | 
|  | 3798 | // types | 
|  | 3799 | typedef _IntType result_type; | 
|  | 3800 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3801 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3802 | { | 
|  | 3803 | result_type __t_; | 
|  | 3804 | double __p_; | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3805 | double __pr_; | 
|  | 3806 | double __odds_ratio_; | 
|  | 3807 | result_type __r0_; | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3808 | public: | 
|  | 3809 | typedef binomial_distribution distribution_type; | 
|  | 3810 |  | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3811 | explicit param_type(result_type __t = 1, double __p = 0.5); | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3812 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3813 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3814 | result_type t() const {return __t_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3815 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3816 | double p() const {return __p_;} | 
|  | 3817 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3818 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3819 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3820 | {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3821 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3822 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3823 | {return !(__x == __y);} | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3824 |  | 
|  | 3825 | friend class binomial_distribution; | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3826 | }; | 
|  | 3827 |  | 
|  | 3828 | private: | 
|  | 3829 | param_type __p_; | 
|  | 3830 |  | 
|  | 3831 | public: | 
|  | 3832 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3833 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3834 | explicit binomial_distribution(result_type __t = 1, double __p = 0.5) | 
|  | 3835 | : __p_(param_type(__t, __p)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3836 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3837 | explicit binomial_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3838 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3839 | void reset() {} | 
|  | 3840 |  | 
|  | 3841 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3842 | template<class _URNG> | 
|  | 3843 | _LIBCPP_INLINE_VISIBILITY | 
|  | 3844 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3845 | {return (*this)(__g, __p_);} | 
|  | 3846 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 3847 |  | 
|  | 3848 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3849 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3850 | result_type t() const {return __p_.t();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3851 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3852 | double p() const {return __p_.p();} | 
|  | 3853 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3854 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3855 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3856 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3857 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 3858 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3859 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3860 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3861 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3862 | result_type max() const {return t();} | 
|  | 3863 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3864 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3865 | bool operator==(const binomial_distribution& __x, | 
|  | 3866 | const binomial_distribution& __y) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3867 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3868 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3869 | bool operator!=(const binomial_distribution& __x, | 
|  | 3870 | const binomial_distribution& __y) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3871 | {return !(__x == __y);} | 
|  | 3872 | }; | 
|  | 3873 |  | 
|  | 3874 | template<class _IntType> | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3875 | binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) | 
|  | 3876 | : __t_(__t), __p_(__p) | 
|  | 3877 | { | 
|  | 3878 | if (0 < __p_ && __p_ < 1) | 
|  | 3879 | { | 
|  | 3880 | __r0_ = static_cast<result_type>((__t_ + 1) * __p_); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3881 | __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) - | 
|  | 3882 | _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + | 
|  | 3883 | (__t_ - __r0_) * _VSTD::log(1 - __p_)); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3884 | __odds_ratio_ = __p_ / (1 - __p_); | 
|  | 3885 | } | 
|  | 3886 | } | 
|  | 3887 |  | 
|  | 3888 | template<class _IntType> | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3889 | template<class _URNG> | 
|  | 3890 | _IntType | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3891 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3892 | { | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3893 | if (__pr.__t_ == 0 || __pr.__p_ == 0) | 
|  | 3894 | return 0; | 
|  | 3895 | if (__pr.__p_ == 1) | 
|  | 3896 | return __pr.__t_; | 
|  | 3897 | uniform_real_distribution<double> __gen; | 
|  | 3898 | double __u = __gen(__g) - __pr.__pr_; | 
|  | 3899 | if (__u < 0) | 
|  | 3900 | return __pr.__r0_; | 
|  | 3901 | double __pu = __pr.__pr_; | 
|  | 3902 | double __pd = __pu; | 
|  | 3903 | result_type __ru = __pr.__r0_; | 
|  | 3904 | result_type __rd = __ru; | 
|  | 3905 | while (true) | 
|  | 3906 | { | 
|  | 3907 | if (__rd >= 1) | 
|  | 3908 | { | 
|  | 3909 | __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); | 
|  | 3910 | __u -= __pd; | 
|  | 3911 | if (__u < 0) | 
|  | 3912 | return __rd - 1; | 
|  | 3913 | } | 
|  | 3914 | --__rd; | 
|  | 3915 | ++__ru; | 
|  | 3916 | if (__ru <= __pr.__t_) | 
|  | 3917 | { | 
|  | 3918 | __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; | 
|  | 3919 | __u -= __pu; | 
|  | 3920 | if (__u < 0) | 
|  | 3921 | return __ru; | 
|  | 3922 | } | 
|  | 3923 | } | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3924 | } | 
|  | 3925 |  | 
|  | 3926 | template <class _CharT, class _Traits, class _IntType> | 
|  | 3927 | basic_ostream<_CharT, _Traits>& | 
|  | 3928 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 3929 | const binomial_distribution<_IntType>& __x) | 
|  | 3930 | { | 
|  | 3931 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3932 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 3933 | ios_base::scientific); | 
| Howard Hinnant | deb23ec | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3934 | _CharT __sp = __os.widen(' '); | 
|  | 3935 | __os.fill(__sp); | 
|  | 3936 | return __os << __x.t() << __sp << __x.p(); | 
|  | 3937 | } | 
|  | 3938 |  | 
|  | 3939 | template <class _CharT, class _Traits, class _IntType> | 
|  | 3940 | basic_istream<_CharT, _Traits>& | 
|  | 3941 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 3942 | binomial_distribution<_IntType>& __x) | 
|  | 3943 | { | 
|  | 3944 | typedef binomial_distribution<_IntType> _Eng; | 
|  | 3945 | typedef typename _Eng::result_type result_type; | 
|  | 3946 | typedef typename _Eng::param_type param_type; | 
|  | 3947 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 3948 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 3949 | result_type __t; | 
|  | 3950 | double __p; | 
|  | 3951 | __is >> __t >> __p; | 
|  | 3952 | if (!__is.fail()) | 
|  | 3953 | __x.param(param_type(__t, __p)); | 
|  | 3954 | return __is; | 
|  | 3955 | } | 
|  | 3956 |  | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3957 | // exponential_distribution | 
|  | 3958 |  | 
|  | 3959 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3960 | class _LIBCPP_VISIBLE exponential_distribution | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3961 | { | 
|  | 3962 | public: | 
|  | 3963 | // types | 
|  | 3964 | typedef _RealType result_type; | 
|  | 3965 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3966 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3967 | { | 
|  | 3968 | result_type __lambda_; | 
|  | 3969 | public: | 
|  | 3970 | typedef exponential_distribution distribution_type; | 
|  | 3971 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3972 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3973 | explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} | 
|  | 3974 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3975 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3976 | result_type lambda() const {return __lambda_;} | 
|  | 3977 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3978 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3979 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3980 | {return __x.__lambda_ == __y.__lambda_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3981 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 3982 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3983 | {return !(__x == __y);} | 
|  | 3984 | }; | 
|  | 3985 |  | 
|  | 3986 | private: | 
|  | 3987 | param_type __p_; | 
|  | 3988 |  | 
|  | 3989 | public: | 
|  | 3990 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3991 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3992 | explicit exponential_distribution(result_type __lambda = 1) | 
|  | 3993 | : __p_(param_type(__lambda)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3994 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3995 | explicit exponential_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3996 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3997 | void reset() {} | 
|  | 3998 |  | 
|  | 3999 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4000 | template<class _URNG> | 
|  | 4001 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4002 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4003 | {return (*this)(__g, __p_);} | 
|  | 4004 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 4005 |  | 
|  | 4006 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4007 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4008 | result_type lambda() const {return __p_.lambda();} | 
|  | 4009 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4010 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4011 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4012 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4013 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4014 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4015 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4016 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4017 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 45a9997 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4018 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4019 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4020 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4021 | bool operator==(const exponential_distribution& __x, | 
|  | 4022 | const exponential_distribution& __y) | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4023 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4024 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4025 | bool operator!=(const exponential_distribution& __x, | 
|  | 4026 | const exponential_distribution& __y) | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4027 | {return !(__x == __y);} | 
|  | 4028 | }; | 
|  | 4029 |  | 
|  | 4030 | template <class _RealType> | 
|  | 4031 | template<class _URNG> | 
|  | 4032 | _RealType | 
|  | 4033 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 4034 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4035 | return -_VSTD::log | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4036 | ( | 
|  | 4037 | result_type(1) - | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4038 | _VSTD::generate_canonical<result_type, | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4039 | numeric_limits<result_type>::digits>(__g) | 
|  | 4040 | ) | 
|  | 4041 | / __p.lambda(); | 
|  | 4042 | } | 
|  | 4043 |  | 
|  | 4044 | template <class _CharT, class _Traits, class _RealType> | 
|  | 4045 | basic_ostream<_CharT, _Traits>& | 
|  | 4046 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4047 | const exponential_distribution<_RealType>& __x) | 
|  | 4048 | { | 
|  | 4049 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4050 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4051 | ios_base::scientific); | 
| Howard Hinnant | bcc4ff0 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4052 | return __os << __x.lambda(); | 
|  | 4053 | } | 
|  | 4054 |  | 
|  | 4055 | template <class _CharT, class _Traits, class _RealType> | 
|  | 4056 | basic_istream<_CharT, _Traits>& | 
|  | 4057 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4058 | exponential_distribution<_RealType>& __x) | 
|  | 4059 | { | 
|  | 4060 | typedef exponential_distribution<_RealType> _Eng; | 
|  | 4061 | typedef typename _Eng::result_type result_type; | 
|  | 4062 | typedef typename _Eng::param_type param_type; | 
|  | 4063 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4064 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4065 | result_type __lambda; | 
|  | 4066 | __is >> __lambda; | 
|  | 4067 | if (!__is.fail()) | 
|  | 4068 | __x.param(param_type(__lambda)); | 
|  | 4069 | return __is; | 
|  | 4070 | } | 
|  | 4071 |  | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4072 | // normal_distribution | 
|  | 4073 |  | 
|  | 4074 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4075 | class _LIBCPP_VISIBLE normal_distribution | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4076 | { | 
|  | 4077 | public: | 
|  | 4078 | // types | 
|  | 4079 | typedef _RealType result_type; | 
|  | 4080 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4081 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4082 | { | 
|  | 4083 | result_type __mean_; | 
|  | 4084 | result_type __stddev_; | 
|  | 4085 | public: | 
|  | 4086 | typedef normal_distribution distribution_type; | 
|  | 4087 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4088 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4089 | explicit param_type(result_type __mean = 0, result_type __stddev = 1) | 
|  | 4090 | : __mean_(__mean), __stddev_(__stddev) {} | 
|  | 4091 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4092 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4093 | result_type mean() const {return __mean_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4094 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4095 | result_type stddev() const {return __stddev_;} | 
|  | 4096 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4097 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4098 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4099 | {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4100 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4101 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4102 | {return !(__x == __y);} | 
|  | 4103 | }; | 
|  | 4104 |  | 
|  | 4105 | private: | 
|  | 4106 | param_type __p_; | 
|  | 4107 | result_type _V_; | 
|  | 4108 | bool _V_hot_; | 
|  | 4109 |  | 
|  | 4110 | public: | 
|  | 4111 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4112 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4113 | explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) | 
|  | 4114 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4115 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4116 | explicit normal_distribution(const param_type& __p) | 
|  | 4117 | : __p_(__p), _V_hot_(false) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4118 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4119 | void reset() {_V_hot_ = false;} | 
|  | 4120 |  | 
|  | 4121 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4122 | template<class _URNG> | 
|  | 4123 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4124 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4125 | {return (*this)(__g, __p_);} | 
|  | 4126 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 4127 |  | 
|  | 4128 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4129 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4130 | result_type mean() const {return __p_.mean();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4131 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4132 | result_type stddev() const {return __p_.stddev();} | 
|  | 4133 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4134 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4135 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4136 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4137 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4138 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4139 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4140 | result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4141 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4142 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
|  | 4143 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4144 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4145 | bool operator==(const normal_distribution& __x, | 
|  | 4146 | const normal_distribution& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4147 | {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && | 
|  | 4148 | (!__x._V_hot_ || __x._V_ == __y._V_);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4149 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4150 | bool operator!=(const normal_distribution& __x, | 
|  | 4151 | const normal_distribution& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4152 | {return !(__x == __y);} | 
|  | 4153 |  | 
|  | 4154 | template <class _CharT, class _Traits, class _RT> | 
|  | 4155 | friend | 
|  | 4156 | basic_ostream<_CharT, _Traits>& | 
|  | 4157 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4158 | const normal_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4159 |  | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4160 | template <class _CharT, class _Traits, class _RT> | 
|  | 4161 | friend | 
|  | 4162 | basic_istream<_CharT, _Traits>& | 
|  | 4163 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4164 | normal_distribution<_RT>& __x); | 
|  | 4165 | }; | 
|  | 4166 |  | 
|  | 4167 | template <class _RealType> | 
|  | 4168 | template<class _URNG> | 
|  | 4169 | _RealType | 
|  | 4170 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 4171 | { | 
|  | 4172 | result_type _U; | 
|  | 4173 | if (_V_hot_) | 
|  | 4174 | { | 
|  | 4175 | _V_hot_ = false; | 
|  | 4176 | _U = _V_; | 
|  | 4177 | } | 
|  | 4178 | else | 
|  | 4179 | { | 
|  | 4180 | uniform_real_distribution<result_type> _Uni(-1, 1); | 
|  | 4181 | result_type __u; | 
|  | 4182 | result_type __v; | 
|  | 4183 | result_type __s; | 
|  | 4184 | do | 
|  | 4185 | { | 
|  | 4186 | __u = _Uni(__g); | 
|  | 4187 | __v = _Uni(__g); | 
|  | 4188 | __s = __u * __u + __v * __v; | 
|  | 4189 | } while (__s > 1 || __s == 0); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4190 | result_type _F = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4191 | _V_ = __v * _F; | 
|  | 4192 | _V_hot_ = true; | 
|  | 4193 | _U = __u * _F; | 
|  | 4194 | } | 
|  | 4195 | return _U * __p.stddev() + __p.mean(); | 
|  | 4196 | } | 
|  | 4197 |  | 
|  | 4198 | template <class _CharT, class _Traits, class _RT> | 
|  | 4199 | basic_ostream<_CharT, _Traits>& | 
|  | 4200 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4201 | const normal_distribution<_RT>& __x) | 
|  | 4202 | { | 
|  | 4203 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4204 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4205 | ios_base::scientific); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4206 | _CharT __sp = __os.widen(' '); | 
|  | 4207 | __os.fill(__sp); | 
|  | 4208 | __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; | 
|  | 4209 | if (__x._V_hot_) | 
|  | 4210 | __os << __sp << __x._V_; | 
|  | 4211 | return __os; | 
|  | 4212 | } | 
|  | 4213 |  | 
|  | 4214 | template <class _CharT, class _Traits, class _RT> | 
|  | 4215 | basic_istream<_CharT, _Traits>& | 
|  | 4216 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4217 | normal_distribution<_RT>& __x) | 
|  | 4218 | { | 
|  | 4219 | typedef normal_distribution<_RT> _Eng; | 
|  | 4220 | typedef typename _Eng::result_type result_type; | 
|  | 4221 | typedef typename _Eng::param_type param_type; | 
|  | 4222 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4223 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4224 | result_type __mean; | 
|  | 4225 | result_type __stddev; | 
|  | 4226 | result_type _V = 0; | 
|  | 4227 | bool _V_hot = false; | 
|  | 4228 | __is >> __mean >> __stddev >> _V_hot; | 
|  | 4229 | if (_V_hot) | 
|  | 4230 | __is >> _V; | 
|  | 4231 | if (!__is.fail()) | 
|  | 4232 | { | 
|  | 4233 | __x.param(param_type(__mean, __stddev)); | 
|  | 4234 | __x._V_hot_ = _V_hot; | 
|  | 4235 | __x._V_ = _V; | 
|  | 4236 | } | 
|  | 4237 | return __is; | 
|  | 4238 | } | 
|  | 4239 |  | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4240 | // lognormal_distribution | 
|  | 4241 |  | 
|  | 4242 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4243 | class _LIBCPP_VISIBLE lognormal_distribution | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4244 | { | 
|  | 4245 | public: | 
|  | 4246 | // types | 
|  | 4247 | typedef _RealType result_type; | 
|  | 4248 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4249 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4250 | { | 
|  | 4251 | normal_distribution<result_type> __nd_; | 
|  | 4252 | public: | 
|  | 4253 | typedef lognormal_distribution distribution_type; | 
|  | 4254 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4255 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4256 | explicit param_type(result_type __m = 0, result_type __s = 1) | 
|  | 4257 | : __nd_(__m, __s) {} | 
|  | 4258 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4259 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4260 | result_type m() const {return __nd_.mean();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4261 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4262 | result_type s() const {return __nd_.stddev();} | 
|  | 4263 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4264 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4265 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4266 | {return __x.__nd_ == __y.__nd_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4267 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4268 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4269 | {return !(__x == __y);} | 
|  | 4270 | friend class lognormal_distribution; | 
|  | 4271 |  | 
|  | 4272 | template <class _CharT, class _Traits, class _RT> | 
|  | 4273 | friend | 
|  | 4274 | basic_ostream<_CharT, _Traits>& | 
|  | 4275 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4276 | const lognormal_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4277 |  | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4278 | template <class _CharT, class _Traits, class _RT> | 
|  | 4279 | friend | 
|  | 4280 | basic_istream<_CharT, _Traits>& | 
|  | 4281 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4282 | lognormal_distribution<_RT>& __x); | 
|  | 4283 | }; | 
|  | 4284 |  | 
|  | 4285 | private: | 
|  | 4286 | param_type __p_; | 
|  | 4287 |  | 
|  | 4288 | public: | 
|  | 4289 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4290 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4291 | explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) | 
|  | 4292 | : __p_(param_type(__m, __s)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4293 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4294 | explicit lognormal_distribution(const param_type& __p) | 
|  | 4295 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4296 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4297 | void reset() {__p_.__nd_.reset();} | 
|  | 4298 |  | 
|  | 4299 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4300 | template<class _URNG> | 
|  | 4301 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4302 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4303 | {return (*this)(__g, __p_);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4304 | template<class _URNG> | 
|  | 4305 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4306 | result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4307 | {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4308 |  | 
|  | 4309 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4310 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4311 | result_type m() const {return __p_.m();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4312 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4313 | result_type s() const {return __p_.s();} | 
|  | 4314 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4315 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4316 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4317 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4318 | void param(const param_type& __p) {__p_ = __p;} | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4319 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4320 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4321 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4322 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4323 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
|  | 4324 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4325 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4326 | bool operator==(const lognormal_distribution& __x, | 
|  | 4327 | const lognormal_distribution& __y) | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4328 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4329 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4330 | bool operator!=(const lognormal_distribution& __x, | 
|  | 4331 | const lognormal_distribution& __y) | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4332 | {return !(__x == __y);} | 
|  | 4333 |  | 
|  | 4334 | template <class _CharT, class _Traits, class _RT> | 
|  | 4335 | friend | 
|  | 4336 | basic_ostream<_CharT, _Traits>& | 
|  | 4337 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4338 | const lognormal_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4339 |  | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4340 | template <class _CharT, class _Traits, class _RT> | 
|  | 4341 | friend | 
|  | 4342 | basic_istream<_CharT, _Traits>& | 
|  | 4343 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4344 | lognormal_distribution<_RT>& __x); | 
|  | 4345 | }; | 
|  | 4346 |  | 
|  | 4347 | template <class _CharT, class _Traits, class _RT> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4348 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4349 | basic_ostream<_CharT, _Traits>& | 
|  | 4350 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4351 | const lognormal_distribution<_RT>& __x) | 
|  | 4352 | { | 
|  | 4353 | return __os << __x.__p_.__nd_; | 
|  | 4354 | } | 
|  | 4355 |  | 
|  | 4356 | template <class _CharT, class _Traits, class _RT> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4357 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fd5c3a3 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4358 | basic_istream<_CharT, _Traits>& | 
|  | 4359 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4360 | lognormal_distribution<_RT>& __x) | 
|  | 4361 | { | 
|  | 4362 | return __is >> __x.__p_.__nd_; | 
|  | 4363 | } | 
|  | 4364 |  | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4365 | // poisson_distribution | 
|  | 4366 |  | 
|  | 4367 | template<class _IntType = int> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4368 | class _LIBCPP_VISIBLE poisson_distribution | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4369 | { | 
|  | 4370 | public: | 
|  | 4371 | // types | 
|  | 4372 | typedef _IntType result_type; | 
|  | 4373 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4374 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4375 | { | 
|  | 4376 | double __mean_; | 
|  | 4377 | double __s_; | 
|  | 4378 | double __d_; | 
|  | 4379 | double __l_; | 
|  | 4380 | double __omega_; | 
|  | 4381 | double __c0_; | 
|  | 4382 | double __c1_; | 
|  | 4383 | double __c2_; | 
|  | 4384 | double __c3_; | 
|  | 4385 | double __c_; | 
|  | 4386 |  | 
|  | 4387 | public: | 
|  | 4388 | typedef poisson_distribution distribution_type; | 
|  | 4389 |  | 
|  | 4390 | explicit param_type(double __mean = 1.0); | 
|  | 4391 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4392 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4393 | double mean() const {return __mean_;} | 
|  | 4394 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4395 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4396 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4397 | {return __x.__mean_ == __y.__mean_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4398 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4399 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4400 | {return !(__x == __y);} | 
|  | 4401 |  | 
|  | 4402 | friend class poisson_distribution; | 
|  | 4403 | }; | 
|  | 4404 |  | 
|  | 4405 | private: | 
|  | 4406 | param_type __p_; | 
|  | 4407 |  | 
|  | 4408 | public: | 
|  | 4409 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4410 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4411 | explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4412 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4413 | explicit poisson_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4414 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4415 | void reset() {} | 
|  | 4416 |  | 
|  | 4417 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4418 | template<class _URNG> | 
|  | 4419 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4420 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4421 | {return (*this)(__g, __p_);} | 
|  | 4422 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 4423 |  | 
|  | 4424 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4425 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4426 | double mean() const {return __p_.mean();} | 
|  | 4427 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4428 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4429 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4430 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4431 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4432 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4433 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4434 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4435 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4436 | result_type max() const {return numeric_limits<result_type>::max();} | 
|  | 4437 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4438 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4439 | bool operator==(const poisson_distribution& __x, | 
|  | 4440 | const poisson_distribution& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4441 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4442 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4443 | bool operator!=(const poisson_distribution& __x, | 
|  | 4444 | const poisson_distribution& __y) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4445 | {return !(__x == __y);} | 
|  | 4446 | }; | 
|  | 4447 |  | 
|  | 4448 | template<class _IntType> | 
|  | 4449 | poisson_distribution<_IntType>::param_type::param_type(double __mean) | 
|  | 4450 | : __mean_(__mean) | 
|  | 4451 | { | 
|  | 4452 | if (__mean_ < 10) | 
|  | 4453 | { | 
|  | 4454 | __s_ = 0; | 
|  | 4455 | __d_ = 0; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4456 | __l_ = _VSTD::exp(-__mean_); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4457 | __omega_ = 0; | 
|  | 4458 | __c3_ = 0; | 
|  | 4459 | __c2_ = 0; | 
|  | 4460 | __c1_ = 0; | 
|  | 4461 | __c0_ = 0; | 
|  | 4462 | __c_ = 0; | 
|  | 4463 | } | 
|  | 4464 | else | 
|  | 4465 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4466 | __s_ = _VSTD::sqrt(__mean_); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4467 | __d_ = 6 * __mean_ * __mean_; | 
|  | 4468 | __l_ = static_cast<result_type>(__mean_ - 1.1484); | 
|  | 4469 | __omega_ = .3989423 / __s_; | 
|  | 4470 | double __b1_ = .4166667E-1 / __mean_; | 
|  | 4471 | double __b2_ = .3 * __b1_ * __b1_; | 
|  | 4472 | __c3_ = .1428571 * __b1_ * __b2_; | 
|  | 4473 | __c2_ = __b2_ - 15. * __c3_; | 
|  | 4474 | __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; | 
|  | 4475 | __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; | 
|  | 4476 | __c_ = .1069 / __mean_; | 
|  | 4477 | } | 
|  | 4478 | } | 
|  | 4479 |  | 
|  | 4480 | template <class _IntType> | 
|  | 4481 | template<class _URNG> | 
|  | 4482 | _IntType | 
|  | 4483 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) | 
|  | 4484 | { | 
|  | 4485 | result_type __x; | 
|  | 4486 | uniform_real_distribution<double> __urd; | 
| Howard Hinnant | 866d73c | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4487 | if (__pr.__mean_ < 10) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4488 | { | 
|  | 4489 | __x = 0; | 
|  | 4490 | for (double __p = __urd(__urng); __p > __pr.__l_; ++__x) | 
|  | 4491 | __p *= __urd(__urng); | 
|  | 4492 | } | 
|  | 4493 | else | 
|  | 4494 | { | 
|  | 4495 | double __difmuk; | 
|  | 4496 | double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); | 
|  | 4497 | double __u; | 
|  | 4498 | if (__g > 0) | 
|  | 4499 | { | 
|  | 4500 | __x = static_cast<result_type>(__g); | 
|  | 4501 | if (__x >= __pr.__l_) | 
|  | 4502 | return __x; | 
|  | 4503 | __difmuk = __pr.__mean_ - __x; | 
|  | 4504 | __u = __urd(__urng); | 
|  | 4505 | if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) | 
|  | 4506 | return __x; | 
|  | 4507 | } | 
|  | 4508 | exponential_distribution<double> __edist; | 
|  | 4509 | for (bool __using_exp_dist = false; true; __using_exp_dist = true) | 
|  | 4510 | { | 
|  | 4511 | double __e; | 
|  | 4512 | if (__using_exp_dist || __g < 0) | 
|  | 4513 | { | 
|  | 4514 | double __t; | 
|  | 4515 | do | 
|  | 4516 | { | 
|  | 4517 | __e = __edist(__urng); | 
|  | 4518 | __u = __urd(__urng); | 
|  | 4519 | __u += __u - 1; | 
|  | 4520 | __t = 1.8 + (__u < 0 ? -__e : __e); | 
|  | 4521 | } while (__t <= -.6744); | 
|  | 4522 | __x = __pr.__mean_ + __pr.__s_ * __t; | 
|  | 4523 | __difmuk = __pr.__mean_ - __x; | 
|  | 4524 | __using_exp_dist = true; | 
|  | 4525 | } | 
|  | 4526 | double __px; | 
|  | 4527 | double __py; | 
|  | 4528 | if (__x < 10) | 
|  | 4529 | { | 
|  | 4530 | const result_type __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, | 
|  | 4531 | 40320, 362880}; | 
|  | 4532 | __px = -__pr.__mean_; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4533 | __py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x]; | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4534 | } | 
|  | 4535 | else | 
|  | 4536 | { | 
|  | 4537 | double __del = .8333333E-1 / __x; | 
|  | 4538 | __del -= 4.8 * __del * __del * __del; | 
|  | 4539 | double __v = __difmuk / __x; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4540 | if (_VSTD::abs(__v) > 0.25) | 
|  | 4541 | __px = __x * _VSTD::log(1 + __v) - __difmuk - __del; | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4542 | else | 
|  | 4543 | __px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) * | 
|  | 4544 | __v + .1421878) * __v + -.1661269) * __v + .2000118) * | 
|  | 4545 | __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4546 | __py = .3989423 / _VSTD::sqrt(__x); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4547 | } | 
|  | 4548 | double __r = (0.5 - __difmuk) / __pr.__s_; | 
|  | 4549 | double __r2 = __r * __r; | 
|  | 4550 | double __fx = -0.5 * __r2; | 
|  | 4551 | double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * | 
|  | 4552 | __r2 + __pr.__c1_) * __r2 + __pr.__c0_); | 
|  | 4553 | if (__using_exp_dist) | 
|  | 4554 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4555 | if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - | 
|  | 4556 | __fy * _VSTD::exp(__fx + __e)) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4557 | break; | 
|  | 4558 | } | 
|  | 4559 | else | 
|  | 4560 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4561 | if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4562 | break; | 
|  | 4563 | } | 
|  | 4564 | } | 
|  | 4565 | } | 
|  | 4566 | return __x; | 
|  | 4567 | } | 
|  | 4568 |  | 
|  | 4569 | template <class _CharT, class _Traits, class _IntType> | 
|  | 4570 | basic_ostream<_CharT, _Traits>& | 
|  | 4571 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4572 | const poisson_distribution<_IntType>& __x) | 
|  | 4573 | { | 
|  | 4574 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4575 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4576 | ios_base::scientific); | 
| Howard Hinnant | 932ce81 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4577 | return __os << __x.mean(); | 
|  | 4578 | } | 
|  | 4579 |  | 
|  | 4580 | template <class _CharT, class _Traits, class _IntType> | 
|  | 4581 | basic_istream<_CharT, _Traits>& | 
|  | 4582 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4583 | poisson_distribution<_IntType>& __x) | 
|  | 4584 | { | 
|  | 4585 | typedef poisson_distribution<_IntType> _Eng; | 
|  | 4586 | typedef typename _Eng::param_type param_type; | 
|  | 4587 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4588 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4589 | double __mean; | 
|  | 4590 | __is >> __mean; | 
|  | 4591 | if (!__is.fail()) | 
|  | 4592 | __x.param(param_type(__mean)); | 
|  | 4593 | return __is; | 
|  | 4594 | } | 
|  | 4595 |  | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4596 | // weibull_distribution | 
|  | 4597 |  | 
|  | 4598 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4599 | class _LIBCPP_VISIBLE weibull_distribution | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4600 | { | 
|  | 4601 | public: | 
|  | 4602 | // types | 
|  | 4603 | typedef _RealType result_type; | 
|  | 4604 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4605 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4606 | { | 
|  | 4607 | result_type __a_; | 
|  | 4608 | result_type __b_; | 
|  | 4609 | public: | 
|  | 4610 | typedef weibull_distribution distribution_type; | 
|  | 4611 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4612 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4613 | explicit param_type(result_type __a = 1, result_type __b = 1) | 
|  | 4614 | : __a_(__a), __b_(__b) {} | 
|  | 4615 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4616 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4617 | result_type a() const {return __a_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4618 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4619 | result_type b() const {return __b_;} | 
|  | 4620 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4621 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4622 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4623 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4624 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4625 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4626 | {return !(__x == __y);} | 
|  | 4627 | }; | 
|  | 4628 |  | 
|  | 4629 | private: | 
|  | 4630 | param_type __p_; | 
|  | 4631 |  | 
|  | 4632 | public: | 
|  | 4633 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4634 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4635 | explicit weibull_distribution(result_type __a = 1, result_type __b = 1) | 
|  | 4636 | : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4637 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4638 | explicit weibull_distribution(const param_type& __p) | 
|  | 4639 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4640 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4641 | void reset() {} | 
|  | 4642 |  | 
|  | 4643 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4644 | template<class _URNG> | 
|  | 4645 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4646 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4647 | {return (*this)(__g, __p_);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4648 | template<class _URNG> | 
|  | 4649 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4650 | result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4651 | {return __p.b() * | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4652 | _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4653 |  | 
|  | 4654 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4655 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4656 | result_type a() const {return __p_.a();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4657 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4658 | result_type b() const {return __p_.b();} | 
|  | 4659 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4660 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4661 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4662 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4663 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4664 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4665 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4666 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4667 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4668 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
|  | 4669 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4670 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4671 | bool operator==(const weibull_distribution& __x, | 
|  | 4672 | const weibull_distribution& __y) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4673 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4674 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4675 | bool operator!=(const weibull_distribution& __x, | 
|  | 4676 | const weibull_distribution& __y) | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4677 | {return !(__x == __y);} | 
|  | 4678 | }; | 
|  | 4679 |  | 
|  | 4680 | template <class _CharT, class _Traits, class _RT> | 
|  | 4681 | basic_ostream<_CharT, _Traits>& | 
|  | 4682 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4683 | const weibull_distribution<_RT>& __x) | 
|  | 4684 | { | 
|  | 4685 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4686 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4687 | ios_base::scientific); | 
| Howard Hinnant | b882982 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4688 | _CharT __sp = __os.widen(' '); | 
|  | 4689 | __os.fill(__sp); | 
|  | 4690 | __os << __x.a() << __sp << __x.b(); | 
|  | 4691 | return __os; | 
|  | 4692 | } | 
|  | 4693 |  | 
|  | 4694 | template <class _CharT, class _Traits, class _RT> | 
|  | 4695 | basic_istream<_CharT, _Traits>& | 
|  | 4696 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4697 | weibull_distribution<_RT>& __x) | 
|  | 4698 | { | 
|  | 4699 | typedef weibull_distribution<_RT> _Eng; | 
|  | 4700 | typedef typename _Eng::result_type result_type; | 
|  | 4701 | typedef typename _Eng::param_type param_type; | 
|  | 4702 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4703 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4704 | result_type __a; | 
|  | 4705 | result_type __b; | 
|  | 4706 | __is >> __a >> __b; | 
|  | 4707 | if (!__is.fail()) | 
|  | 4708 | __x.param(param_type(__a, __b)); | 
|  | 4709 | return __is; | 
|  | 4710 | } | 
|  | 4711 |  | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4712 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4713 | class _LIBCPP_VISIBLE extreme_value_distribution | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4714 | { | 
|  | 4715 | public: | 
|  | 4716 | // types | 
|  | 4717 | typedef _RealType result_type; | 
|  | 4718 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4719 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4720 | { | 
|  | 4721 | result_type __a_; | 
|  | 4722 | result_type __b_; | 
|  | 4723 | public: | 
|  | 4724 | typedef extreme_value_distribution distribution_type; | 
|  | 4725 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4726 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4727 | explicit param_type(result_type __a = 0, result_type __b = 1) | 
|  | 4728 | : __a_(__a), __b_(__b) {} | 
|  | 4729 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4730 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4731 | result_type a() const {return __a_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4732 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4733 | result_type b() const {return __b_;} | 
|  | 4734 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4735 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4736 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4737 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4738 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4739 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4740 | {return !(__x == __y);} | 
|  | 4741 | }; | 
|  | 4742 |  | 
|  | 4743 | private: | 
|  | 4744 | param_type __p_; | 
|  | 4745 |  | 
|  | 4746 | public: | 
|  | 4747 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4748 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4749 | explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) | 
|  | 4750 | : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4751 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4752 | explicit extreme_value_distribution(const param_type& __p) | 
|  | 4753 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4754 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4755 | void reset() {} | 
|  | 4756 |  | 
|  | 4757 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4758 | template<class _URNG> | 
|  | 4759 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4760 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4761 | {return (*this)(__g, __p_);} | 
|  | 4762 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 4763 |  | 
|  | 4764 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4765 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4766 | result_type a() const {return __p_.a();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4767 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4768 | result_type b() const {return __p_.b();} | 
|  | 4769 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4770 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4771 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4772 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4773 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4774 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4775 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4776 | result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4777 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4778 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
|  | 4779 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4780 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4781 | bool operator==(const extreme_value_distribution& __x, | 
|  | 4782 | const extreme_value_distribution& __y) | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4783 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4784 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4785 | bool operator!=(const extreme_value_distribution& __x, | 
|  | 4786 | const extreme_value_distribution& __y) | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4787 | {return !(__x == __y);} | 
|  | 4788 | }; | 
|  | 4789 |  | 
|  | 4790 | template<class _RealType> | 
|  | 4791 | template<class _URNG> | 
|  | 4792 | _RealType | 
|  | 4793 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 4794 | { | 
|  | 4795 | return __p.a() - __p.b() * | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4796 | _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4797 | } | 
|  | 4798 |  | 
|  | 4799 | template <class _CharT, class _Traits, class _RT> | 
|  | 4800 | basic_ostream<_CharT, _Traits>& | 
|  | 4801 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4802 | const extreme_value_distribution<_RT>& __x) | 
|  | 4803 | { | 
|  | 4804 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4805 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4806 | ios_base::scientific); | 
| Howard Hinnant | c675d98 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4807 | _CharT __sp = __os.widen(' '); | 
|  | 4808 | __os.fill(__sp); | 
|  | 4809 | __os << __x.a() << __sp << __x.b(); | 
|  | 4810 | return __os; | 
|  | 4811 | } | 
|  | 4812 |  | 
|  | 4813 | template <class _CharT, class _Traits, class _RT> | 
|  | 4814 | basic_istream<_CharT, _Traits>& | 
|  | 4815 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4816 | extreme_value_distribution<_RT>& __x) | 
|  | 4817 | { | 
|  | 4818 | typedef extreme_value_distribution<_RT> _Eng; | 
|  | 4819 | typedef typename _Eng::result_type result_type; | 
|  | 4820 | typedef typename _Eng::param_type param_type; | 
|  | 4821 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4822 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4823 | result_type __a; | 
|  | 4824 | result_type __b; | 
|  | 4825 | __is >> __a >> __b; | 
|  | 4826 | if (!__is.fail()) | 
|  | 4827 | __x.param(param_type(__a, __b)); | 
|  | 4828 | return __is; | 
|  | 4829 | } | 
|  | 4830 |  | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4831 | // gamma_distribution | 
|  | 4832 |  | 
|  | 4833 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4834 | class _LIBCPP_VISIBLE gamma_distribution | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4835 | { | 
|  | 4836 | public: | 
|  | 4837 | // types | 
|  | 4838 | typedef _RealType result_type; | 
|  | 4839 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4840 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4841 | { | 
|  | 4842 | result_type __alpha_; | 
|  | 4843 | result_type __beta_; | 
|  | 4844 | public: | 
|  | 4845 | typedef gamma_distribution distribution_type; | 
|  | 4846 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4847 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4848 | explicit param_type(result_type __alpha = 1, result_type __beta = 1) | 
|  | 4849 | : __alpha_(__alpha), __beta_(__beta) {} | 
|  | 4850 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4851 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4852 | result_type alpha() const {return __alpha_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4853 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4854 | result_type beta() const {return __beta_;} | 
|  | 4855 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4856 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4857 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4858 | {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4859 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4860 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4861 | {return !(__x == __y);} | 
|  | 4862 | }; | 
|  | 4863 |  | 
|  | 4864 | private: | 
|  | 4865 | param_type __p_; | 
|  | 4866 |  | 
|  | 4867 | public: | 
|  | 4868 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4869 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4870 | explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) | 
|  | 4871 | : __p_(param_type(__alpha, __beta)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4872 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4873 | explicit gamma_distribution(const param_type& __p) | 
|  | 4874 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4875 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4876 | void reset() {} | 
|  | 4877 |  | 
|  | 4878 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4879 | template<class _URNG> | 
|  | 4880 | _LIBCPP_INLINE_VISIBILITY | 
|  | 4881 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4882 | {return (*this)(__g, __p_);} | 
|  | 4883 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 4884 |  | 
|  | 4885 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4886 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4887 | result_type alpha() const {return __p_.alpha();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4888 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4889 | result_type beta() const {return __p_.beta();} | 
|  | 4890 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4891 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4892 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4893 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4894 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 4895 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4896 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4897 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4898 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4899 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4900 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4901 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4902 | bool operator==(const gamma_distribution& __x, | 
|  | 4903 | const gamma_distribution& __y) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4904 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4905 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 4906 | bool operator!=(const gamma_distribution& __x, | 
|  | 4907 | const gamma_distribution& __y) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4908 | {return !(__x == __y);} | 
|  | 4909 | }; | 
|  | 4910 |  | 
|  | 4911 | template <class _RealType> | 
|  | 4912 | template<class _URNG> | 
|  | 4913 | _RealType | 
|  | 4914 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 4915 | { | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4916 | result_type __a = __p.alpha(); | 
|  | 4917 | uniform_real_distribution<result_type> __gen(0, 1); | 
|  | 4918 | exponential_distribution<result_type> __egen; | 
|  | 4919 | result_type __x; | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4920 | if (__a == 1) | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4921 | __x = __egen(__g); | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4922 | else if (__a > 1) | 
|  | 4923 | { | 
|  | 4924 | const result_type __b = __a - 1; | 
|  | 4925 | const result_type __c = 3 * __a - result_type(0.75); | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4926 | while (true) | 
|  | 4927 | { | 
|  | 4928 | const result_type __u = __gen(__g); | 
|  | 4929 | const result_type __v = __gen(__g); | 
|  | 4930 | const result_type __w = __u * (1 - __u); | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4931 | if (__w != 0) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4932 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4933 | const result_type __y = _VSTD::sqrt(__c / __w) * | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4934 | (__u - result_type(0.5)); | 
|  | 4935 | __x = __b + __y; | 
|  | 4936 | if (__x >= 0) | 
|  | 4937 | { | 
|  | 4938 | const result_type __z = 64 * __w * __w * __w * __v * __v; | 
|  | 4939 | if (__z <= 1 - 2 * __y * __y / __x) | 
|  | 4940 | break; | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4941 | if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4942 | break; | 
|  | 4943 | } | 
|  | 4944 | } | 
|  | 4945 | } | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4946 | } | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4947 | else  // __a < 1 | 
|  | 4948 | { | 
|  | 4949 | while (true) | 
|  | 4950 | { | 
|  | 4951 | const result_type __u = __gen(__g); | 
|  | 4952 | const result_type __es = __egen(__g); | 
|  | 4953 | if (__u <= 1 - __a) | 
|  | 4954 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4955 | __x = _VSTD::pow(__u, 1 / __a); | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4956 | if (__x <= __es) | 
|  | 4957 | break; | 
|  | 4958 | } | 
|  | 4959 | else | 
|  | 4960 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4961 | const result_type __e = -_VSTD::log((1-__u)/__a); | 
|  | 4962 | __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); | 
| Howard Hinnant | 7070922 | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 4963 | if (__x <= __e + __es) | 
|  | 4964 | break; | 
|  | 4965 | } | 
|  | 4966 | } | 
|  | 4967 | } | 
|  | 4968 | return __x * __p.beta(); | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4969 | } | 
|  | 4970 |  | 
|  | 4971 | template <class _CharT, class _Traits, class _RT> | 
|  | 4972 | basic_ostream<_CharT, _Traits>& | 
|  | 4973 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 4974 | const gamma_distribution<_RT>& __x) | 
|  | 4975 | { | 
|  | 4976 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4977 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 4978 | ios_base::scientific); | 
| Howard Hinnant | f8bfb45 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4979 | _CharT __sp = __os.widen(' '); | 
|  | 4980 | __os.fill(__sp); | 
|  | 4981 | __os << __x.alpha() << __sp << __x.beta(); | 
|  | 4982 | return __os; | 
|  | 4983 | } | 
|  | 4984 |  | 
|  | 4985 | template <class _CharT, class _Traits, class _RT> | 
|  | 4986 | basic_istream<_CharT, _Traits>& | 
|  | 4987 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 4988 | gamma_distribution<_RT>& __x) | 
|  | 4989 | { | 
|  | 4990 | typedef gamma_distribution<_RT> _Eng; | 
|  | 4991 | typedef typename _Eng::result_type result_type; | 
|  | 4992 | typedef typename _Eng::param_type param_type; | 
|  | 4993 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 4994 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 4995 | result_type __alpha; | 
|  | 4996 | result_type __beta; | 
|  | 4997 | __is >> __alpha >> __beta; | 
|  | 4998 | if (!__is.fail()) | 
|  | 4999 | __x.param(param_type(__alpha, __beta)); | 
|  | 5000 | return __is; | 
|  | 5001 | } | 
| Howard Hinnant | 6f97c4e | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 5002 |  | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5003 | // negative_binomial_distribution | 
|  | 5004 |  | 
|  | 5005 | template<class _IntType = int> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5006 | class _LIBCPP_VISIBLE negative_binomial_distribution | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5007 | { | 
|  | 5008 | public: | 
|  | 5009 | // types | 
|  | 5010 | typedef _IntType result_type; | 
|  | 5011 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5012 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5013 | { | 
|  | 5014 | result_type __k_; | 
|  | 5015 | double __p_; | 
|  | 5016 | public: | 
|  | 5017 | typedef negative_binomial_distribution distribution_type; | 
|  | 5018 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5019 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5020 | explicit param_type(result_type __k = 1, double __p = 0.5) | 
|  | 5021 | : __k_(__k), __p_(__p) {} | 
|  | 5022 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5023 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5024 | result_type k() const {return __k_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5025 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5026 | double p() const {return __p_;} | 
|  | 5027 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5028 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5029 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5030 | {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5031 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5032 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5033 | {return !(__x == __y);} | 
|  | 5034 | }; | 
|  | 5035 |  | 
|  | 5036 | private: | 
|  | 5037 | param_type __p_; | 
|  | 5038 |  | 
|  | 5039 | public: | 
|  | 5040 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5041 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5042 | explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) | 
|  | 5043 | : __p_(__k, __p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5044 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5045 | explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5046 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5047 | void reset() {} | 
|  | 5048 |  | 
|  | 5049 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5050 | template<class _URNG> | 
|  | 5051 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5052 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5053 | {return (*this)(__g, __p_);} | 
|  | 5054 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 5055 |  | 
|  | 5056 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5057 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5058 | result_type k() const {return __p_.k();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5059 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5060 | double p() const {return __p_.p();} | 
|  | 5061 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5062 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5063 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5064 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5065 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5066 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5067 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5068 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5069 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5070 | result_type max() const {return numeric_limits<result_type>::max();} | 
|  | 5071 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5072 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5073 | bool operator==(const negative_binomial_distribution& __x, | 
|  | 5074 | const negative_binomial_distribution& __y) | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5075 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5076 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5077 | bool operator!=(const negative_binomial_distribution& __x, | 
|  | 5078 | const negative_binomial_distribution& __y) | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5079 | {return !(__x == __y);} | 
|  | 5080 | }; | 
|  | 5081 |  | 
|  | 5082 | template <class _IntType> | 
|  | 5083 | template<class _URNG> | 
|  | 5084 | _IntType | 
|  | 5085 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) | 
|  | 5086 | { | 
|  | 5087 | result_type __k = __pr.k(); | 
|  | 5088 | double __p = __pr.p(); | 
|  | 5089 | if (__k <= 21 * __p) | 
|  | 5090 | { | 
|  | 5091 | bernoulli_distribution __gen(__p); | 
|  | 5092 | result_type __f = 0; | 
|  | 5093 | result_type __s = 0; | 
|  | 5094 | while (__s < __k) | 
|  | 5095 | { | 
|  | 5096 | if (__gen(__urng)) | 
|  | 5097 | ++__s; | 
|  | 5098 | else | 
|  | 5099 | ++__f; | 
|  | 5100 | } | 
|  | 5101 | return __f; | 
|  | 5102 | } | 
|  | 5103 | return poisson_distribution<result_type>(gamma_distribution<double> | 
|  | 5104 | (__k, (1-__p)/__p)(__urng))(__urng); | 
|  | 5105 | } | 
|  | 5106 |  | 
|  | 5107 | template <class _CharT, class _Traits, class _IntType> | 
|  | 5108 | basic_ostream<_CharT, _Traits>& | 
|  | 5109 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5110 | const negative_binomial_distribution<_IntType>& __x) | 
|  | 5111 | { | 
|  | 5112 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5113 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5114 | ios_base::scientific); | 
| Howard Hinnant | 89eaea2 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5115 | _CharT __sp = __os.widen(' '); | 
|  | 5116 | __os.fill(__sp); | 
|  | 5117 | return __os << __x.k() << __sp << __x.p(); | 
|  | 5118 | } | 
|  | 5119 |  | 
|  | 5120 | template <class _CharT, class _Traits, class _IntType> | 
|  | 5121 | basic_istream<_CharT, _Traits>& | 
|  | 5122 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5123 | negative_binomial_distribution<_IntType>& __x) | 
|  | 5124 | { | 
|  | 5125 | typedef negative_binomial_distribution<_IntType> _Eng; | 
|  | 5126 | typedef typename _Eng::result_type result_type; | 
|  | 5127 | typedef typename _Eng::param_type param_type; | 
|  | 5128 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5129 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5130 | result_type __k; | 
|  | 5131 | double __p; | 
|  | 5132 | __is >> __k >> __p; | 
|  | 5133 | if (!__is.fail()) | 
|  | 5134 | __x.param(param_type(__k, __p)); | 
|  | 5135 | return __is; | 
|  | 5136 | } | 
|  | 5137 |  | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5138 | // geometric_distribution | 
|  | 5139 |  | 
|  | 5140 | template<class _IntType = int> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5141 | class _LIBCPP_VISIBLE geometric_distribution | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5142 | { | 
|  | 5143 | public: | 
|  | 5144 | // types | 
|  | 5145 | typedef _IntType result_type; | 
|  | 5146 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5147 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5148 | { | 
|  | 5149 | double __p_; | 
|  | 5150 | public: | 
|  | 5151 | typedef geometric_distribution distribution_type; | 
|  | 5152 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5153 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5154 | explicit param_type(double __p = 0.5) : __p_(__p) {} | 
|  | 5155 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5156 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5157 | double p() const {return __p_;} | 
|  | 5158 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5159 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5160 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5161 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5162 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5163 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5164 | {return !(__x == __y);} | 
|  | 5165 | }; | 
|  | 5166 |  | 
|  | 5167 | private: | 
|  | 5168 | param_type __p_; | 
|  | 5169 |  | 
|  | 5170 | public: | 
|  | 5171 | // constructors and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5172 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5173 | explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5174 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5175 | explicit geometric_distribution(const param_type& __p) : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5176 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5177 | void reset() {} | 
|  | 5178 |  | 
|  | 5179 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5180 | template<class _URNG> | 
|  | 5181 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5182 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5183 | {return (*this)(__g, __p_);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5184 | template<class _URNG> | 
|  | 5185 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5186 | result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5187 | {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} | 
|  | 5188 |  | 
|  | 5189 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5190 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5191 | double p() const {return __p_.p();} | 
|  | 5192 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5193 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5194 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5195 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5196 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5197 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5198 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5199 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5200 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5201 | result_type max() const {return numeric_limits<result_type>::max();} | 
|  | 5202 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5203 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5204 | bool operator==(const geometric_distribution& __x, | 
|  | 5205 | const geometric_distribution& __y) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5206 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5207 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5208 | bool operator!=(const geometric_distribution& __x, | 
|  | 5209 | const geometric_distribution& __y) | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5210 | {return !(__x == __y);} | 
|  | 5211 | }; | 
|  | 5212 |  | 
|  | 5213 | template <class _CharT, class _Traits, class _IntType> | 
|  | 5214 | basic_ostream<_CharT, _Traits>& | 
|  | 5215 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5216 | const geometric_distribution<_IntType>& __x) | 
|  | 5217 | { | 
|  | 5218 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5219 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5220 | ios_base::scientific); | 
| Howard Hinnant | 05fa30d | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5221 | return __os << __x.p(); | 
|  | 5222 | } | 
|  | 5223 |  | 
|  | 5224 | template <class _CharT, class _Traits, class _IntType> | 
|  | 5225 | basic_istream<_CharT, _Traits>& | 
|  | 5226 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5227 | geometric_distribution<_IntType>& __x) | 
|  | 5228 | { | 
|  | 5229 | typedef geometric_distribution<_IntType> _Eng; | 
|  | 5230 | typedef typename _Eng::param_type param_type; | 
|  | 5231 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5232 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5233 | double __p; | 
|  | 5234 | __is >> __p; | 
|  | 5235 | if (!__is.fail()) | 
|  | 5236 | __x.param(param_type(__p)); | 
|  | 5237 | return __is; | 
|  | 5238 | } | 
|  | 5239 |  | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5240 | // chi_squared_distribution | 
|  | 5241 |  | 
|  | 5242 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5243 | class _LIBCPP_VISIBLE chi_squared_distribution | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5244 | { | 
|  | 5245 | public: | 
|  | 5246 | // types | 
|  | 5247 | typedef _RealType result_type; | 
|  | 5248 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5249 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5250 | { | 
|  | 5251 | result_type __n_; | 
|  | 5252 | public: | 
|  | 5253 | typedef chi_squared_distribution distribution_type; | 
|  | 5254 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5255 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5256 | explicit param_type(result_type __n = 1) : __n_(__n) {} | 
|  | 5257 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5258 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5259 | result_type n() const {return __n_;} | 
|  | 5260 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5261 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5262 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5263 | {return __x.__n_ == __y.__n_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5264 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5265 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5266 | {return !(__x == __y);} | 
|  | 5267 | }; | 
|  | 5268 |  | 
|  | 5269 | private: | 
|  | 5270 | param_type __p_; | 
|  | 5271 |  | 
|  | 5272 | public: | 
|  | 5273 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5274 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5275 | explicit chi_squared_distribution(result_type __n = 1) | 
|  | 5276 | : __p_(param_type(__n)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5277 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5278 | explicit chi_squared_distribution(const param_type& __p) | 
|  | 5279 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5280 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5281 | void reset() {} | 
|  | 5282 |  | 
|  | 5283 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5284 | template<class _URNG> | 
|  | 5285 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5286 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5287 | {return (*this)(__g, __p_);} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5288 | template<class _URNG> | 
|  | 5289 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5290 | result_type operator()(_URNG& __g, const param_type& __p) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5291 | {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} | 
|  | 5292 |  | 
|  | 5293 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5294 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5295 | result_type n() const {return __p_.n();} | 
|  | 5296 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5297 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5298 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5299 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5300 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5301 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5302 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5303 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5304 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5305 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5306 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5307 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5308 | bool operator==(const chi_squared_distribution& __x, | 
|  | 5309 | const chi_squared_distribution& __y) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5310 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5311 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5312 | bool operator!=(const chi_squared_distribution& __x, | 
|  | 5313 | const chi_squared_distribution& __y) | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5314 | {return !(__x == __y);} | 
|  | 5315 | }; | 
|  | 5316 |  | 
|  | 5317 | template <class _CharT, class _Traits, class _RT> | 
|  | 5318 | basic_ostream<_CharT, _Traits>& | 
|  | 5319 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5320 | const chi_squared_distribution<_RT>& __x) | 
|  | 5321 | { | 
|  | 5322 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5323 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5324 | ios_base::scientific); | 
| Howard Hinnant | e390073 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5325 | __os << __x.n(); | 
|  | 5326 | return __os; | 
|  | 5327 | } | 
|  | 5328 |  | 
|  | 5329 | template <class _CharT, class _Traits, class _RT> | 
|  | 5330 | basic_istream<_CharT, _Traits>& | 
|  | 5331 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5332 | chi_squared_distribution<_RT>& __x) | 
|  | 5333 | { | 
|  | 5334 | typedef chi_squared_distribution<_RT> _Eng; | 
|  | 5335 | typedef typename _Eng::result_type result_type; | 
|  | 5336 | typedef typename _Eng::param_type param_type; | 
|  | 5337 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5338 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5339 | result_type __n; | 
|  | 5340 | __is >> __n; | 
|  | 5341 | if (!__is.fail()) | 
|  | 5342 | __x.param(param_type(__n)); | 
|  | 5343 | return __is; | 
|  | 5344 | } | 
|  | 5345 |  | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5346 | // cauchy_distribution | 
|  | 5347 |  | 
|  | 5348 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5349 | class _LIBCPP_VISIBLE cauchy_distribution | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5350 | { | 
|  | 5351 | public: | 
|  | 5352 | // types | 
|  | 5353 | typedef _RealType result_type; | 
|  | 5354 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5355 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5356 | { | 
|  | 5357 | result_type __a_; | 
|  | 5358 | result_type __b_; | 
|  | 5359 | public: | 
|  | 5360 | typedef cauchy_distribution distribution_type; | 
|  | 5361 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5362 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5363 | explicit param_type(result_type __a = 0, result_type __b = 1) | 
|  | 5364 | : __a_(__a), __b_(__b) {} | 
|  | 5365 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5366 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5367 | result_type a() const {return __a_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5368 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5369 | result_type b() const {return __b_;} | 
|  | 5370 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5371 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5372 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5373 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5374 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5375 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5376 | {return !(__x == __y);} | 
|  | 5377 | }; | 
|  | 5378 |  | 
|  | 5379 | private: | 
|  | 5380 | param_type __p_; | 
|  | 5381 |  | 
|  | 5382 | public: | 
|  | 5383 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5384 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5385 | explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) | 
|  | 5386 | : __p_(param_type(__a, __b)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5387 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5388 | explicit cauchy_distribution(const param_type& __p) | 
|  | 5389 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5390 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5391 | void reset() {} | 
|  | 5392 |  | 
|  | 5393 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5394 | template<class _URNG> | 
|  | 5395 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5396 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5397 | {return (*this)(__g, __p_);} | 
|  | 5398 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 5399 |  | 
|  | 5400 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5401 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5402 | result_type a() const {return __p_.a();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5403 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5404 | result_type b() const {return __p_.b();} | 
|  | 5405 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5406 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5407 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5408 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5409 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5410 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5411 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5412 | result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5413 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5414 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5415 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5416 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5417 | bool operator==(const cauchy_distribution& __x, | 
|  | 5418 | const cauchy_distribution& __y) | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5419 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5420 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5421 | bool operator!=(const cauchy_distribution& __x, | 
|  | 5422 | const cauchy_distribution& __y) | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5423 | {return !(__x == __y);} | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5424 | }; | 
|  | 5425 |  | 
|  | 5426 | template <class _RealType> | 
|  | 5427 | template<class _URNG> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5428 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5429 | _RealType | 
|  | 5430 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 5431 | { | 
|  | 5432 | uniform_real_distribution<result_type> __gen; | 
|  | 5433 | // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5434 | return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5435 | } | 
|  | 5436 |  | 
|  | 5437 | template <class _CharT, class _Traits, class _RT> | 
|  | 5438 | basic_ostream<_CharT, _Traits>& | 
|  | 5439 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5440 | const cauchy_distribution<_RT>& __x) | 
|  | 5441 | { | 
|  | 5442 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5443 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5444 | ios_base::scientific); | 
| Howard Hinnant | 6692b26 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5445 | _CharT __sp = __os.widen(' '); | 
|  | 5446 | __os.fill(__sp); | 
|  | 5447 | __os << __x.a() << __sp << __x.b(); | 
|  | 5448 | return __os; | 
|  | 5449 | } | 
|  | 5450 |  | 
|  | 5451 | template <class _CharT, class _Traits, class _RT> | 
|  | 5452 | basic_istream<_CharT, _Traits>& | 
|  | 5453 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5454 | cauchy_distribution<_RT>& __x) | 
|  | 5455 | { | 
|  | 5456 | typedef cauchy_distribution<_RT> _Eng; | 
|  | 5457 | typedef typename _Eng::result_type result_type; | 
|  | 5458 | typedef typename _Eng::param_type param_type; | 
|  | 5459 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5460 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5461 | result_type __a; | 
|  | 5462 | result_type __b; | 
|  | 5463 | __is >> __a >> __b; | 
|  | 5464 | if (!__is.fail()) | 
|  | 5465 | __x.param(param_type(__a, __b)); | 
|  | 5466 | return __is; | 
|  | 5467 | } | 
|  | 5468 |  | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5469 | // fisher_f_distribution | 
|  | 5470 |  | 
|  | 5471 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5472 | class _LIBCPP_VISIBLE fisher_f_distribution | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5473 | { | 
|  | 5474 | public: | 
|  | 5475 | // types | 
|  | 5476 | typedef _RealType result_type; | 
|  | 5477 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5478 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5479 | { | 
|  | 5480 | result_type __m_; | 
|  | 5481 | result_type __n_; | 
|  | 5482 | public: | 
|  | 5483 | typedef fisher_f_distribution distribution_type; | 
|  | 5484 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5485 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5486 | explicit param_type(result_type __m = 1, result_type __n = 1) | 
|  | 5487 | : __m_(__m), __n_(__n) {} | 
|  | 5488 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5489 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5490 | result_type m() const {return __m_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5491 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5492 | result_type n() const {return __n_;} | 
|  | 5493 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5494 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5495 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5496 | {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5497 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5498 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5499 | {return !(__x == __y);} | 
|  | 5500 | }; | 
|  | 5501 |  | 
|  | 5502 | private: | 
|  | 5503 | param_type __p_; | 
|  | 5504 |  | 
|  | 5505 | public: | 
|  | 5506 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5507 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5508 | explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) | 
|  | 5509 | : __p_(param_type(__m, __n)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5510 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5511 | explicit fisher_f_distribution(const param_type& __p) | 
|  | 5512 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5513 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5514 | void reset() {} | 
|  | 5515 |  | 
|  | 5516 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5517 | template<class _URNG> | 
|  | 5518 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5519 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5520 | {return (*this)(__g, __p_);} | 
|  | 5521 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 5522 |  | 
|  | 5523 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5524 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5525 | result_type m() const {return __p_.m();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5526 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5527 | result_type n() const {return __p_.n();} | 
|  | 5528 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5529 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5530 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5531 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5532 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5533 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5534 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5535 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5536 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5537 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5538 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5539 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5540 | bool operator==(const fisher_f_distribution& __x, | 
|  | 5541 | const fisher_f_distribution& __y) | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5542 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5543 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5544 | bool operator!=(const fisher_f_distribution& __x, | 
|  | 5545 | const fisher_f_distribution& __y) | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5546 | {return !(__x == __y);} | 
|  | 5547 | }; | 
|  | 5548 |  | 
|  | 5549 | template <class _RealType> | 
|  | 5550 | template<class _URNG> | 
|  | 5551 | _RealType | 
|  | 5552 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 5553 | { | 
|  | 5554 | gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); | 
|  | 5555 | gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); | 
|  | 5556 | return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); | 
|  | 5557 | } | 
|  | 5558 |  | 
|  | 5559 | template <class _CharT, class _Traits, class _RT> | 
|  | 5560 | basic_ostream<_CharT, _Traits>& | 
|  | 5561 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5562 | const fisher_f_distribution<_RT>& __x) | 
|  | 5563 | { | 
|  | 5564 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5565 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5566 | ios_base::scientific); | 
| Howard Hinnant | e31e36f | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5567 | _CharT __sp = __os.widen(' '); | 
|  | 5568 | __os.fill(__sp); | 
|  | 5569 | __os << __x.m() << __sp << __x.n(); | 
|  | 5570 | return __os; | 
|  | 5571 | } | 
|  | 5572 |  | 
|  | 5573 | template <class _CharT, class _Traits, class _RT> | 
|  | 5574 | basic_istream<_CharT, _Traits>& | 
|  | 5575 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5576 | fisher_f_distribution<_RT>& __x) | 
|  | 5577 | { | 
|  | 5578 | typedef fisher_f_distribution<_RT> _Eng; | 
|  | 5579 | typedef typename _Eng::result_type result_type; | 
|  | 5580 | typedef typename _Eng::param_type param_type; | 
|  | 5581 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5582 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5583 | result_type __m; | 
|  | 5584 | result_type __n; | 
|  | 5585 | __is >> __m >> __n; | 
|  | 5586 | if (!__is.fail()) | 
|  | 5587 | __x.param(param_type(__m, __n)); | 
|  | 5588 | return __is; | 
|  | 5589 | } | 
|  | 5590 |  | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5591 | // student_t_distribution | 
|  | 5592 |  | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5593 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5594 | class _LIBCPP_VISIBLE student_t_distribution | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5595 | { | 
|  | 5596 | public: | 
|  | 5597 | // types | 
|  | 5598 | typedef _RealType result_type; | 
|  | 5599 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5600 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5601 | { | 
|  | 5602 | result_type __n_; | 
|  | 5603 | public: | 
|  | 5604 | typedef student_t_distribution distribution_type; | 
|  | 5605 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5606 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5607 | explicit param_type(result_type __n = 1) : __n_(__n) {} | 
|  | 5608 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5609 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5610 | result_type n() const {return __n_;} | 
|  | 5611 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5612 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5613 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5614 | {return __x.__n_ == __y.__n_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5615 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5616 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5617 | {return !(__x == __y);} | 
|  | 5618 | }; | 
|  | 5619 |  | 
|  | 5620 | private: | 
|  | 5621 | param_type __p_; | 
|  | 5622 | normal_distribution<result_type> __nd_; | 
|  | 5623 |  | 
|  | 5624 | public: | 
|  | 5625 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5626 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5627 | explicit student_t_distribution(result_type __n = 1) | 
|  | 5628 | : __p_(param_type(__n)) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5629 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5630 | explicit student_t_distribution(const param_type& __p) | 
|  | 5631 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5632 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5633 | void reset() {__nd_.reset();} | 
|  | 5634 |  | 
|  | 5635 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5636 | template<class _URNG> | 
|  | 5637 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5638 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5639 | {return (*this)(__g, __p_);} | 
|  | 5640 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 5641 |  | 
|  | 5642 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5643 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5644 | result_type n() const {return __p_.n();} | 
|  | 5645 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5646 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5647 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5648 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5649 | void param(const param_type& __p) {__p_ = __p;} | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5650 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5651 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5652 | result_type min() const {return -numeric_limits<result_type>::infinity();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5653 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5654 | result_type max() const {return numeric_limits<result_type>::infinity();} | 
|  | 5655 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5656 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5657 | bool operator==(const student_t_distribution& __x, | 
|  | 5658 | const student_t_distribution& __y) | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5659 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5660 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5661 | bool operator!=(const student_t_distribution& __x, | 
|  | 5662 | const student_t_distribution& __y) | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5663 | {return !(__x == __y);} | 
|  | 5664 | }; | 
|  | 5665 |  | 
|  | 5666 | template <class _RealType> | 
|  | 5667 | template<class _URNG> | 
|  | 5668 | _RealType | 
|  | 5669 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 5670 | { | 
|  | 5671 | gamma_distribution<result_type> __gd(__p.n() * .5, 2); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5672 | return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5673 | } | 
|  | 5674 |  | 
|  | 5675 | template <class _CharT, class _Traits, class _RT> | 
|  | 5676 | basic_ostream<_CharT, _Traits>& | 
|  | 5677 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5678 | const student_t_distribution<_RT>& __x) | 
|  | 5679 | { | 
|  | 5680 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5681 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5682 | ios_base::scientific); | 
| Howard Hinnant | ecbb921 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5683 | __os << __x.n(); | 
|  | 5684 | return __os; | 
|  | 5685 | } | 
|  | 5686 |  | 
|  | 5687 | template <class _CharT, class _Traits, class _RT> | 
|  | 5688 | basic_istream<_CharT, _Traits>& | 
|  | 5689 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5690 | student_t_distribution<_RT>& __x) | 
|  | 5691 | { | 
|  | 5692 | typedef student_t_distribution<_RT> _Eng; | 
|  | 5693 | typedef typename _Eng::result_type result_type; | 
|  | 5694 | typedef typename _Eng::param_type param_type; | 
|  | 5695 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5696 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5697 | result_type __n; | 
|  | 5698 | __is >> __n; | 
|  | 5699 | if (!__is.fail()) | 
|  | 5700 | __x.param(param_type(__n)); | 
|  | 5701 | return __is; | 
|  | 5702 | } | 
|  | 5703 |  | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5704 | // discrete_distribution | 
|  | 5705 |  | 
|  | 5706 | template<class _IntType = int> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5707 | class _LIBCPP_VISIBLE discrete_distribution | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5708 | { | 
|  | 5709 | public: | 
|  | 5710 | // types | 
|  | 5711 | typedef _IntType result_type; | 
|  | 5712 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5713 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5714 | { | 
|  | 5715 | vector<double> __p_; | 
|  | 5716 | public: | 
|  | 5717 | typedef discrete_distribution distribution_type; | 
|  | 5718 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5719 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5720 | param_type() {} | 
|  | 5721 | template<class _InputIterator> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5722 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5723 | param_type(_InputIterator __f, _InputIterator __l) | 
|  | 5724 | : __p_(__f, __l) {__init();} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5725 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5726 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5727 | param_type(initializer_list<double> __wl) | 
|  | 5728 | : __p_(__wl.begin(), __wl.end()) {__init();} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5729 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5730 | template<class _UnaryOperation> | 
|  | 5731 | param_type(size_t __nw, double __xmin, double __xmax, | 
|  | 5732 | _UnaryOperation __fw); | 
|  | 5733 |  | 
|  | 5734 | vector<double> probabilities() const; | 
|  | 5735 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5736 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5737 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5738 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5739 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5740 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5741 | {return !(__x == __y);} | 
|  | 5742 |  | 
|  | 5743 | private: | 
|  | 5744 | void __init(); | 
|  | 5745 |  | 
|  | 5746 | friend class discrete_distribution; | 
|  | 5747 |  | 
|  | 5748 | template <class _CharT, class _Traits, class _IT> | 
|  | 5749 | friend | 
|  | 5750 | basic_ostream<_CharT, _Traits>& | 
|  | 5751 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5752 | const discrete_distribution<_IT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5753 |  | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5754 | template <class _CharT, class _Traits, class _IT> | 
|  | 5755 | friend | 
|  | 5756 | basic_istream<_CharT, _Traits>& | 
|  | 5757 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5758 | discrete_distribution<_IT>& __x); | 
|  | 5759 | }; | 
|  | 5760 |  | 
|  | 5761 | private: | 
|  | 5762 | param_type __p_; | 
|  | 5763 |  | 
|  | 5764 | public: | 
|  | 5765 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5766 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5767 | discrete_distribution() {} | 
|  | 5768 | template<class _InputIterator> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5769 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5770 | discrete_distribution(_InputIterator __f, _InputIterator __l) | 
|  | 5771 | : __p_(__f, __l) {} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5772 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5773 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5774 | discrete_distribution(initializer_list<double> __wl) | 
|  | 5775 | : __p_(__wl) {} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5776 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5777 | template<class _UnaryOperation> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5778 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5779 | discrete_distribution(size_t __nw, double __xmin, double __xmax, | 
|  | 5780 | _UnaryOperation __fw) | 
|  | 5781 | : __p_(__nw, __xmin, __xmax, __fw) {} | 
|  | 5782 | explicit discrete_distribution(const param_type& __p) | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5783 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5784 | : __p_(__p) {} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5785 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5786 | void reset() {} | 
|  | 5787 |  | 
|  | 5788 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5789 | template<class _URNG> | 
|  | 5790 | _LIBCPP_INLINE_VISIBILITY | 
|  | 5791 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5792 | {return (*this)(__g, __p_);} | 
|  | 5793 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 5794 |  | 
|  | 5795 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5796 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5797 | vector<double> probabilities() const {return __p_.probabilities();} | 
|  | 5798 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5799 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5800 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5801 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5802 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 5803 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5804 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5805 | result_type min() const {return 0;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5806 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5807 | result_type max() const {return __p_.__p_.size();} | 
|  | 5808 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5809 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5810 | bool operator==(const discrete_distribution& __x, | 
|  | 5811 | const discrete_distribution& __y) | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5812 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5813 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5814 | bool operator!=(const discrete_distribution& __x, | 
|  | 5815 | const discrete_distribution& __y) | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5816 | {return !(__x == __y);} | 
|  | 5817 |  | 
|  | 5818 | template <class _CharT, class _Traits, class _IT> | 
|  | 5819 | friend | 
|  | 5820 | basic_ostream<_CharT, _Traits>& | 
|  | 5821 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5822 | const discrete_distribution<_IT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5823 |  | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5824 | template <class _CharT, class _Traits, class _IT> | 
|  | 5825 | friend | 
|  | 5826 | basic_istream<_CharT, _Traits>& | 
|  | 5827 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5828 | discrete_distribution<_IT>& __x); | 
|  | 5829 | }; | 
|  | 5830 |  | 
|  | 5831 | template<class _IntType> | 
|  | 5832 | template<class _UnaryOperation> | 
|  | 5833 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, | 
|  | 5834 | double __xmin, | 
|  | 5835 | double __xmax, | 
|  | 5836 | _UnaryOperation __fw) | 
|  | 5837 | { | 
|  | 5838 | if (__nw > 1) | 
|  | 5839 | { | 
|  | 5840 | __p_.reserve(__nw - 1); | 
|  | 5841 | double __d = (__xmax - __xmin) / __nw; | 
|  | 5842 | double __d2 = __d / 2; | 
|  | 5843 | for (size_t __k = 0; __k < __nw; ++__k) | 
|  | 5844 | __p_.push_back(__fw(__xmin + __k * __d + __d2)); | 
|  | 5845 | __init(); | 
|  | 5846 | } | 
|  | 5847 | } | 
|  | 5848 |  | 
|  | 5849 | template<class _IntType> | 
|  | 5850 | void | 
|  | 5851 | discrete_distribution<_IntType>::param_type::__init() | 
|  | 5852 | { | 
|  | 5853 | if (!__p_.empty()) | 
|  | 5854 | { | 
|  | 5855 | if (__p_.size() > 1) | 
|  | 5856 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5857 | double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); | 
|  | 5858 | for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5859 | __i < __e; ++__i) | 
|  | 5860 | *__i /= __s; | 
|  | 5861 | vector<double> __t(__p_.size() - 1); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5862 | _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5863 | swap(__p_, __t); | 
|  | 5864 | } | 
|  | 5865 | else | 
|  | 5866 | { | 
|  | 5867 | __p_.clear(); | 
|  | 5868 | __p_.shrink_to_fit(); | 
|  | 5869 | } | 
|  | 5870 | } | 
|  | 5871 | } | 
|  | 5872 |  | 
|  | 5873 | template<class _IntType> | 
|  | 5874 | vector<double> | 
|  | 5875 | discrete_distribution<_IntType>::param_type::probabilities() const | 
|  | 5876 | { | 
|  | 5877 | size_t __n = __p_.size(); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5878 | _VSTD::vector<double> __p(__n+1); | 
|  | 5879 | _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5880 | if (__n > 0) | 
|  | 5881 | __p[__n] = 1 - __p_[__n-1]; | 
|  | 5882 | else | 
|  | 5883 | __p[0] = 1; | 
|  | 5884 | return __p; | 
|  | 5885 | } | 
|  | 5886 |  | 
|  | 5887 | template<class _IntType> | 
|  | 5888 | template<class _URNG> | 
|  | 5889 | _IntType | 
|  | 5890 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 5891 | { | 
|  | 5892 | uniform_real_distribution<double> __gen; | 
|  | 5893 | return static_cast<_IntType>( | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5894 | _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5895 | __p.__p_.begin()); | 
|  | 5896 | } | 
|  | 5897 |  | 
|  | 5898 | template <class _CharT, class _Traits, class _IT> | 
|  | 5899 | basic_ostream<_CharT, _Traits>& | 
|  | 5900 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5901 | const discrete_distribution<_IT>& __x) | 
|  | 5902 | { | 
|  | 5903 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5904 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 5905 | ios_base::scientific); | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5906 | _CharT __sp = __os.widen(' '); | 
|  | 5907 | __os.fill(__sp); | 
|  | 5908 | size_t __n = __x.__p_.__p_.size(); | 
|  | 5909 | __os << __n; | 
|  | 5910 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 5911 | __os << __sp << __x.__p_.__p_[__i]; | 
|  | 5912 | return __os; | 
|  | 5913 | } | 
|  | 5914 |  | 
|  | 5915 | template <class _CharT, class _Traits, class _IT> | 
|  | 5916 | basic_istream<_CharT, _Traits>& | 
|  | 5917 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5918 | discrete_distribution<_IT>& __x) | 
|  | 5919 | { | 
|  | 5920 | typedef discrete_distribution<_IT> _Eng; | 
|  | 5921 | typedef typename _Eng::result_type result_type; | 
|  | 5922 | typedef typename _Eng::param_type param_type; | 
|  | 5923 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 5924 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 5925 | size_t __n; | 
|  | 5926 | __is >> __n; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5927 | vector<double> __p(__n); | 
| Howard Hinnant | fb0e5ec | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5928 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 5929 | __is >> __p[__i]; | 
|  | 5930 | if (!__is.fail()) | 
|  | 5931 | swap(__x.__p_.__p_, __p); | 
|  | 5932 | return __is; | 
|  | 5933 | } | 
|  | 5934 |  | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5935 | // piecewise_constant_distribution | 
|  | 5936 |  | 
|  | 5937 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5938 | class _LIBCPP_VISIBLE piecewise_constant_distribution | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5939 | { | 
|  | 5940 | public: | 
|  | 5941 | // types | 
|  | 5942 | typedef _RealType result_type; | 
|  | 5943 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5944 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5945 | { | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5946 | vector<result_type> __b_; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 5947 | vector<result_type> __densities_; | 
|  | 5948 | vector<result_type> __areas_; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5949 | public: | 
|  | 5950 | typedef piecewise_constant_distribution distribution_type; | 
|  | 5951 |  | 
|  | 5952 | param_type(); | 
|  | 5953 | template<class _InputIteratorB, class _InputIteratorW> | 
|  | 5954 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, | 
|  | 5955 | _InputIteratorW __fW); | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5956 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5957 | template<class _UnaryOperation> | 
|  | 5958 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 5959 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5960 | template<class _UnaryOperation> | 
|  | 5961 | param_type(size_t __nw, result_type __xmin, result_type __xmax, | 
|  | 5962 | _UnaryOperation __fw); | 
| Howard Hinnant | e79d71e | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 5963 | param_type & operator=(const param_type& __rhs); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5964 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5965 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5966 | vector<result_type> intervals() const {return __b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5967 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 5968 | vector<result_type> densities() const {return __densities_;} | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5969 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5970 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5971 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5972 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5973 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 5974 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5975 | {return !(__x == __y);} | 
|  | 5976 |  | 
|  | 5977 | private: | 
|  | 5978 | void __init(); | 
|  | 5979 |  | 
|  | 5980 | friend class piecewise_constant_distribution; | 
|  | 5981 |  | 
|  | 5982 | template <class _CharT, class _Traits, class _RT> | 
|  | 5983 | friend | 
|  | 5984 | basic_ostream<_CharT, _Traits>& | 
|  | 5985 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 5986 | const piecewise_constant_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5987 |  | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 5988 | template <class _CharT, class _Traits, class _RT> | 
|  | 5989 | friend | 
|  | 5990 | basic_istream<_CharT, _Traits>& | 
|  | 5991 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 5992 | piecewise_constant_distribution<_RT>& __x); | 
|  | 5993 | }; | 
|  | 5994 |  | 
|  | 5995 | private: | 
|  | 5996 | param_type __p_; | 
|  | 5997 |  | 
|  | 5998 | public: | 
|  | 5999 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6000 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6001 | piecewise_constant_distribution() {} | 
|  | 6002 | template<class _InputIteratorB, class _InputIteratorW> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6003 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6004 | piecewise_constant_distribution(_InputIteratorB __fB, | 
|  | 6005 | _InputIteratorB __lB, | 
|  | 6006 | _InputIteratorW __fW) | 
|  | 6007 | : __p_(__fB, __lB, __fW) {} | 
|  | 6008 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6009 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6010 | template<class _UnaryOperation> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6011 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6012 | piecewise_constant_distribution(initializer_list<result_type> __bl, | 
|  | 6013 | _UnaryOperation __fw) | 
|  | 6014 | : __p_(__bl, __fw) {} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6015 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6016 |  | 
|  | 6017 | template<class _UnaryOperation> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6018 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6019 | piecewise_constant_distribution(size_t __nw, result_type __xmin, | 
|  | 6020 | result_type __xmax, _UnaryOperation __fw) | 
|  | 6021 | : __p_(__nw, __xmin, __xmax, __fw) {} | 
|  | 6022 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6023 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6024 | explicit piecewise_constant_distribution(const param_type& __p) | 
|  | 6025 | : __p_(__p) {} | 
|  | 6026 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6027 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6028 | void reset() {} | 
|  | 6029 |  | 
|  | 6030 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6031 | template<class _URNG> | 
|  | 6032 | _LIBCPP_INLINE_VISIBILITY | 
|  | 6033 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6034 | {return (*this)(__g, __p_);} | 
|  | 6035 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 6036 |  | 
|  | 6037 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6038 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6039 | vector<result_type> intervals() const {return __p_.intervals();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6040 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6041 | vector<result_type> densities() const {return __p_.densities();} | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6042 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6043 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6044 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6045 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6046 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 6047 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6048 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6049 | result_type min() const {return __p_.__b_.front();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6050 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6051 | result_type max() const {return __p_.__b_.back();} | 
|  | 6052 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6053 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6054 | bool operator==(const piecewise_constant_distribution& __x, | 
|  | 6055 | const piecewise_constant_distribution& __y) | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6056 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6057 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6058 | bool operator!=(const piecewise_constant_distribution& __x, | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6059 | const piecewise_constant_distribution& __y) | 
|  | 6060 | {return !(__x == __y);} | 
|  | 6061 |  | 
|  | 6062 | template <class _CharT, class _Traits, class _RT> | 
|  | 6063 | friend | 
|  | 6064 | basic_ostream<_CharT, _Traits>& | 
|  | 6065 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 6066 | const piecewise_constant_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6067 |  | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6068 | template <class _CharT, class _Traits, class _RT> | 
|  | 6069 | friend | 
|  | 6070 | basic_istream<_CharT, _Traits>& | 
|  | 6071 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 6072 | piecewise_constant_distribution<_RT>& __x); | 
|  | 6073 | }; | 
|  | 6074 |  | 
|  | 6075 | template<class _RealType> | 
| Howard Hinnant | e79d71e | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6076 | typename piecewise_constant_distribution<_RealType>::param_type & | 
|  | 6077 | piecewise_constant_distribution<_RealType>::param_type::operator= | 
|  | 6078 | (const param_type& __rhs) | 
|  | 6079 | { | 
|  | 6080 | //  These can throw | 
|  | 6081 | __b_.reserve        (__rhs.__b_.size ()); | 
|  | 6082 | __densities_.reserve(__rhs.__densities_.size()); | 
|  | 6083 | __areas_.reserve    (__rhs.__areas_.size()); | 
|  | 6084 |  | 
|  | 6085 | //  These can not throw | 
|  | 6086 | __b_         = __rhs.__b_; | 
|  | 6087 | __densities_ = __rhs.__densities_; | 
|  | 6088 | __areas_     =  __rhs.__areas_; | 
|  | 6089 | return *this; | 
|  | 6090 | } | 
|  | 6091 |  | 
|  | 6092 | template<class _RealType> | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6093 | void | 
|  | 6094 | piecewise_constant_distribution<_RealType>::param_type::__init() | 
|  | 6095 | { | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6096 | // __densities_ contains non-normalized areas | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6097 | result_type __total_area = _VSTD::accumulate(__densities_.begin(), | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6098 | __densities_.end(), | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6099 | result_type()); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6100 | for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
|  | 6101 | __densities_[__i] /= __total_area; | 
|  | 6102 | // __densities_ contains normalized areas | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6103 | __areas_.assign(__densities_.size(), result_type()); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6104 | _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6105 | __areas_.begin() + 1); | 
|  | 6106 | // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] | 
|  | 6107 | __densities_.back() = 1 - __areas_.back();  // correct round off error | 
|  | 6108 | for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
|  | 6109 | __densities_[__i] /= (__b_[__i+1] - __b_[__i]); | 
|  | 6110 | // __densities_ now contains __densities_ | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6111 | } | 
|  | 6112 |  | 
|  | 6113 | template<class _RealType> | 
|  | 6114 | piecewise_constant_distribution<_RealType>::param_type::param_type() | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6115 | : __b_(2), | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6116 | __densities_(1, 1.0), | 
|  | 6117 | __areas_(1, 0.0) | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6118 | { | 
|  | 6119 | __b_[1] = 1; | 
|  | 6120 | } | 
|  | 6121 |  | 
|  | 6122 | template<class _RealType> | 
|  | 6123 | template<class _InputIteratorB, class _InputIteratorW> | 
|  | 6124 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
|  | 6125 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) | 
|  | 6126 | : __b_(__fB, __lB) | 
|  | 6127 | { | 
|  | 6128 | if (__b_.size() < 2) | 
|  | 6129 | { | 
|  | 6130 | __b_.resize(2); | 
|  | 6131 | __b_[0] = 0; | 
|  | 6132 | __b_[1] = 1; | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6133 | __densities_.assign(1, 1.0); | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6134 | __areas_.assign(1, 0.0); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6135 | } | 
|  | 6136 | else | 
|  | 6137 | { | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6138 | __densities_.reserve(__b_.size() - 1); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6139 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6140 | __densities_.push_back(*__fW); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6141 | __init(); | 
|  | 6142 | } | 
|  | 6143 | } | 
|  | 6144 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6145 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 6146 |  | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6147 | template<class _RealType> | 
|  | 6148 | template<class _UnaryOperation> | 
|  | 6149 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
|  | 6150 | initializer_list<result_type> __bl, _UnaryOperation __fw) | 
|  | 6151 | : __b_(__bl.begin(), __bl.end()) | 
|  | 6152 | { | 
|  | 6153 | if (__b_.size() < 2) | 
|  | 6154 | { | 
|  | 6155 | __b_.resize(2); | 
|  | 6156 | __b_[0] = 0; | 
|  | 6157 | __b_[1] = 1; | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6158 | __densities_.assign(1, 1.0); | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6159 | __areas_.assign(1, 0.0); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6160 | } | 
|  | 6161 | else | 
|  | 6162 | { | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6163 | __densities_.reserve(__b_.size() - 1); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6164 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i) | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6165 | __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6166 | __init(); | 
|  | 6167 | } | 
|  | 6168 | } | 
|  | 6169 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6170 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 6171 |  | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6172 | template<class _RealType> | 
|  | 6173 | template<class _UnaryOperation> | 
|  | 6174 | piecewise_constant_distribution<_RealType>::param_type::param_type( | 
|  | 6175 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) | 
|  | 6176 | : __b_(__nw == 0 ? 2 : __nw + 1) | 
|  | 6177 | { | 
|  | 6178 | size_t __n = __b_.size() - 1; | 
|  | 6179 | result_type __d = (__xmax - __xmin) / __n; | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6180 | __densities_.reserve(__n); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6181 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6182 | { | 
|  | 6183 | __b_[__i] = __xmin + __i * __d; | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6184 | __densities_.push_back(__fw(__b_[__i] + __d*.5)); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6185 | } | 
|  | 6186 | __b_[__n] = __xmax; | 
|  | 6187 | __init(); | 
|  | 6188 | } | 
|  | 6189 |  | 
|  | 6190 | template<class _RealType> | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6191 | template<class _URNG> | 
|  | 6192 | _RealType | 
|  | 6193 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 6194 | { | 
|  | 6195 | typedef uniform_real_distribution<result_type> _Gen; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6196 | result_type __u = _Gen()(__g); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6197 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6198 | __u) - __p.__areas_.begin() - 1; | 
|  | 6199 | return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6200 | } | 
|  | 6201 |  | 
|  | 6202 | template <class _CharT, class _Traits, class _RT> | 
|  | 6203 | basic_ostream<_CharT, _Traits>& | 
|  | 6204 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 6205 | const piecewise_constant_distribution<_RT>& __x) | 
|  | 6206 | { | 
|  | 6207 | __save_flags<_CharT, _Traits> _(__os); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6208 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 6209 | ios_base::scientific); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6210 | _CharT __sp = __os.widen(' '); | 
|  | 6211 | __os.fill(__sp); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6212 | size_t __n = __x.__p_.__b_.size(); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6213 | __os << __n; | 
|  | 6214 | for (size_t __i = 0; __i < __n; ++__i) | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6215 | __os << __sp << __x.__p_.__b_[__i]; | 
|  | 6216 | __n = __x.__p_.__densities_.size(); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6217 | __os << __sp << __n; | 
|  | 6218 | for (size_t __i = 0; __i < __n; ++__i) | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6219 | __os << __sp << __x.__p_.__densities_[__i]; | 
|  | 6220 | __n = __x.__p_.__areas_.size(); | 
|  | 6221 | __os << __sp << __n; | 
|  | 6222 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6223 | __os << __sp << __x.__p_.__areas_[__i]; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6224 | return __os; | 
|  | 6225 | } | 
|  | 6226 |  | 
|  | 6227 | template <class _CharT, class _Traits, class _RT> | 
|  | 6228 | basic_istream<_CharT, _Traits>& | 
|  | 6229 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 6230 | piecewise_constant_distribution<_RT>& __x) | 
|  | 6231 | { | 
|  | 6232 | typedef piecewise_constant_distribution<_RT> _Eng; | 
|  | 6233 | typedef typename _Eng::result_type result_type; | 
|  | 6234 | typedef typename _Eng::param_type param_type; | 
|  | 6235 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 6236 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 6237 | size_t __n; | 
|  | 6238 | __is >> __n; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6239 | vector<result_type> __b(__n); | 
|  | 6240 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6241 | __is >> __b[__i]; | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6242 | __is >> __n; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6243 | vector<result_type> __densities(__n); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6244 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6245 | __is >> __densities[__i]; | 
|  | 6246 | __is >> __n; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6247 | vector<result_type> __areas(__n); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6248 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6249 | __is >> __areas[__i]; | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6250 | if (!__is.fail()) | 
|  | 6251 | { | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6252 | swap(__x.__p_.__b_, __b); | 
| Howard Hinnant | 5d6a2e5 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6253 | swap(__x.__p_.__densities_, __densities); | 
|  | 6254 | swap(__x.__p_.__areas_, __areas); | 
| Howard Hinnant | e302eab | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6255 | } | 
|  | 6256 | return __is; | 
|  | 6257 | } | 
|  | 6258 |  | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6259 | // piecewise_linear_distribution | 
|  | 6260 |  | 
|  | 6261 | template<class _RealType = double> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6262 | class _LIBCPP_VISIBLE piecewise_linear_distribution | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6263 | { | 
|  | 6264 | public: | 
|  | 6265 | // types | 
|  | 6266 | typedef _RealType result_type; | 
|  | 6267 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6268 | class _LIBCPP_VISIBLE param_type | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6269 | { | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6270 | vector<result_type> __b_; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6271 | vector<result_type> __densities_; | 
|  | 6272 | vector<result_type> __areas_; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6273 | public: | 
|  | 6274 | typedef piecewise_linear_distribution distribution_type; | 
|  | 6275 |  | 
|  | 6276 | param_type(); | 
|  | 6277 | template<class _InputIteratorB, class _InputIteratorW> | 
|  | 6278 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, | 
|  | 6279 | _InputIteratorW __fW); | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6280 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6281 | template<class _UnaryOperation> | 
|  | 6282 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6283 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6284 | template<class _UnaryOperation> | 
|  | 6285 | param_type(size_t __nw, result_type __xmin, result_type __xmax, | 
|  | 6286 | _UnaryOperation __fw); | 
| Howard Hinnant | e79d71e | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6287 | param_type & operator=(const param_type& __rhs); | 
|  | 6288 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6289 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6290 | vector<result_type> intervals() const {return __b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6291 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6292 | vector<result_type> densities() const {return __densities_;} | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6293 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6294 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6295 | bool operator==(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6296 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6297 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6298 | bool operator!=(const param_type& __x, const param_type& __y) | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6299 | {return !(__x == __y);} | 
|  | 6300 |  | 
|  | 6301 | private: | 
|  | 6302 | void __init(); | 
|  | 6303 |  | 
|  | 6304 | friend class piecewise_linear_distribution; | 
|  | 6305 |  | 
|  | 6306 | template <class _CharT, class _Traits, class _RT> | 
|  | 6307 | friend | 
|  | 6308 | basic_ostream<_CharT, _Traits>& | 
|  | 6309 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 6310 | const piecewise_linear_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6311 |  | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6312 | template <class _CharT, class _Traits, class _RT> | 
|  | 6313 | friend | 
|  | 6314 | basic_istream<_CharT, _Traits>& | 
|  | 6315 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 6316 | piecewise_linear_distribution<_RT>& __x); | 
|  | 6317 | }; | 
|  | 6318 |  | 
|  | 6319 | private: | 
|  | 6320 | param_type __p_; | 
|  | 6321 |  | 
|  | 6322 | public: | 
|  | 6323 | // constructor and reset functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6324 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6325 | piecewise_linear_distribution() {} | 
|  | 6326 | template<class _InputIteratorB, class _InputIteratorW> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6327 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6328 | piecewise_linear_distribution(_InputIteratorB __fB, | 
|  | 6329 | _InputIteratorB __lB, | 
|  | 6330 | _InputIteratorW __fW) | 
|  | 6331 | : __p_(__fB, __lB, __fW) {} | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6332 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6333 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6334 | template<class _UnaryOperation> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6335 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6336 | piecewise_linear_distribution(initializer_list<result_type> __bl, | 
|  | 6337 | _UnaryOperation __fw) | 
|  | 6338 | : __p_(__bl, __fw) {} | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6339 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6340 |  | 
|  | 6341 | template<class _UnaryOperation> | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6342 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6343 | piecewise_linear_distribution(size_t __nw, result_type __xmin, | 
|  | 6344 | result_type __xmax, _UnaryOperation __fw) | 
|  | 6345 | : __p_(__nw, __xmin, __xmax, __fw) {} | 
|  | 6346 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6347 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6348 | explicit piecewise_linear_distribution(const param_type& __p) | 
|  | 6349 | : __p_(__p) {} | 
|  | 6350 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6351 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6352 | void reset() {} | 
|  | 6353 |  | 
|  | 6354 | // generating functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6355 | template<class _URNG> | 
|  | 6356 | _LIBCPP_INLINE_VISIBILITY | 
|  | 6357 | result_type operator()(_URNG& __g) | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6358 | {return (*this)(__g, __p_);} | 
|  | 6359 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); | 
|  | 6360 |  | 
|  | 6361 | // property functions | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6362 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6363 | vector<result_type> intervals() const {return __p_.intervals();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6364 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6365 | vector<result_type> densities() const {return __p_.densities();} | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6366 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6367 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6368 | param_type param() const {return __p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6369 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6370 | void param(const param_type& __p) {__p_ = __p;} | 
|  | 6371 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6372 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6373 | result_type min() const {return __p_.__b_.front();} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6374 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6375 | result_type max() const {return __p_.__b_.back();} | 
|  | 6376 |  | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6377 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6378 | bool operator==(const piecewise_linear_distribution& __x, | 
|  | 6379 | const piecewise_linear_distribution& __y) | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6380 | {return __x.__p_ == __y.__p_;} | 
| Howard Hinnant | 392183f | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6381 | friend _LIBCPP_INLINE_VISIBILITY | 
|  | 6382 | bool operator!=(const piecewise_linear_distribution& __x, | 
|  | 6383 | const piecewise_linear_distribution& __y) | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6384 | {return !(__x == __y);} | 
|  | 6385 |  | 
|  | 6386 | template <class _CharT, class _Traits, class _RT> | 
|  | 6387 | friend | 
|  | 6388 | basic_ostream<_CharT, _Traits>& | 
|  | 6389 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 6390 | const piecewise_linear_distribution<_RT>& __x); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6391 |  | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6392 | template <class _CharT, class _Traits, class _RT> | 
|  | 6393 | friend | 
|  | 6394 | basic_istream<_CharT, _Traits>& | 
|  | 6395 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 6396 | piecewise_linear_distribution<_RT>& __x); | 
|  | 6397 | }; | 
|  | 6398 |  | 
|  | 6399 | template<class _RealType> | 
| Howard Hinnant | e79d71e | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6400 | typename piecewise_linear_distribution<_RealType>::param_type & | 
|  | 6401 | piecewise_linear_distribution<_RealType>::param_type::operator= | 
|  | 6402 | (const param_type& __rhs) | 
|  | 6403 | { | 
|  | 6404 | //  These can throw | 
|  | 6405 | __b_.reserve        (__rhs.__b_.size ()); | 
|  | 6406 | __densities_.reserve(__rhs.__densities_.size()); | 
|  | 6407 | __areas_.reserve    (__rhs.__areas_.size()); | 
|  | 6408 |  | 
|  | 6409 | //  These can not throw | 
|  | 6410 | __b_         = __rhs.__b_; | 
|  | 6411 | __densities_ = __rhs.__densities_; | 
|  | 6412 | __areas_     =  __rhs.__areas_; | 
|  | 6413 | return *this; | 
|  | 6414 | } | 
|  | 6415 |  | 
|  | 6416 |  | 
|  | 6417 | template<class _RealType> | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6418 | void | 
|  | 6419 | piecewise_linear_distribution<_RealType>::param_type::__init() | 
|  | 6420 | { | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6421 | __areas_.assign(__densities_.size() - 1, result_type()); | 
|  | 6422 | result_type _S = 0; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6423 | for (size_t __i = 0; __i < __areas_.size(); ++__i) | 
|  | 6424 | { | 
|  | 6425 | __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * | 
|  | 6426 | (__b_[__i+1] - __b_[__i]) * .5; | 
|  | 6427 | _S += __areas_[__i]; | 
|  | 6428 | } | 
|  | 6429 | for (size_t __i = __areas_.size(); __i > 1;) | 
|  | 6430 | { | 
|  | 6431 | --__i; | 
|  | 6432 | __areas_[__i] = __areas_[__i-1] / _S; | 
|  | 6433 | } | 
|  | 6434 | __areas_[0] = 0; | 
|  | 6435 | for (size_t __i = 1; __i < __areas_.size(); ++__i) | 
|  | 6436 | __areas_[__i] += __areas_[__i-1]; | 
|  | 6437 | for (size_t __i = 0; __i < __densities_.size(); ++__i) | 
|  | 6438 | __densities_[__i] /= _S; | 
|  | 6439 | } | 
|  | 6440 |  | 
|  | 6441 | template<class _RealType> | 
|  | 6442 | piecewise_linear_distribution<_RealType>::param_type::param_type() | 
|  | 6443 | : __b_(2), | 
|  | 6444 | __densities_(2, 1.0), | 
|  | 6445 | __areas_(1, 0.0) | 
|  | 6446 | { | 
|  | 6447 | __b_[1] = 1; | 
|  | 6448 | } | 
|  | 6449 |  | 
|  | 6450 | template<class _RealType> | 
|  | 6451 | template<class _InputIteratorB, class _InputIteratorW> | 
|  | 6452 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
|  | 6453 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) | 
|  | 6454 | : __b_(__fB, __lB) | 
|  | 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, ++__fW) | 
|  | 6468 | __densities_.push_back(*__fW); | 
|  | 6469 | __init(); | 
|  | 6470 | } | 
|  | 6471 | } | 
|  | 6472 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6473 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 6474 |  | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6475 | template<class _RealType> | 
|  | 6476 | template<class _UnaryOperation> | 
|  | 6477 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
|  | 6478 | initializer_list<result_type> __bl, _UnaryOperation __fw) | 
|  | 6479 | : __b_(__bl.begin(), __bl.end()) | 
|  | 6480 | { | 
|  | 6481 | if (__b_.size() < 2) | 
|  | 6482 | { | 
|  | 6483 | __b_.resize(2); | 
|  | 6484 | __b_[0] = 0; | 
|  | 6485 | __b_[1] = 1; | 
|  | 6486 | __densities_.assign(2, 1.0); | 
|  | 6487 | __areas_.assign(1, 0.0); | 
|  | 6488 | } | 
|  | 6489 | else | 
|  | 6490 | { | 
|  | 6491 | __densities_.reserve(__b_.size()); | 
|  | 6492 | for (size_t __i = 0; __i < __b_.size(); ++__i) | 
|  | 6493 | __densities_.push_back(__fw(__b_[__i])); | 
|  | 6494 | __init(); | 
|  | 6495 | } | 
|  | 6496 | } | 
|  | 6497 |  | 
| Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6498 | #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
|  | 6499 |  | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6500 | template<class _RealType> | 
|  | 6501 | template<class _UnaryOperation> | 
|  | 6502 | piecewise_linear_distribution<_RealType>::param_type::param_type( | 
|  | 6503 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) | 
|  | 6504 | : __b_(__nw == 0 ? 2 : __nw + 1) | 
|  | 6505 | { | 
|  | 6506 | size_t __n = __b_.size() - 1; | 
|  | 6507 | result_type __d = (__xmax - __xmin) / __n; | 
|  | 6508 | __densities_.reserve(__b_.size()); | 
|  | 6509 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6510 | { | 
|  | 6511 | __b_[__i] = __xmin + __i * __d; | 
|  | 6512 | __densities_.push_back(__fw(__b_[__i])); | 
|  | 6513 | } | 
|  | 6514 | __b_[__n] = __xmax; | 
|  | 6515 | __densities_.push_back(__fw(__b_[__n])); | 
|  | 6516 | __init(); | 
|  | 6517 | } | 
|  | 6518 |  | 
|  | 6519 | template<class _RealType> | 
|  | 6520 | template<class _URNG> | 
|  | 6521 | _RealType | 
|  | 6522 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) | 
|  | 6523 | { | 
|  | 6524 | typedef uniform_real_distribution<result_type> _Gen; | 
|  | 6525 | result_type __u = _Gen()(__g); | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6526 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6527 | __u) - __p.__areas_.begin() - 1; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6528 | __u -= __p.__areas_[__k]; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6529 | const result_type __dk = __p.__densities_[__k]; | 
|  | 6530 | const result_type __dk1 = __p.__densities_[__k+1]; | 
|  | 6531 | const result_type __deltad = __dk1 - __dk; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6532 | const result_type __bk = __p.__b_[__k]; | 
|  | 6533 | if (__deltad == 0) | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6534 | return __u / __dk + __bk; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6535 | const result_type __bk1 = __p.__b_[__k+1]; | 
|  | 6536 | const result_type __deltab = __bk1 - __bk; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6537 | return (__bk * __dk1 - __bk1 * __dk + | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6538 | _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6539 | __deltad; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6540 | } | 
|  | 6541 |  | 
|  | 6542 | template <class _CharT, class _Traits, class _RT> | 
|  | 6543 | basic_ostream<_CharT, _Traits>& | 
|  | 6544 | operator<<(basic_ostream<_CharT, _Traits>& __os, | 
|  | 6545 | const piecewise_linear_distribution<_RT>& __x) | 
|  | 6546 | { | 
|  | 6547 | __save_flags<_CharT, _Traits> _(__os); | 
|  | 6548 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | | 
|  | 6549 | ios_base::scientific); | 
|  | 6550 | _CharT __sp = __os.widen(' '); | 
|  | 6551 | __os.fill(__sp); | 
|  | 6552 | size_t __n = __x.__p_.__b_.size(); | 
|  | 6553 | __os << __n; | 
|  | 6554 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6555 | __os << __sp << __x.__p_.__b_[__i]; | 
|  | 6556 | __n = __x.__p_.__densities_.size(); | 
|  | 6557 | __os << __sp << __n; | 
|  | 6558 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6559 | __os << __sp << __x.__p_.__densities_[__i]; | 
|  | 6560 | __n = __x.__p_.__areas_.size(); | 
|  | 6561 | __os << __sp << __n; | 
|  | 6562 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6563 | __os << __sp << __x.__p_.__areas_[__i]; | 
|  | 6564 | return __os; | 
|  | 6565 | } | 
|  | 6566 |  | 
|  | 6567 | template <class _CharT, class _Traits, class _RT> | 
|  | 6568 | basic_istream<_CharT, _Traits>& | 
|  | 6569 | operator>>(basic_istream<_CharT, _Traits>& __is, | 
|  | 6570 | piecewise_linear_distribution<_RT>& __x) | 
|  | 6571 | { | 
|  | 6572 | typedef piecewise_linear_distribution<_RT> _Eng; | 
|  | 6573 | typedef typename _Eng::result_type result_type; | 
|  | 6574 | typedef typename _Eng::param_type param_type; | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6575 | __save_flags<_CharT, _Traits> _(__is); | 
|  | 6576 | __is.flags(ios_base::dec | ios_base::skipws); | 
|  | 6577 | size_t __n; | 
|  | 6578 | __is >> __n; | 
|  | 6579 | vector<result_type> __b(__n); | 
|  | 6580 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6581 | __is >> __b[__i]; | 
|  | 6582 | __is >> __n; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6583 | vector<result_type> __densities(__n); | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6584 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6585 | __is >> __densities[__i]; | 
|  | 6586 | __is >> __n; | 
| Howard Hinnant | 908484b | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6587 | vector<result_type> __areas(__n); | 
| Howard Hinnant | b4d2fd2 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6588 | for (size_t __i = 0; __i < __n; ++__i) | 
|  | 6589 | __is >> __areas[__i]; | 
|  | 6590 | if (!__is.fail()) | 
|  | 6591 | { | 
|  | 6592 | swap(__x.__p_.__b_, __b); | 
|  | 6593 | swap(__x.__p_.__densities_, __densities); | 
|  | 6594 | swap(__x.__p_.__areas_, __areas); | 
|  | 6595 | } | 
|  | 6596 | return __is; | 
|  | 6597 | } | 
|  | 6598 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6599 | _LIBCPP_END_NAMESPACE_STD | 
|  | 6600 |  | 
|  | 6601 | #endif  // _LIBCPP_RANDOM |