diff --git a/sprout/config/compiler.hpp b/sprout/config/compiler.hpp index 462e861d..ae72ef45 100644 --- a/sprout/config/compiler.hpp +++ b/sprout/config/compiler.hpp @@ -31,9 +31,9 @@ # include #elif defined(__BORLANDC__) # include -#elif defined( __MWERKS__) +#elif defined(__MWERKS__) # include -#elif defined( __SUNPRO_CC) +#elif defined(__SUNPRO_CC) # include #elif defined(__HP_aCC) # include diff --git a/sprout/random.hpp b/sprout/random.hpp index 39cdd24c..cda73e2d 100644 --- a/sprout/random.hpp +++ b/sprout/random.hpp @@ -3,13 +3,14 @@ #include #include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/sprout/random/additive_combine.hpp b/sprout/random/additive_combine.hpp index bd416e9a..fc8fcad7 100644 --- a/sprout/random/additive_combine.hpp +++ b/sprout/random/additive_combine.hpp @@ -16,18 +16,27 @@ namespace sprout { template class additive_combine_engine { public: - typedef MLCG1 first_base; - typedef MLCG2 second_base; - typedef typename first_base::result_type result_type; + typedef MLCG1 base1_type; + typedef MLCG2 base2_type; + typedef base1_type first_base; + typedef base2_type second_base; + typedef typename base1_type::result_type result_type; private: + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { + return 1; + } + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return base1_type::modulus - 1; + } + public: struct private_constructor_tag {}; private: - first_base mlcg1_; - second_base mlcg2_; + base1_type mlcg1_; + base2_type mlcg2_; private: SPROUT_CONSTEXPR additive_combine_engine( - first_base const& mlcg1, - second_base const& mlcg2, + base1_type const& mlcg1, + base2_type const& mlcg2, private_constructor_tag ) : mlcg1_(mlcg1) @@ -38,7 +47,7 @@ namespace sprout { return sprout::random::random_result( rnd2.result() < rnd1.result() ? rnd1.result() - rnd2.result() - : rnd1.result() - rnd2.result() + first_base::modulus - 1 + : rnd1.result() - rnd2.result() + base1_type::modulus - 1 , additive_combine_engine( rnd1.engine(), @@ -60,19 +69,25 @@ namespace sprout { : mlcg1_(seed1) , mlcg2_(seed2) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return 1; } - SPROUT_CONSTEXPR result_type max() const { - return first_base::modulus - 1; + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { + return base1_type::modulus - 1; } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { return generate(mlcg1_(), mlcg2_()); } - friend SPROUT_CONSTEXPR bool operator==(additive_combine_engine const& lhs, additive_combine_engine const& rhs) { + SPROUT_CONSTEXPR base1_type const& base1() const SPROUT_NOEXCEPT { + return mlcg1_; + } + SPROUT_CONSTEXPR base2_type const& base2() const SPROUT_NOEXCEPT { + return mlcg2_; + } + friend SPROUT_CONSTEXPR bool operator==(additive_combine_engine const& lhs, additive_combine_engine const& rhs) SPROUT_NOEXCEPT { return lhs.mlcg1_ == rhs.mlcg1_ && lhs.mlcg2_ == rhs.mlcg2_; } - friend SPROUT_CONSTEXPR bool operator!=(additive_combine_engine const& lhs, additive_combine_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(additive_combine_engine const& lhs, additive_combine_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template diff --git a/sprout/random/bernoulli_distribution.hpp b/sprout/random/bernoulli_distribution.hpp index 51bd8c3c..308316b9 100644 --- a/sprout/random/bernoulli_distribution.hpp +++ b/sprout/random/bernoulli_distribution.hpp @@ -46,7 +46,7 @@ namespace sprout { explicit SPROUT_CONSTEXPR param_type(RealType p_arg) : p_(arg_check(p_arg)) {} - SPROUT_CONSTEXPR RealType p() const { + SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT { return p_; } template @@ -73,10 +73,10 @@ namespace sprout { { return lhs << rhs.p_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.p_ == rhs.p_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -104,16 +104,16 @@ namespace sprout { explicit SPROUT_CONSTEXPR bernoulli_distribution(param_type const& parm) : p_(parm.p()) {} - SPROUT_CONSTEXPR RealType p() const { + SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT { return p_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return false; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return true; } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(p_); } void param(param_type const& parm) { @@ -146,10 +146,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/binomial_distribution.hpp b/sprout/random/binomial_distribution.hpp index 914a2f2f..b7256972 100644 --- a/sprout/random/binomial_distribution.hpp +++ b/sprout/random/binomial_distribution.hpp @@ -102,10 +102,10 @@ namespace sprout { : t_(arg_check(t_arg, p_arg)) , p_(p_arg) {} - SPROUT_CONSTEXPR IntType t() const { + SPROUT_CONSTEXPR IntType t() const SPROUT_NOEXCEPT { return t_; } - SPROUT_CONSTEXPR RealType p() const { + SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT { return p_; } template @@ -134,10 +134,10 @@ namespace sprout { { return lhs << rhs.t_ << " " << rhs.p_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.t_ == rhs.t_ && lhs.p_ == rhs.p_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -635,19 +635,19 @@ namespace sprout { , btrd_(!init_use_inversion(parm.t(), parm.p()) ? init_btrd(parm.t(), parm.p()) : btrd_type()) , q_n_(init_use_inversion(parm.t(), parm.p()) ? init_q_n(parm.t(), parm.p()) : RealType()) {} - SPROUT_CONSTEXPR result_type t() const { + SPROUT_CONSTEXPR result_type t() const SPROUT_NOEXCEPT { return t_; } - SPROUT_CONSTEXPR result_type p() const { + SPROUT_CONSTEXPR result_type p() const SPROUT_NOEXCEPT { return p_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return 0; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return t_; } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(t_, p_); } void param(param_type const& parm) { @@ -685,10 +685,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(binomial_distribution const& lhs, binomial_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(binomial_distribution const& lhs, binomial_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(binomial_distribution const& lhs, binomial_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(binomial_distribution const& lhs, binomial_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/geometric_distribution.hpp b/sprout/random/geometric_distribution.hpp index bfc235ea..48824623 100644 --- a/sprout/random/geometric_distribution.hpp +++ b/sprout/random/geometric_distribution.hpp @@ -50,7 +50,7 @@ namespace sprout { explicit SPROUT_CONSTEXPR param_type(RealType p_arg) : p_(arg_check(p_arg)) {} - SPROUT_CONSTEXPR RealType p() const { + SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT { return p_; } template @@ -77,10 +77,10 @@ namespace sprout { { return lhs << rhs.p_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.p_ == rhs.p_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -119,16 +119,16 @@ namespace sprout { : p_(parm.p()) , log_1mp_(init_log_1mp(parm.p())) {} - SPROUT_CONSTEXPR result_type p() const { + SPROUT_CONSTEXPR result_type p() const SPROUT_NOEXCEPT { return p_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return 0; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return std::numeric_limits::max(); } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(p_); } void param(param_type const& parm) { @@ -159,10 +159,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(geometric_distribution const& lhs, geometric_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(geometric_distribution const& lhs, geometric_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(geometric_distribution const& lhs, geometric_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(geometric_distribution const& lhs, geometric_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/inversive_congruential.hpp b/sprout/random/inversive_congruential.hpp index 1e34ebb0..567a945b 100644 --- a/sprout/random/inversive_congruential.hpp +++ b/sprout/random/inversive_congruential.hpp @@ -26,13 +26,14 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR IntType increment = b; SPROUT_STATIC_CONSTEXPR IntType modulus = p; SPROUT_STATIC_CONSTEXPR IntType default_seed = 1; - private: - static SPROUT_CONSTEXPR result_type static_min() { + public: + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { return b == 0 ? 1 : 0; } - static SPROUT_CONSTEXPR result_type static_max() { + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { return modulus - 1; } + private: template static SPROUT_CONSTEXPR typename std::enable_if::value, bool>::type arg_check_nothrow(T const& x0) { @@ -80,20 +81,20 @@ namespace sprout { explicit SPROUT_CONSTEXPR inversive_congruential_engine(IntType const& x0) : x_(init_seed(x0)) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return static_min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return static_max(); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { typedef sprout::random::detail::const_mod do_mod; return generate(do_mod::mult_add(a, do_mod::invert(x_), b)); } - friend SPROUT_CONSTEXPR bool operator==(inversive_congruential_engine const& lhs, inversive_congruential_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(inversive_congruential_engine const& lhs, inversive_congruential_engine const& rhs) SPROUT_NOEXCEPT { return lhs.x_ == rhs.x_; } - friend SPROUT_CONSTEXPR bool operator!=(inversive_congruential_engine const& lhs, inversive_congruential_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(inversive_congruential_engine const& lhs, inversive_congruential_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template diff --git a/sprout/random/linear_congruential.hpp b/sprout/random/linear_congruential.hpp index 063d93f5..5ddd76e5 100644 --- a/sprout/random/linear_congruential.hpp +++ b/sprout/random/linear_congruential.hpp @@ -15,28 +15,28 @@ namespace sprout { // // linear_congruential_engine // - template + template class linear_congruential_engine { + static_assert(std::numeric_limits::is_integer, "std::numeric_limits::is_integer"); + static_assert(m == 0 || a < m, "m == 0 || a < m"); + static_assert(m == 0 || c < m, "m == 0 || c < m"); public: - typedef IntType result_type; + typedef UIntType result_type; private: struct private_constructor_tag {}; public: - SPROUT_STATIC_CONSTEXPR IntType multiplier = a; - SPROUT_STATIC_CONSTEXPR IntType increment = c; - SPROUT_STATIC_CONSTEXPR IntType modulus = m; - SPROUT_STATIC_CONSTEXPR IntType default_seed = 1; + SPROUT_STATIC_CONSTEXPR UIntType multiplier = a; + SPROUT_STATIC_CONSTEXPR UIntType increment = c; + SPROUT_STATIC_CONSTEXPR UIntType modulus = m; + SPROUT_STATIC_CONSTEXPR UIntType default_seed = 1; public: - static_assert(std::numeric_limits::is_integer, "std::numeric_limits::is_integer"); - static_assert(m == 0 || a < m, "m == 0 || a < m"); - static_assert(m == 0 || c < m, "m == 0 || c < m"); - private: - static SPROUT_CONSTEXPR result_type static_min() { + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { return c == 0 ? 1 : 0; } - static SPROUT_CONSTEXPR result_type static_max() { - return modulus - 1; + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return m - 1; } + private: template static SPROUT_CONSTEXPR typename std::enable_if::value, bool>::type arg_check_nothrow(T const& x0) { @@ -47,24 +47,24 @@ namespace sprout { arg_check_nothrow(T const& x0) { return x0 >= static_min() && x0 <= static_max(); } - static SPROUT_CONSTEXPR IntType arg_check(IntType const& x0) { + static SPROUT_CONSTEXPR UIntType arg_check(UIntType const& x0) { return arg_check_nothrow(x0) ? x0 : throw std::invalid_argument("linear_congruential_engine<>: invalid argument (x0 >= static_min() && x0 <= static_max())") ; } - static SPROUT_CONSTEXPR IntType init_seed_2(IntType const& x0) { + static SPROUT_CONSTEXPR UIntType init_seed_2(UIntType const& x0) { return arg_check(increment == 0 && x0 == 0 ? 1 : x0); } - static SPROUT_CONSTEXPR IntType init_seed_1(IntType const& x0) { + static SPROUT_CONSTEXPR UIntType init_seed_1(UIntType const& x0) { return init_seed_2(x0 <= 0 && x0 != 0 ? x0 + modulus : x0); } - static SPROUT_CONSTEXPR IntType init_seed(IntType const& x0) { + static SPROUT_CONSTEXPR UIntType init_seed(UIntType const& x0) { return init_seed_1(modulus == 0 ? x0 : x0 % modulus); } private: - IntType x_; + UIntType x_; private: - SPROUT_CONSTEXPR linear_congruential_engine(IntType const& x, private_constructor_tag) + SPROUT_CONSTEXPR linear_congruential_engine(UIntType const& x, private_constructor_tag) : x_(x) {} SPROUT_CONSTEXPR sprout::random::random_result generate(result_type result) const { @@ -77,22 +77,22 @@ namespace sprout { SPROUT_CONSTEXPR linear_congruential_engine() : x_(init_seed(default_seed)) {} - explicit SPROUT_CONSTEXPR linear_congruential_engine(IntType const& x0) + explicit SPROUT_CONSTEXPR linear_congruential_engine(UIntType const& x0) : x_(init_seed(x0)) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return static_min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return static_max(); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { - return generate(sprout::random::detail::const_mod::mult_add(a, x_, c)); + return generate(sprout::random::detail::const_mod::mult_add(a, x_, c)); } - friend SPROUT_CONSTEXPR bool operator==(linear_congruential_engine const& lhs, linear_congruential_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(linear_congruential_engine const& lhs, linear_congruential_engine const& rhs) SPROUT_NOEXCEPT { return lhs.x_ == rhs.x_; } - friend SPROUT_CONSTEXPR bool operator!=(linear_congruential_engine const& lhs, linear_congruential_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(linear_congruential_engine const& lhs, linear_congruential_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template @@ -101,7 +101,7 @@ namespace sprout { linear_congruential_engine& rhs ) { - IntType x; + UIntType x; if (lhs >> x) { if(arg_check_nothrow(x)) { rhs.x_ = x; @@ -120,14 +120,14 @@ namespace sprout { return lhs << rhs.x_; } }; - template - SPROUT_CONSTEXPR_OR_CONST IntType sprout::random::linear_congruential_engine::multiplier; - template - SPROUT_CONSTEXPR_OR_CONST IntType sprout::random::linear_congruential_engine::increment; - template - SPROUT_CONSTEXPR_OR_CONST IntType sprout::random::linear_congruential_engine::modulus; - template - SPROUT_CONSTEXPR_OR_CONST IntType sprout::random::linear_congruential_engine::default_seed; + template + SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::linear_congruential_engine::multiplier; + template + SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::linear_congruential_engine::increment; + template + SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::linear_congruential_engine::modulus; + template + SPROUT_CONSTEXPR_OR_CONST UIntType sprout::random::linear_congruential_engine::default_seed; // // minstd_rand0 diff --git a/sprout/random/linear_feedback_shift.hpp b/sprout/random/linear_feedback_shift.hpp index 9d5b0611..59b2266e 100644 --- a/sprout/random/linear_feedback_shift.hpp +++ b/sprout/random/linear_feedback_shift.hpp @@ -29,16 +29,17 @@ namespace sprout { static_assert(k < w, "k < w"); static_assert(0 < 2 * q && 2 * q < k, "0 < 2 * q && 2 * q < k"); static_assert(0 < s && s <= k - q, "0 < s && s <= k - q"); + public: + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { + return 0; + } + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return wordmask(); + } private: static SPROUT_CONSTEXPR UIntType wordmask() { return sprout::detail::low_bits_mask_t::sig_bits; } - static SPROUT_CONSTEXPR result_type static_min() { - return 0; - } - static SPROUT_CONSTEXPR result_type static_max() { - return wordmask(); - } static SPROUT_CONSTEXPR UIntType init_seed_1(UIntType const& x0) { return x0 < (1 << (w - k)) ? x0 + (1 << (w - k)) : x0; } @@ -64,19 +65,19 @@ namespace sprout { explicit SPROUT_CONSTEXPR linear_feedback_shift_engine(UIntType const& x0) : x_(init_seed(x0)) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return static_min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return static_max(); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { return generate(((x_ & ((wordmask() << (w - k)) & wordmask())) << s) ^ ((((x_ << q) ^ x_) & wordmask()) >> (k - s))); } - friend SPROUT_CONSTEXPR bool operator==(linear_feedback_shift_engine const& lhs, linear_feedback_shift_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(linear_feedback_shift_engine const& lhs, linear_feedback_shift_engine const& rhs) SPROUT_NOEXCEPT { return lhs.x_ == rhs.x_; } - friend SPROUT_CONSTEXPR bool operator!=(linear_feedback_shift_engine const& lhs, linear_feedback_shift_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(linear_feedback_shift_engine const& lhs, linear_feedback_shift_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template diff --git a/sprout/random/mersenne_twister.hpp b/sprout/random/mersenne_twister.hpp index 1b672294..28e4887a 100644 --- a/sprout/random/mersenne_twister.hpp +++ b/sprout/random/mersenne_twister.hpp @@ -46,6 +46,13 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR std::size_t unroll_factor = 6; SPROUT_STATIC_CONSTEXPR std::size_t unroll_extra1 = (n - m) % unroll_factor; SPROUT_STATIC_CONSTEXPR std::size_t unroll_extra2 = (m - 1) % unroll_factor; + public: + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { + return 0; + } + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return sprout::detail::low_bits_mask_t::sig_bits; + } private: template static SPROUT_CONSTEXPR typename std::enable_if< @@ -68,13 +75,6 @@ namespace sprout { static SPROUT_CONSTEXPR sprout::array init_seed(UIntType const& value) { return init_seed_1(value & static_max()); } - public: - static SPROUT_CONSTEXPR result_type static_min() { - return 0; - } - static SPROUT_CONSTEXPR result_type static_max() { - return sprout::detail::low_bits_mask_t::sig_bits; - } private: sprout::array x_; std::size_t i_; @@ -373,10 +373,10 @@ namespace sprout { : x_(init_seed(value)) , i_(n) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return static_min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return static_max(); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { @@ -385,13 +385,13 @@ namespace sprout { : generate() ; } - friend SPROUT_CONSTEXPR bool operator==(mersenne_twister_engine const& lhs, mersenne_twister_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(mersenne_twister_engine const& lhs, mersenne_twister_engine const& rhs) SPROUT_NOEXCEPT { return lhs.i_ < rhs.i_ ? lhs.equal_impl(rhs) : rhs.equal_impl(lhs) ; } - friend SPROUT_CONSTEXPR bool operator!=(mersenne_twister_engine const& lhs, mersenne_twister_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(mersenne_twister_engine const& lhs, mersenne_twister_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template diff --git a/sprout/random/normal_distribution.hpp b/sprout/random/normal_distribution.hpp index f4a1dd87..eb5150e7 100644 --- a/sprout/random/normal_distribution.hpp +++ b/sprout/random/normal_distribution.hpp @@ -59,10 +59,13 @@ namespace sprout { : mean_(arg_check(mean_arg, sigma_arg)) , sigma_(sigma_arg) {} - SPROUT_CONSTEXPR RealType mean() const { + SPROUT_CONSTEXPR RealType mean() const SPROUT_NOEXCEPT { return mean_; } - SPROUT_CONSTEXPR RealType sigma() const { + SPROUT_CONSTEXPR RealType sigma() const SPROUT_NOEXCEPT { + return sigma_; + } + SPROUT_CONSTEXPR RealType stddev() const SPROUT_NOEXCEPT { return sigma_; } template @@ -91,10 +94,10 @@ namespace sprout { { return lhs << rhs.mean_ << " " << rhs.sigma_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.mean_ == rhs.mean_ && lhs.sigma_ == rhs.sigma_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -186,19 +189,22 @@ namespace sprout { , cached_rho_(0) , valid_(false) {} - SPROUT_CONSTEXPR result_type mean() const { + SPROUT_CONSTEXPR result_type mean() const SPROUT_NOEXCEPT { return mean_; } - SPROUT_CONSTEXPR result_type sigma() const { + SPROUT_CONSTEXPR result_type sigma() const SPROUT_NOEXCEPT { return sigma_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type stddev() const SPROUT_NOEXCEPT { + return sigma_; + } + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return -std::numeric_limits::infinity(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return std::numeric_limits::infinity(); } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(mean_, sigma_); } void param(param_type const& parm) { @@ -238,14 +244,14 @@ namespace sprout { { return lhs << rhs.param() << " " << rhs.valid_ << " " << rhs.cached_rho_ << " " << rhs.r1_ << " " << rhs.r2_; } - friend SPROUT_CONSTEXPR bool operator==(normal_distribution const& lhs, normal_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(normal_distribution const& lhs, normal_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param() && lhs.valid_ == rhs.valid_ && lhs.cached_rho_ == rhs.cached_rho_ && lhs.r1_ == rhs.r1_ && lhs.r2_ == rhs.r2_ ; } - friend SPROUT_CONSTEXPR bool operator!=(normal_distribution const& lhs, normal_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(normal_distribution const& lhs, normal_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index eaa6770d..da7b2baf 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -68,46 +68,46 @@ namespace sprout { , engine_(engine) , distribution_(distribution) {} - SPROUT_CONSTEXPR operator result_type() const { + SPROUT_CONSTEXPR operator result_type() const SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR random_result operator()() const { return distribution_(engine_); } - result_type& result() { + result_type& result() SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR result_type const& result() const { + SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { return result_; } - result_type& generated_value() { + result_type& generated_value() SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR result_type const& generated_value() const { + SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT { return result_; } - engine_type& engine() { + engine_type& engine() SPROUT_NOEXCEPT { return engine_; } - SPROUT_CONSTEXPR engine_type const& engine() const { + SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT { return engine_; } - random_result& next_generator() { + random_result& next_generator() SPROUT_NOEXCEPT { return *this; } - SPROUT_CONSTEXPR random_result const& next_generator() const { + SPROUT_CONSTEXPR random_result const& next_generator() const SPROUT_NOEXCEPT { return *this; } - distribution_type& distribution() { + distribution_type& distribution() SPROUT_NOEXCEPT { return distribution_; } - SPROUT_CONSTEXPR distribution_type const& distribution() const { + SPROUT_CONSTEXPR distribution_type const& distribution() const SPROUT_NOEXCEPT { return distribution_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return distribution_.min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return distribution_.max(); } void swap(random_result& other) @@ -121,19 +121,19 @@ namespace sprout { sprout::swap(engine_, other.engine_); sprout::swap(distribution_, other.distribution_); } - friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT { return lhs.result_ == rhs.result_ && lhs.engine_ == rhs.engine_ && lhs.distribution_ == rhs.distribution_ ; } - friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } - SPROUT_CONSTEXPR reference operator*() const { + SPROUT_CONSTEXPR reference operator*() const SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR pointer operator->() const { + SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT { return &result_; } random_result& operator++() { @@ -193,48 +193,48 @@ namespace sprout { : result_(result) , engine_(engine) {} - SPROUT_CONSTEXPR operator result_type() const { + SPROUT_CONSTEXPR operator result_type() const SPROUT_NOEXCEPT { return result_; } SPROUT_CONSTEXPR random_result operator()() const { return engine_(); } - result_type& result() { + result_type& result() SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR result_type const& result() const { + SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT { return result_; } - result_type& generated_value() { + result_type& generated_value() SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR result_type const& generated_value() const { + SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT { return result_; } - engine_type& engine() { + engine_type& engine() SPROUT_NOEXCEPT { return engine_; } - SPROUT_CONSTEXPR engine_type const& engine() const { + SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT { return engine_; } - random_result& next_generator() { + random_result& next_generator() SPROUT_NOEXCEPT { return *this; } - SPROUT_CONSTEXPR random_result const& next_generator() const { + SPROUT_CONSTEXPR random_result const& next_generator() const SPROUT_NOEXCEPT { return *this; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return engine_.min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return engine_.max(); } - friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT { return lhs.result_ == rhs.result_ && lhs.engine_ == rhs.engine_ ; } - friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } void swap(random_result& other) @@ -246,10 +246,10 @@ namespace sprout { sprout::swap(result_, other.result_); sprout::swap(engine_, other.engine_); } - SPROUT_CONSTEXPR reference operator*() const { + SPROUT_CONSTEXPR reference operator*() const SPROUT_NOEXCEPT { return result_; } - SPROUT_CONSTEXPR pointer operator->() const { + SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT { return &result_; } random_result& operator++() { diff --git a/sprout/random/shuffle_order.hpp b/sprout/random/shuffle_order.hpp index 83cc9766..c2c89a92 100644 --- a/sprout/random/shuffle_order.hpp +++ b/sprout/random/shuffle_order.hpp @@ -36,6 +36,11 @@ namespace sprout { class shuffle_order_engine : private sprout::random::detail::shuffle_order_engine_member { + static_assert( + std::numeric_limits::is_integer, + "std::numeric_limits::is_integer" + ); + static_assert(k > 0, "k > 0"); private: typedef sprout::random::detail::shuffle_order_engine_member member_type; public: @@ -47,8 +52,12 @@ namespace sprout { SPROUT_STATIC_CONSTEXPR std::size_t buffer_size = k; SPROUT_STATIC_CONSTEXPR std::size_t table_size = k; public: - static_assert(std::numeric_limits::is_integer, "std::numeric_limits::is_integer"); - static_assert(k > 0, "k > 0"); + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { + return base_type::static_min(); + } + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return base_type::static_max(); + } private: template static SPROUT_CONSTEXPR typename std::enable_if< @@ -120,10 +129,10 @@ namespace sprout { explicit SPROUT_CONSTEXPR shuffle_order_engine(base_type const& rng) : member_type(init_member(rng)) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return rng_.min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return rng_.max(); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { @@ -133,10 +142,13 @@ namespace sprout { base_unsigned(sprout::random::detail::subtract()(y_, min())) ); } - friend SPROUT_CONSTEXPR bool operator==(shuffle_order_engine const& lhs, shuffle_order_engine const& rhs) { + SPROUT_CONSTEXPR base_type const& base() const SPROUT_NOEXCEPT { + return rng_; + } + friend SPROUT_CONSTEXPR bool operator==(shuffle_order_engine const& lhs, shuffle_order_engine const& rhs) SPROUT_NOEXCEPT { return lhs.rng_ == rhs.rng_ && lhs.y_ == rhs.y_ && lhs.v_ == rhs.v_; } - friend SPROUT_CONSTEXPR bool operator!=(shuffle_order_engine const& lhs, shuffle_order_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(shuffle_order_engine const& lhs, shuffle_order_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template diff --git a/sprout/random/uniform_01.hpp b/sprout/random/uniform_01.hpp index 8a7003da..7fab14c7 100644 --- a/sprout/random/uniform_01.hpp +++ b/sprout/random/uniform_01.hpp @@ -44,10 +44,10 @@ namespace sprout { { return lhs; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return true; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -118,13 +118,13 @@ namespace sprout { {} explicit SPROUT_CONSTEXPR uniform_01(param_type const& parm) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return result_type(0); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return result_type(1); } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(); } void param(param_type const& parm) { @@ -149,10 +149,10 @@ namespace sprout { { return lhs; } - friend SPROUT_CONSTEXPR bool operator==(uniform_01 const& lhs, uniform_01 const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(uniform_01 const& lhs, uniform_01 const& rhs) SPROUT_NOEXCEPT { return true; } - friend SPROUT_CONSTEXPR bool operator!=(uniform_01 const& lhs, uniform_01 const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(uniform_01 const& lhs, uniform_01 const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/uniform_int_distribution.hpp b/sprout/random/uniform_int_distribution.hpp index 6aa68738..55fa5b3a 100644 --- a/sprout/random/uniform_int_distribution.hpp +++ b/sprout/random/uniform_int_distribution.hpp @@ -320,10 +320,10 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - SPROUT_CONSTEXPR IntType a() const { + SPROUT_CONSTEXPR IntType a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR IntType b() const { + SPROUT_CONSTEXPR IntType b() const SPROUT_NOEXCEPT { return max_; } template @@ -352,10 +352,10 @@ namespace sprout { { return lhs << rhs.min_ << " " << rhs.max_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.min_ == rhs.min_ && lhs.max_ == rhs.max_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -384,19 +384,19 @@ namespace sprout { : min_(parm.a()) , max_(parm.b()) {} - SPROUT_CONSTEXPR result_type a() const { + SPROUT_CONSTEXPR result_type a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type b() const { + SPROUT_CONSTEXPR result_type b() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(min_, max_); } void param(param_type const& parm) { @@ -427,10 +427,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/uniform_real_distribution.hpp b/sprout/random/uniform_real_distribution.hpp index 6bb4b1f7..48f9bb61 100644 --- a/sprout/random/uniform_real_distribution.hpp +++ b/sprout/random/uniform_real_distribution.hpp @@ -215,10 +215,10 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - SPROUT_CONSTEXPR RealType a() const { + SPROUT_CONSTEXPR RealType a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR RealType b() const { + SPROUT_CONSTEXPR RealType b() const SPROUT_NOEXCEPT { return max_; } template @@ -247,10 +247,10 @@ namespace sprout { { return lhs << rhs.min_ << " " << rhs.max_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.min_ == rhs.min_ && lhs.max_ == rhs.max_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -279,19 +279,19 @@ namespace sprout { : min_(parm.a()) , max_(parm.b()) {} - SPROUT_CONSTEXPR result_type a() const { + SPROUT_CONSTEXPR result_type a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type b() const { + SPROUT_CONSTEXPR result_type b() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(min_, max_); } void param(param_type const& parm) { @@ -322,10 +322,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/uniform_smallint.hpp b/sprout/random/uniform_smallint.hpp index debdf814..7fac93d0 100644 --- a/sprout/random/uniform_smallint.hpp +++ b/sprout/random/uniform_smallint.hpp @@ -53,10 +53,10 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - SPROUT_CONSTEXPR IntType a() const { + SPROUT_CONSTEXPR IntType a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR IntType b() const { + SPROUT_CONSTEXPR IntType b() const SPROUT_NOEXCEPT { return max_; } template @@ -85,10 +85,10 @@ namespace sprout { { return lhs << rhs.min_ << " " << rhs.max_; } - friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return lhs.min_ == rhs.min_ && lhs.max_ == rhs.max_; } - friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(param_type const& lhs, param_type const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; @@ -214,19 +214,19 @@ namespace sprout { : min_(parm.a()) , max_(parm.b()) {} - SPROUT_CONSTEXPR result_type a() const { + SPROUT_CONSTEXPR result_type a() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type b() const { + SPROUT_CONSTEXPR result_type b() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return min_; } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return max_; } - SPROUT_CONSTEXPR param_type param() const { + SPROUT_CONSTEXPR param_type param() const SPROUT_NOEXCEPT { return param_type(min_, max_); } void param(param_type const& parm) { @@ -258,10 +258,10 @@ namespace sprout { { return lhs << rhs.param(); } - friend SPROUT_CONSTEXPR bool operator==(uniform_smallint const& lhs, uniform_smallint const& rhs) { + friend SPROUT_CONSTEXPR bool operator==(uniform_smallint const& lhs, uniform_smallint const& rhs) SPROUT_NOEXCEPT { return lhs.param() == rhs.param(); } - friend SPROUT_CONSTEXPR bool operator!=(uniform_smallint const& lhs, uniform_smallint const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(uniform_smallint const& lhs, uniform_smallint const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } }; diff --git a/sprout/random/variate_generator.hpp b/sprout/random/variate_generator.hpp index c1971263..698d925b 100644 --- a/sprout/random/variate_generator.hpp +++ b/sprout/random/variate_generator.hpp @@ -44,22 +44,22 @@ namespace sprout { SPROUT_CONSTEXPR random_result_type operator()() const { return distribution_(engine_); } - engine_reference_type engine() { + engine_reference_type engine() SPROUT_NOEXCEPT { return engine_helper_type::ref(engine_); } - SPROUT_CONSTEXPR engine_const_reference_type engine() const { + SPROUT_CONSTEXPR engine_const_reference_type engine() const SPROUT_NOEXCEPT { return engine_helper_type::ref(engine_); } - distribution_reference_type distribution() { + distribution_reference_type distribution() SPROUT_NOEXCEPT { return distribution_helper_type::ref(distribution_); } - SPROUT_CONSTEXPR distribution_const_reference_type distribution() const { + SPROUT_CONSTEXPR distribution_const_reference_type distribution() const SPROUT_NOEXCEPT { return distribution_helper_type::ref(distribution_); } - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return distribution_.min(); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return distribution_.max(); } }; diff --git a/sprout/random/xor_combine.hpp b/sprout/random/xor_combine.hpp index a57ea38c..38c68a57 100644 --- a/sprout/random/xor_combine.hpp +++ b/sprout/random/xor_combine.hpp @@ -17,10 +17,19 @@ namespace sprout { public: typedef URNG1 base1_type; typedef URNG2 base2_type; + typedef base1_type first_base; + typedef base2_type second_base; typedef typename base1_type::result_type result_type; public: SPROUT_STATIC_CONSTEXPR int shift1 = s1; SPROUT_STATIC_CONSTEXPR int shift2 = s2; + public: + static SPROUT_CONSTEXPR result_type static_min() SPROUT_NOEXCEPT { + return NS_SSCRISK_CEL_OR_SPROUT::min(base1_type::static_min(), base2_type::static_min()); + } + static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT { + return NS_SSCRISK_CEL_OR_SPROUT::max(base1_type::static_max(), base2_type::static_max()); + } private: base1_type rng1_; base2_type rng2_; @@ -48,19 +57,25 @@ namespace sprout { : rng1_(rng1) , rng2_(rng2) {} - SPROUT_CONSTEXPR result_type min() const { + SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT { return NS_SSCRISK_CEL_OR_SPROUT::min(rng1_.min(), rng2_.min()); } - SPROUT_CONSTEXPR result_type max() const { + SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT { return NS_SSCRISK_CEL_OR_SPROUT::max(rng1_.max(), rng2_.max()); } SPROUT_CONSTEXPR sprout::random::random_result operator()() const { return generate(rng1_(), rng2_()); } - friend SPROUT_CONSTEXPR bool operator==(xor_combine_engine const& lhs, xor_combine_engine const& rhs) { + SPROUT_CONSTEXPR base1_type const& base1() const SPROUT_NOEXCEPT { + return rng1_; + } + SPROUT_CONSTEXPR base2_type const& base2() const SPROUT_NOEXCEPT { + return rng2_; + } + friend SPROUT_CONSTEXPR bool operator==(xor_combine_engine const& lhs, xor_combine_engine const& rhs) SPROUT_NOEXCEPT { return lhs.rng1_ == rhs.rng1_ && lhs.rng2_ == rhs.rng2_; } - friend SPROUT_CONSTEXPR bool operator!=(xor_combine_engine const& lhs, xor_combine_engine const& rhs) { + friend SPROUT_CONSTEXPR bool operator!=(xor_combine_engine const& lhs, xor_combine_engine const& rhs) SPROUT_NOEXCEPT { return !(lhs == rhs); } template