1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

エラー通知を標準例外に変更

This commit is contained in:
bolero-MURAKAMI 2011-10-26 15:57:31 +09:00
parent 9823888049
commit 4729d31bf2
22 changed files with 76 additions and 57 deletions

View file

@ -2,6 +2,7 @@
#define SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#include <iosfwd>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/random/random_result.hpp>
@ -22,7 +23,7 @@ namespace sprout {
static SPROUT_CONSTEXPR RealType arg_check(RealType p_arg) {
return arg_check_nothrow(p_arg)
? p_arg
: throw "assert(p_arg >= 0 && p_arg <= 1)"
: throw std::invalid_argument("bernoulli_distribution<>: invalid argument (p_arg >= 0 && p_arg <= 1)")
;
}
public:

View file

@ -4,6 +4,7 @@
#include <cmath>
#include <iosfwd>
#include <istream>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#include <sprout/random/random_result.hpp>
@ -59,7 +60,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType arg_check(IntType t_arg, RealType p_arg) {
return arg_check_nothrow(t_arg, p_arg)
? t_arg
: throw "assert(t_arg >= IntType(0) && RealType(0) <= p_arg && p_arg <= RealType(1))"
: throw std::invalid_argument("binomial_distribution<>: invalid argument (t_arg >= 0 && 0 <= p_arg && p_arg <= 1)")
;
}
public:

View file

@ -2,6 +2,7 @@
#define SPROUT_RANDOM_DETAIL_CONST_MOD_HPP
#include <limits>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
@ -31,7 +32,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType mult_schrage_1(IntType a, IntType value, IntType q, IntType r) {
return r < q
? sub(a * (value % q), r * (value / q))
: throw "assert(r < q)"
: throw std::domain_error("const_mod<>: domain error (r < q)")
;
}
static SPROUT_CONSTEXPR IntType mult_schrage(IntType a, IntType value) {
@ -40,7 +41,8 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType mult_general(IntType a, IntType b) {
return std::uintmax_t(modulus) <= std::numeric_limits<std::uintmax_t>::max() / modulus
? static_cast<IntType>(std::uintmax_t(a) * b % modulus)
: /*static_cast<IntType>(sprout::random::detail::mulmod(a, b, modulus))*/throw "Sorry, not implemented."
//: static_cast<IntType>(sprout::random::detail::mulmod(a, b, modulus)) // ???
: throw std::domain_error("const_mod<>: Sorry, not implemented.")
;
}
static SPROUT_CONSTEXPR IntType sub(IntType a, IntType b) {
@ -61,7 +63,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType invert_euclidian(IntType c) {
return c > 0
? c == 1 ? 1 : invert_euclidian_1(c, 0, 1, c, m)
: throw "assert(c > 0)"
: throw std::domain_error("const_mod<>: domain error (c > 0)")
;
}
static SPROUT_CONSTEXPR IntType invert_euclidian0_3(IntType c, IntType l1, IntType l2, IntType n, IntType p) {
@ -73,13 +75,13 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType invert_euclidian0_1(IntType c, IntType l1, IntType l2, IntType n, IntType p) {
return std::numeric_limits<IntType>::max() % n != n - 1
? invert_euclidian0_2(c, l1 + (std::numeric_limits<IntType>::max() / n) * l2, l2, n, std::numeric_limits<IntType>::max() - (std::numeric_limits<IntType>::max() / n) * n + 1)
: throw "assert(std::numeric_limits<IntType>::max() % n != n - 1)"
: throw std::domain_error("const_mod<>: domain error (numeric_limits<IntType>::max() % n != n - 1)")
;
}
static SPROUT_CONSTEXPR IntType invert_euclidian0(IntType c) {
return c > 0
? c == 1 ? 1 : invert_euclidian0_1(c, 0, 1, c, m)
: throw "assert(c > 0)"
: throw std::domain_error("const_mod<>: domain error (c > 0)")
;
}
public:

View file

@ -4,6 +4,7 @@
#include <cmath>
#include <ios>
#include <limits>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/random/uniform_01.hpp>
@ -35,7 +36,7 @@ namespace sprout {
static SPROUT_CONSTEXPR RealType arg_check(RealType p_arg) {
return arg_check_nothrow(p_arg)
? p_arg
: throw "assert(RealType(0) < p_arg && p_arg < RealType(1))"
: throw std::invalid_argument("geometric_distribution<>: invalid argument (0 < p_arg && p_arg < 1)")
;
}
public:

View file

@ -4,6 +4,7 @@
#include <cstdint>
#include <limits>
#include <ios>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/random/detail/const_mod.hpp>
#include <sprout/random/random_result.hpp>
@ -37,7 +38,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType arg_check(IntType const& x0) {
return arg_check_nothrow(x0)
? x0
: throw "assert(x0 >= static_min() && x0 <= static_max())"
: throw std::invalid_argument("inversive_congruential_engine<>: invalid argument (x0 >= static_min() && x0 <= static_max())")
;
}
static SPROUT_CONSTEXPR IntType init_seed_2(IntType const& x0) {

View file

@ -4,6 +4,7 @@
#include <cstdint>
#include <limits>
#include <ios>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/random/detail/const_mod.hpp>
#include <sprout/random/random_result.hpp>
@ -41,7 +42,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType arg_check(IntType const& x0) {
return arg_check_nothrow(x0)
? x0
: throw "assert(x0 >= static_min() && x0 <= static_max())"
: 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) {

View file

@ -5,6 +5,7 @@
#include <limits>
#include <ios>
#include <istream>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/random/uniform_01.hpp>
#include <sprout/random/random_result.hpp>
@ -30,7 +31,7 @@ namespace sprout {
static SPROUT_CONSTEXPR RealType arg_check(RealType mean_arg, RealType sigma_arg) {
return arg_check_nothrow(mean_arg, sigma_arg)
? mean_arg
: throw "assert(sigma_arg >= RealType(0))"
: throw std::invalid_argument("normal_distribution<>: invalid argument (sigma_arg >= 0)")
;
}
public:

View file

@ -69,7 +69,7 @@ namespace sprout {
SPROUT_CONSTEXPR random_iterator operator()() const {
return count_ != 0
? random_iterator(random_(), count_ > 0 ? count_ - 1 : count_)
: throw "assert(count_ != 0)"
: throw std::out_of_range("random_iterator<>: increment at out of range")
;
}
random_result_type& random_result() {
@ -119,13 +119,13 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0
? random_.result()
: (throw "assert(count_ != 0)", random_.result())
: (throw std::out_of_range("random_iterator<>: dereference at out of range"), random_.result())
;
}
SPROUT_CONSTEXPR pointer operator->() const {
return count_ != 0
? &random_.result()
: throw "assert(count_ != 0)"
: throw std::out_of_range("random_iterator<>: dereference at out of range")
;
}
random_iterator& operator++() {
@ -188,7 +188,7 @@ namespace sprout {
SPROUT_CONSTEXPR random_iterator operator()() const {
return count_ != 0
? random_iterator(random_(), count_ > 0 ? count_ - 1 : count_)
: throw "assert(count_ != 0)"
: throw std::out_of_range("random_iterator<>: increment at out of range")
;
}
random_result_type& random_result() {
@ -232,13 +232,13 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0
? random_.result()
: (throw "assert(count_ != 0)", random_.result())
: (throw std::out_of_range("random_iterator<>: dereference at out of range"), random_.result())
;
}
SPROUT_CONSTEXPR pointer operator->() const {
return count_ > 0
? &random_.result()
: throw "assert(count_ != 0)"
: throw std::out_of_range("random_iterator<>: dereference at out of range")
;
}
random_iterator& operator++() {

View file

@ -6,6 +6,7 @@
#include <limits>
#include <ios>
#include <istream>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
@ -102,7 +103,8 @@ namespace sprout {
k == 1 ? BaseUnsigned(0)
: brange < std::numeric_limits<BaseUnsigned>::max() / k ? BaseUnsigned(k * off / (brange + 1))
: brange < std::numeric_limits<std::uintmax_t>::max() / k ? static_cast<BaseUnsigned>(static_cast<std::uintmax_t>(off) * k / (static_cast<std::uintmax_t>(brange) + 1))
: /*static_cast<BaseUnsigned>(sprout::random::detail::muldiv(off, k, static_cast<std::uintmax_t>(brange) + 1))*/throw "Sorry, not implemented."
//: static_cast<BaseUnsigned>(sprout::random::detail::muldiv(off, k, static_cast<std::uintmax_t>(brange) + 1)) // ???
: throw std::domain_error("shuffle_order_engine<>: Sorry, not implemented.")
);
}
public:

View file

@ -4,6 +4,7 @@
#include <limits>
#include <ios>
#include <istream>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp>
@ -396,7 +397,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType arg_check(IntType min_arg, IntType max_arg) {
return arg_check_nothrow(min_arg, max_arg)
? min_arg
: throw "assert(min_arg <= max_arg)"
: throw std::invalid_argument("uniform_int_distribution<>: invalid argument (min_arg <= max_arg)")
;
}
public:

View file

@ -3,6 +3,7 @@
#include <ios>
#include <istream>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp>
@ -54,8 +55,8 @@ namespace sprout {
max_value,
numerator / divisor * (max_value - min_value) + min_value
)
: throw "assert(numerator >= 0 && numerator <= divisor)"
: throw "assert(divisor > 0)"
: throw std::domain_error("generate_uniform_real(): domain error (numerator >= 0 && numerator <= divisor)")
: throw std::domain_error("generate_uniform_real(): domain error (divisor > 0)")
;
}
template<typename Engine, typename T>
@ -123,8 +124,8 @@ namespace sprout {
max_value,
numerator / divisor * (max_value - min_value) + min_value
)
: throw "assert(numerator >= 0 && numerator <= divisor)"
: throw "assert(divisor > 0)"
: throw std::domain_error("generate_uniform_real(): domain error (numerator >= 0 && numerator <= divisor)")
: throw std::domain_error("generate_uniform_real(): domain error (divisor > 0)")
;
}
template<typename Engine, typename T>
@ -188,7 +189,7 @@ namespace sprout {
static SPROUT_CONSTEXPR RealType arg_check(RealType min_arg, RealType max_arg) {
return arg_check_nothrow(min_arg, max_arg)
? min_arg
: throw "assert(min_arg <= max_arg)"
: throw std::invalid_argument("uniform_real_distribution<>: invalid argument (min_arg <= max_arg)")
;
}
public:

View file

@ -3,6 +3,7 @@
#include <iosfwd>
#include <istream>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp>
@ -26,7 +27,7 @@ namespace sprout {
static SPROUT_CONSTEXPR IntType arg_check(IntType min_arg, IntType max_arg) {
return arg_check_nothrow(min_arg, max_arg)
? min_arg
: throw "assert(min_arg <= max_arg)"
: throw std::invalid_argument("uniform_smallint<>: invalid argument (min_arg <= max_arg)")
;
}
public: