diff --git a/sprout/random/bernoulli_distribution.hpp b/sprout/random/bernoulli_distribution.hpp index 6103a0c3..61c1ad84 100644 --- a/sprout/random/bernoulli_distribution.hpp +++ b/sprout/random/bernoulli_distribution.hpp @@ -32,22 +32,26 @@ namespace sprout { class param_type { public: typedef bernoulli_distribution distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) { + return distribution_type::arg_check_nothrow(p_arg); + } private: RealType p_; public: SPROUT_CONSTEXPR param_type() : p_(RealType(0.5)) {} - SPROUT_CONSTEXPR explicit param_type(RealType p_arg = RealType(0.5)) + SPROUT_CONSTEXPR explicit param_type(RealType p_arg) : p_(arg_check(p_arg)) {} SPROUT_CONSTEXPR RealType p() const { return p_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { RealType p; @@ -93,7 +97,7 @@ namespace sprout { SPROUT_CONSTEXPR bernoulli_distribution() : p_(RealType(0.5)) {} - SPROUT_CONSTEXPR explicit bernoulli_distribution(RealType p_arg = RealType(0.5)) + SPROUT_CONSTEXPR explicit bernoulli_distribution(RealType p_arg) : p_(arg_check(p_arg)) {} SPROUT_CONSTEXPR explicit bernoulli_distribution(param_type const& parm) @@ -122,14 +126,14 @@ namespace sprout { ; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - bernoulli_distribution const& rhs + bernoulli_distribution& rhs ) { param_type parm; return lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -138,7 +142,7 @@ namespace sprout { bernoulli_distribution const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) { return lhs.param() == rhs.param(); diff --git a/sprout/random/binomial_distribution.hpp b/sprout/random/binomial_distribution.hpp index 001a7987..0bf6b1cd 100644 --- a/sprout/random/binomial_distribution.hpp +++ b/sprout/random/binomial_distribution.hpp @@ -69,6 +69,10 @@ namespace sprout { class param_type { public: typedef binomial_distribution distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType t_arg, RealType p_arg) { + return distribution_type::arg_check_nothrow(t_arg, p_arg); + } private: IntType t_; RealType p_; @@ -88,9 +92,9 @@ namespace sprout { return p_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { IntType t; @@ -391,8 +395,8 @@ namespace sprout { return param_type(t_, p_); } void param(param_type const& parm) { - t_ = parm.a(); - p_ = parm.b(); + t_ = parm.t(); + p_ = parm.p(); init(); } template @@ -405,14 +409,14 @@ namespace sprout { ; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - binomial_distribution const& rhs + binomial_distribution& rhs ) { param_type parm; lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -421,7 +425,7 @@ namespace sprout { binomial_distribution const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(binomial_distribution const& lhs, binomial_distribution const& rhs) { return lhs.param() == rhs.param(); diff --git a/sprout/random/geometric_distribution.hpp b/sprout/random/geometric_distribution.hpp index 0b69328e..fd181ba1 100644 --- a/sprout/random/geometric_distribution.hpp +++ b/sprout/random/geometric_distribution.hpp @@ -45,6 +45,10 @@ namespace sprout { class param_type { public: typedef geometric_distribution distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) { + return distribution_type::arg_check_nothrow(p_arg); + } private: RealType p_; public: @@ -58,9 +62,9 @@ namespace sprout { return p_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { RealType p; @@ -147,14 +151,14 @@ namespace sprout { return generate(eng); } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - geometric_distribution const& rhs + geometric_distribution& rhs ) { param_type parm; lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -163,7 +167,7 @@ namespace sprout { geometric_distribution const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(geometric_distribution const& lhs, geometric_distribution const& rhs) { return lhs.param() == rhs.param(); diff --git a/sprout/random/uniform_01.hpp b/sprout/random/uniform_01.hpp index 85147c7a..52248e5a 100644 --- a/sprout/random/uniform_01.hpp +++ b/sprout/random/uniform_01.hpp @@ -26,9 +26,9 @@ namespace sprout { typedef uniform_01 distribution_type; public: template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { return lhs; @@ -81,6 +81,8 @@ namespace sprout { ); } public: + SPROUT_CONSTEXPR explicit uniform_01() + {} SPROUT_CONSTEXPR explicit uniform_01(param_type const& parm) {} SPROUT_CONSTEXPR result_type min() const { @@ -99,9 +101,9 @@ namespace sprout { return generate(eng, eng()); } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - uniform_01 const& rhs + uniform_01& rhs ) { return lhs; diff --git a/sprout/random/uniform_int_distribution.hpp b/sprout/random/uniform_int_distribution.hpp index aa1e6db7..4338938f 100644 --- a/sprout/random/uniform_int_distribution.hpp +++ b/sprout/random/uniform_int_distribution.hpp @@ -406,6 +406,10 @@ namespace sprout { class param_type { public: typedef uniform_int_distribution distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) { + return distribution_type::arg_check_nothrow(min_arg, max_arg); + } private: IntType min_; IntType max_; @@ -425,9 +429,9 @@ namespace sprout { return max_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { IntType min; @@ -478,7 +482,7 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - explicit uniform_int_distribution(param_type const& parm) + SPROUT_CONSTEXPR explicit uniform_int_distribution(param_type const& parm) : min_(parm.a()) , max_(parm.b()) {} @@ -506,14 +510,14 @@ namespace sprout { return generate(sprout::random::detail::generate_uniform_int(eng, min_, max_)); } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - uniform_int_distribution const& rhs + uniform_int_distribution& rhs ) { param_type parm; lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -522,7 +526,7 @@ namespace sprout { uniform_int_distribution const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) { return lhs.param() == rhs.param(); diff --git a/sprout/random/uniform_real_distribution.hpp b/sprout/random/uniform_real_distribution.hpp index a77b3990..8e4be241 100644 --- a/sprout/random/uniform_real_distribution.hpp +++ b/sprout/random/uniform_real_distribution.hpp @@ -198,6 +198,10 @@ namespace sprout { class param_type { public: typedef uniform_real_distribution distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType min_arg, RealType max_arg) { + return distribution_type::arg_check_nothrow(min_arg, max_arg); + } private: RealType min_; RealType max_; @@ -217,9 +221,9 @@ namespace sprout { return max_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { RealType min; @@ -270,7 +274,7 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - explicit uniform_real_distribution(param_type const& parm) + SPROUT_CONSTEXPR explicit uniform_real_distribution(param_type const& parm) : min_(parm.a()) , max_(parm.b()) {} @@ -298,14 +302,14 @@ namespace sprout { return generate(sprout::random::detail::generate_uniform_real(eng, min_, max_)); } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - uniform_real_distribution const& rhs + uniform_real_distribution& rhs ) { param_type parm; lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -314,7 +318,7 @@ namespace sprout { uniform_real_distribution const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) { return lhs.param() == rhs.param(); diff --git a/sprout/random/uniform_smallint.hpp b/sprout/random/uniform_smallint.hpp index 54b7cde2..e3605848 100644 --- a/sprout/random/uniform_smallint.hpp +++ b/sprout/random/uniform_smallint.hpp @@ -36,6 +36,10 @@ namespace sprout { class param_type { public: typedef uniform_smallint distribution_type; + private: + static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) { + return distribution_type::arg_check_nothrow(min_arg, max_arg); + } private: IntType min_; IntType max_; @@ -55,9 +59,9 @@ namespace sprout { return max_; } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - param_type const& rhs + param_type& rhs ) { IntType min; @@ -205,7 +209,7 @@ namespace sprout { : min_(arg_check(min_arg, max_arg)) , max_(max_arg) {} - explicit uniform_smallint(param_type const& parm) + SPROUT_CONSTEXPR explicit uniform_smallint(param_type const& parm) : min_(parm.a()) , max_(parm.b()) {} @@ -234,14 +238,14 @@ namespace sprout { return generate(eng, typename std::is_integral::type()); } template - friend std::basic_ostream& operator>>( + friend std::basic_istream& operator>>( std::basic_istream& lhs, - uniform_smallint const& rhs + uniform_smallint& rhs ) { param_type parm; lhs >> parm; - param(parm); + rhs.param(parm); return lhs; } template @@ -250,7 +254,7 @@ namespace sprout { uniform_smallint const& rhs ) { - return lhs << param(); + return lhs << rhs.param(); } SPROUT_CONSTEXPR friend bool operator==(uniform_smallint const& lhs, uniform_smallint const& rhs) { return lhs.param() == rhs.param();