1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +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

@ -12,8 +12,8 @@ namespace sprout {
template<std::size_t Bits>
struct high_bit_mask_t {
public:
typedef typename sprout::detail::uint_t<(Bits + 1)>::least least;
typedef typename sprout::detail::uint_t<(Bits + 1)>::fast fast;
typedef typename sprout::detail::uint_t<(Bits + 1)>::least least;
typedef typename sprout::detail::uint_t<(Bits + 1)>::fast fast;
public:
SPROUT_STATIC_CONSTEXPR least high_bit = least(1u) << Bits;
SPROUT_STATIC_CONSTEXPR fast high_bit_fast = fast(1u) << Bits;
@ -23,8 +23,8 @@ namespace sprout {
template<std::size_t Bits>
struct low_bits_mask_t {
public:
typedef typename sprout::detail::uint_t<Bits>::least least;
typedef typename sprout::detail::uint_t<Bits>::fast fast;
typedef typename sprout::detail::uint_t<Bits>::least least;
typedef typename sprout::detail::uint_t<Bits>::fast fast;
public:
SPROUT_STATIC_CONSTEXPR least sig_bits = ~(~(least(0u)) << Bits);
SPROUT_STATIC_CONSTEXPR fast sig_bits_fast = fast(sig_bits);
@ -35,9 +35,9 @@ namespace sprout {
template<> \
struct low_bits_mask_t<std::numeric_limits<Type>::digits> { \
public: \
typedef std::numeric_limits<Type> limits_type; \
typedef typename sprout::detail::uint_t<limits_type::digits>::least least; \
typedef typename sprout::detail::uint_t<limits_type::digits>::fast fast; \
typedef std::numeric_limits<Type> limits_type; \
typedef typename sprout::detail::uint_t<limits_type::digits>::least least; \
typedef typename sprout::detail::uint_t<limits_type::digits>::fast fast; \
public: \
SPROUT_STATIC_CONSTEXPR least sig_bits = ~(least(0u)); \
SPROUT_STATIC_CONSTEXPR fast sig_bits_fast = fast(sig_bits); \
@ -55,7 +55,7 @@ namespace sprout {
SPROUT_LOW_BITS_MASK_SPECIALIZE(unsigned long);
#endif
#if ULLONG_MAX > ULONG_MAX
SPROUT_LOW_BITS_MASK_SPECIALIZE(unsigned long long);
SPROUT_LOW_BITS_MASK_SPECIALIZE(unsigned long long);
#endif
#undef SPROUT_LOW_BITS_MASK_SPECIALIZE

View file

@ -4,6 +4,7 @@
#include <cstddef>
#include <iterator>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
@ -99,13 +100,13 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0
? holder_.get()
: (throw "assert(count_ != 0)", holder_.get())
: (throw std::out_of_range("value_iterator<>: dereference at out of range"), holder_.get())
;
}
SPROUT_CONSTEXPR pointer operator->() const {
return count_ != 0
? holder_.get_pointer()
: throw "assert(count_ != 0)"
: throw std::out_of_range("value_iterator<>: dereference at out of range")
;
}
value_iterator& operator++() {

View file

@ -3,6 +3,7 @@
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
@ -634,7 +635,7 @@ namespace sprout {
SPROUT_CONSTEXPR T factorial(std::size_t x) {
return x <= sprout::math::detail::factorials<T>::limit
? sprout::math::detail::factorials<T>::table[x]
: throw "assert(x <= sprout::math::detail::factorials<T>::limit)"
: throw std::invalid_argument("factorial(): argument limit exceeded")
;
}
} // namespace math

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:

View file

@ -54,9 +54,9 @@ namespace sprout {
;
}
static SPROUT_CONSTEXPR std::size_t length(char_type const* s) {
return !*s ? 0
: 1 + length(s + 1)
;
return !*s ? 0
: 1 + length(s + 1)
;
}
static SPROUT_CONSTEXPR char_type const* find(char_type const* s, std::size_t n, char_type const& a) {
return !n ? nullptr
@ -115,9 +115,9 @@ namespace sprout {
}
template<typename ConstIterator>
static SPROUT_CONSTEXPR std::size_t length(ConstIterator s) {
return !*s ? 0
: 1 + length(s + 1)
;
return !*s ? 0
: 1 + length(s + 1)
;
}
template<typename ConstIterator>
static SPROUT_CONSTEXPR ConstIterator find(ConstIterator s, std::size_t n, char_type const& a) {
@ -257,7 +257,7 @@ namespace sprout {
static SPROUT_CONSTEXPR basic_string<T, N, Traits> from_c_str(value_type const* s, size_type n) {
return !(N < n)
? from_c_str_impl(s, n, typename sprout::index_range<0, N>::type())
: throw "basic_string<>: index out of range"
: throw std::out_of_range("basic_string<>: index out of range")
;
}
static SPROUT_CONSTEXPR basic_string<T, N, Traits> from_c_str(value_type const* s) {
@ -465,7 +465,7 @@ namespace sprout {
? n == npos
? substr(pos, size() - pos)
: from_c_str(c_str() + pos, n)
: throw "basic_string<>: index out of range"
: throw std::out_of_range("basic_string<>: index out of range")
;
}
template<std::size_t N2>
@ -486,13 +486,13 @@ namespace sprout {
SPROUT_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string<T, N2, Traits> const& str, size_type pos2, size_type n2) const {
return !(str.size() < pos2)
? compare(pos1, n1, str.begin() + pos2, NS_SSCRISK_CEL_OR_SPROUT_DETAIL::min(n2, str.size() - pos2))
: throw "basic_string<>: index out of range"
: throw std::out_of_range("basic_string<>: index out of range")
;
}
SPROUT_CONSTEXPR int compare(size_type pos1, size_type n1, value_type const* s, size_type n2) const {
return !(size() < pos1)
? compare_impl_1(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT_DETAIL::min(n1, size() - pos1), s, n2)
: throw "basic_string<>: index out of range"
: throw std::out_of_range("basic_string<>: index out of range")
;
}
// others:
@ -560,7 +560,7 @@ namespace sprout {
>::type compare(size_type pos1, size_type n1, ConstIterator s, size_type n2) const {
return !(size() < pos1)
? compare_impl_1(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT_DETAIL::min(n1, size() - pos1), s, n2)
: throw "basic_string<>: index out of range"
: throw std::out_of_range("basic_string<>: index out of range")
;
}
#endif

View file

@ -17,7 +17,7 @@ namespace sprout {
private:
typedef typename result_type::value_type value_type;
private:
sprout::sha1 sha_;
sprout::sha1 sha_;
private:
SPROUT_CONSTEXPR result_type sha_to_uuid_1(sprout::sha1::value_type const& value) const {
return result_type{{

View file

@ -4,6 +4,7 @@
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/uuid/uuid.hpp>
@ -30,7 +31,10 @@ namespace sprout {
Iterator last;
public:
SPROUT_CONSTEXPR next_char(Iterator f, Iterator l)
: c(f != l ? *f : throw "string_generator: invalid uuid string (out of range)")
: c(f != l
? *f
: throw std::domain_error("string_generator: invalid uuid string (out of range)")
)
, first(sprout::next(f))
, last(l)
{}
@ -42,7 +46,7 @@ namespace sprout {
SPROUT_CONSTEXPR std::uint8_t value_at(std::size_t i) const {
return i < 22
? sprout::uuids::detail::values<void>::table[i]
: throw "string_generator: invalid uuid string (invalid character)"
: throw std::domain_error("string_generator: invalid uuid string (invalid character)")
;
}
template<typename Elem>
@ -110,7 +114,7 @@ namespace sprout {
return has_dashes
? is_dash(nc.c)
? generate_2_2(nc.next(), open_brace, has_dashes, args...)
//: throw "string_generator: invalid uuid string (dashes not found)" // ???
//: throw std::domain_error("string_generator: invalid uuid string (dashes not found)") // ???
: generate_2_2(nc, open_brace, has_dashes, args...)
: generate_2_2(nc, open_brace, has_dashes, args...)
;
@ -139,7 +143,7 @@ namespace sprout {
>::type generate_2(next_char<Iterator> nc, Char open_brace, bool has_dashes, Args... args) const {
return !open_brace || (open_brace && is_close_brace(nc.next().c, open_brace))
? result_type{{args...}}
: throw "string_generator: invalid uuid string (brace not closed)"
: throw std::domain_error("string_generator: invalid uuid string (brace not closed)")
;
}
template<typename Iterator, typename Char, typename... Args>

View file

@ -29,7 +29,7 @@ namespace sprout {
//
class uuid {
public:
typedef std::uint8_t value_type;
typedef std::uint8_t value_type;
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
typedef sprout::index_iterator<uuid&> iterator;
typedef sprout::index_iterator<uuid const&> const_iterator;