mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-01-23 20:46:37 +00:00
add SPROUT_ASSERT
This commit is contained in:
parent
a5e14e71e1
commit
07f052fb6e
32 changed files with 386 additions and 284 deletions
195
sprout/assert.hpp
Normal file
195
sprout/assert.hpp
Normal file
|
@ -0,0 +1,195 @@
|
|||
#ifndef SPROUT_ASEERT_HPP
|
||||
#define SPROUT_ASEERT_HPP
|
||||
|
||||
#if defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG)
|
||||
# include <sprout/config.hpp>
|
||||
#elif defined(SPROUT_ENABLE_ASSERT_HANDLER)
|
||||
# include <sprout/config.hpp>
|
||||
# include <sprout/adl/not_found.hpp>
|
||||
#else
|
||||
# include <cstdlib>
|
||||
# include <iostream>
|
||||
# include <sprout/config.hpp>
|
||||
#endif
|
||||
#if !(defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG))
|
||||
# include <sprout/preprocessor/stringize.hpp>
|
||||
#endif
|
||||
|
||||
#if !(defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG))
|
||||
//
|
||||
// SPROUT_ASSERTION_FAILED_FORMAT
|
||||
//
|
||||
# ifndef SPROUT_ASSERTION_FAILED_FORMAT
|
||||
# define SPROUT_ASSERTION_FAILED_FORMAT(expr, file, line) \
|
||||
"***** Internal Program Error - assertion (" #expr ") failed: " file "(" SPROUT_PP_STRINGIZE(line) ")"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// SPROUT_ASSERT
|
||||
//
|
||||
|
||||
#if defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG)
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
assertion_disabled() SPROUT_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_ASSERT(expr) \
|
||||
(sprout::detail::assertion_disabled())
|
||||
|
||||
#elif defined(SPROUT_ENABLE_ASSERT_HANDLER)
|
||||
|
||||
namespace sprout_adl {
|
||||
SPROUT_CONSTEXPR sprout::not_found_via_adl assertion_failed(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout_assertion_detail {
|
||||
using sprout_adl::assertion_failed;
|
||||
|
||||
//template<typename Dummy>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
call_assertion_failed(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) {
|
||||
return cond ? true
|
||||
: (assertion_failed(expr, function, file, line), false)
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
// //
|
||||
// // assertion_failed
|
||||
// // * user defined
|
||||
// //
|
||||
// void
|
||||
// assertion_failed(char const* expr, char const* function, char const* file, long line);
|
||||
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
assertion_check(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) {
|
||||
return cond ? true
|
||||
: sprout_assertion_detail::call_assertion_failed(cond, formatted, expr, function, file, line)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_ASSERT(expr) ( \
|
||||
sprout::detail::assertion_check( \
|
||||
(expr), SPROUT_ASSERTION_FAILED_FORMAT(expr, __FILE__, __LINE__), \
|
||||
#expr, "(unknown)"/*SPROUT_CURRENT_FUNCTION*/, __FILE__, __LINE__) \
|
||||
)
|
||||
|
||||
#else
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline bool
|
||||
assertion_failed(char const* formatted) {
|
||||
return (std::cerr << formatted << std::endl), std::abort(), false;
|
||||
}
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
assertion_check(bool cond, char const* formatted) {
|
||||
return cond ? true
|
||||
: sprout::detail::assertion_failed(formatted)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_ASSERT(expr) \
|
||||
(sprout::detail::assertion_check((expr), SPROUT_ASSERTION_FAILED_FORMAT(expr, __FILE__, __LINE__)))
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// SPROUT_ASSERT_MSG
|
||||
//
|
||||
|
||||
#if defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG)
|
||||
|
||||
# define SPROUT_ASSERT_MSG(expr, msg) \
|
||||
(sprout::detail::assertion_disabled())
|
||||
|
||||
#elif defined(SPROUT_ENABLE_ASSERT_HANDLER)
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// assertion_failed_msg
|
||||
// * user defined
|
||||
//
|
||||
void
|
||||
assertion_failed_msg(char const* expr, char const* msg, char const* function, char const* file, long line);
|
||||
|
||||
namespace detail {
|
||||
inline bool
|
||||
assertion_failed_msg(char const* formatted, char const* expr, char const* msg, char const* function, char const* file, long line) {
|
||||
return sprout::assertion_failed_msg(expr, msg, function, file, line), false;
|
||||
}
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
assertion_check_msg(bool cond, char const* formatted, char const* expr, char const* msg, char const* function, char const* file, long line) {
|
||||
return cond ? true
|
||||
: sprout::detail::assertion_failed_msg(formatted, expr, msg, function, file, line)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_ASSERT_MSG(expr, msg) ( \
|
||||
sprout::detail::assertion_check_msg( \
|
||||
(expr), SPROUT_ASSERTION_FAILED_FORMAT(expr, __FILE__, __LINE__), \
|
||||
#expr, msg, "(unknown)"/*SPROUT_CURRENT_FUNCTION*/, __FILE__, __LINE__) \
|
||||
)
|
||||
|
||||
#else
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline bool
|
||||
assertion_failed_msg(char const* formatted, char const* msg) {
|
||||
return (std::cerr << formatted << ": " << msg << std::endl), std::abort(), false;
|
||||
}
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
assertion_check_msg(bool cond, char const* formatted, char const* msg) {
|
||||
return cond ? true
|
||||
: sprout::detail::assertion_failed_msg(formatted, msg)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_ASSERT_MSG(expr, msg) \
|
||||
(sprout::detail::assertion_check_msg((expr), SPROUT_ASSERTION_FAILED_FORMAT(expr, __FILE__, __LINE__), msg))
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// SPROUT_VERIFY
|
||||
//
|
||||
|
||||
#if defined(SPROUT_DISABLE_ASSERTS) || (!defined(SPROUT_ENABLE_ASSERT_HANDLER) && defined(NDEBUG))
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
verification_disabled(bool) SPROUT_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
# define SPROUT_VERIFY(expr) \
|
||||
(sprout::detail::verification_disabled((expr)))
|
||||
|
||||
#else
|
||||
|
||||
# define SPROUT_VERIFY(expr) SPROUT_ASSERT(expr)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_ASEERT_HPP
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -72,12 +73,11 @@ namespace sprout {
|
|||
>::type
|
||||
bit_reverse_in(IntType x, std::size_t length) {
|
||||
typedef typename std::make_unsigned<IntType>::type unsigned_type;
|
||||
return length <= sizeof(IntType) * CHAR_BIT
|
||||
? static_cast<IntType>(
|
||||
return SPROUT_ASSERT(length <= sizeof(IntType) * CHAR_BIT),
|
||||
static_cast<IntType>(
|
||||
sprout::detail::bit_rev<sizeof(IntType)>().template operator()<unsigned_type>(x)
|
||||
>> (sizeof(IntType) * CHAR_BIT - length)
|
||||
)
|
||||
: throw std::invalid_argument("invalid length")
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <sprout/breed/breed_fwd.hpp>
|
||||
#include <sprout/breed/args.hpp>
|
||||
#include <sprout/breed/traits.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace breed {
|
||||
|
@ -34,7 +35,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename T, typename Expr, typename Arg, std::size_t N>
|
||||
SPROUT_CONSTEXPR Expr make_terminal(T const (&t)[N], Expr const*, sprout::breed::term<Arg[N]> const*) {
|
||||
return throw "Sorry, not implemented.", Expr();
|
||||
return SPROUT_ASSERT_MSG(0, "Sorry, not implemented."), Expr();
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
|
|
43
sprout/current_function.hpp
Normal file
43
sprout/current_function.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef SPROUT_CURRENT_FUNCTION_HPP
|
||||
#define SPROUT_CURRENT_FUNCTION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
inline void
|
||||
current_function_helper() {
|
||||
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __PRETTY_FUNCTION__
|
||||
|
||||
#elif defined(__DMC__) && (__DMC__ >= 0x810)
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __PRETTY_FUNCTION__
|
||||
|
||||
#elif defined(__FUNCSIG__)
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __FUNCSIG__
|
||||
|
||||
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __FUNCTION__
|
||||
|
||||
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __FUNC__
|
||||
|
||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION __func__
|
||||
|
||||
#else
|
||||
|
||||
# define SPROUT_CURRENT_FUNCTION "(unknown)"
|
||||
|
||||
#endif
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CURRENT_FUNCTION_HPP
|
|
@ -5,22 +5,23 @@
|
|||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Elem, typename IntType>
|
||||
inline SPROUT_CONSTEXPR Elem
|
||||
int_to_char(IntType val, int base) {
|
||||
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
|
||||
: val >= 10 && val < static_cast<IntType>(base) ? static_cast<Elem>('a') + (val - 10)
|
||||
: throw std::invalid_argument("value out of bounds")
|
||||
return SPROUT_ASSERT(2 <= base && base <= 36), SPROUT_ASSERT(IntType(0) <= val && val < static_cast<IntType>(base)),
|
||||
val < 10 ? static_cast<Elem>('0') + val
|
||||
: static_cast<Elem>('a') + (val - 10)
|
||||
;
|
||||
}
|
||||
template<typename Elem, typename IntType>
|
||||
inline SPROUT_CONSTEXPR Elem
|
||||
int_to_char(IntType val) {
|
||||
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
|
||||
: throw std::invalid_argument("value out of bounds")
|
||||
return SPROUT_ASSERT(IntType(0) <= val && val < IntType(10)),
|
||||
static_cast<Elem>('0') + val
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next_fwd.hpp>
|
||||
#include <sprout/iterator/prev_fwd.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout_adl {
|
||||
sprout::not_found_via_adl iterator_next(...);
|
||||
|
@ -82,9 +82,9 @@ namespace sprout {
|
|||
std::forward_iterator_tag*
|
||||
)
|
||||
{
|
||||
return n == 0 ? it
|
||||
: n > 0 ? sprout::iterator_detail::next_impl_2(it, n)
|
||||
: throw std::domain_error("next: nagative distance is invalid ForwardIterator")
|
||||
return SPROUT_ASSERT(n >= 0),
|
||||
n == 0 ? it
|
||||
: sprout::iterator_detail::next_impl_2(it, n)
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#define SPROUT_MATH_BERNOULLI_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
|
@ -233,11 +233,10 @@ namespace sprout {
|
|||
template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
|
||||
inline SPROUT_CONSTEXPR T bernoulli_number(std::size_t x) {
|
||||
typedef typename std::remove_cv<T>::type type;
|
||||
return x <= sprout::math::bernoulli_number_limit<type>()
|
||||
? x == 1 ? type(-1) / 2
|
||||
return SPROUT_ASSERT(x <= sprout::math::bernoulli_number_limit<type>()),
|
||||
x == 1 ? type(-1) / 2
|
||||
: x % 2 ? type(0)
|
||||
: sprout::math::detail::bernoulli_numbers<type>::table[x / 2]
|
||||
: throw std::invalid_argument("bernoulli_number(): argument limit exceeded")
|
||||
;
|
||||
}
|
||||
} // namespace math
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ceil: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ceil: large float rounding."), x)
|
||||
: x < 0 ? -static_cast<FloatType>(static_cast<std::uintmax_t>(-x))
|
||||
: sprout::math::detail::ceil_impl(x, static_cast<FloatType>(static_cast<std::uintmax_t>(x)))
|
||||
;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#define SPROUT_MATH_FACTORIAL_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/type_traits/is_int.hpp>
|
||||
#include <sprout/type_traits/is_uint.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
|
@ -767,9 +767,8 @@ namespace sprout {
|
|||
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
|
||||
inline SPROUT_CONSTEXPR T factorial(std::size_t x) {
|
||||
typedef typename std::remove_cv<T>::type type;
|
||||
return x <= sprout::math::factorial_limit<type>()
|
||||
? sprout::math::detail::factorials<type>::table[x]
|
||||
: throw std::invalid_argument("factorial(): argument limit exceeded")
|
||||
return SPROUT_ASSERT(x <= sprout::math::factorial_limit<type>()),
|
||||
sprout::math::detail::factorials<type>::table[x]
|
||||
;
|
||||
}
|
||||
} // namespace math
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("floor: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("floor: large float rounding."), x)
|
||||
: x < 0 ? sprout::math::detail::floor_impl(x, -static_cast<FloatType>(static_cast<std::uintmax_t>(-x)))
|
||||
: static_cast<FloatType>(static_cast<std::uintmax_t>(x))
|
||||
;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
iceil_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
iceil(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
: sprout::math::detail::iceil_impl(x, static_cast<To>(x))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
ifloor_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
ifloor(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
: sprout::math::detail::ifloor_impl(x, static_cast<To>(x))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
iround_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iround: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iround: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace sprout {
|
|||
iround(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iround: large float irounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iround: large float irounding."), x)
|
||||
: x < 0 ? sprout::math::detail::iround_impl_nagative(x, static_cast<To>(x))
|
||||
: sprout::math::detail::iround_impl_positive(x, static_cast<To>(x))
|
||||
;
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
itrunc_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace sprout {
|
|||
itrunc(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("round: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("round: large float rounding."), x)
|
||||
: x < 0 ? sprout::math::detail::round_impl_nagative(x, -static_cast<FloatType>(static_cast<std::uintmax_t>(-x)))
|
||||
: sprout::math::detail::round_impl_positive(x, static_cast<FloatType>(static_cast<std::uintmax_t>(x)))
|
||||
;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("trunc: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("trunc: large float rounding."), x)
|
||||
: x < 0 ? -static_cast<FloatType>(static_cast<std::uintmax_t>(-x))
|
||||
: static_cast<FloatType>(static_cast<std::uintmax_t>(x))
|
||||
;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef SPROUT_OPTIONAL_OPTIONAL_HPP
|
||||
#define SPROUT_OPTIONAL_OPTIONAL_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/none.hpp>
|
||||
#include <sprout/optional/nullopt.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -120,13 +120,13 @@ namespace sprout {
|
|||
return get();
|
||||
}
|
||||
SPROUT_CONSTEXPR reference_const_type get() const {
|
||||
return is_initialized() ? val.get()
|
||||
: (throw std::domain_error("optional: value not initialized"), val.get())
|
||||
return SPROUT_ASSERT(is_initialized()) ? val.get()
|
||||
: val.get()
|
||||
;
|
||||
}
|
||||
reference_type get() {
|
||||
return is_initialized() ? val.get()
|
||||
: (throw std::domain_error("optional: value not initialized"), val.get())
|
||||
return SPROUT_ASSERT(is_initialized()) ? val.get()
|
||||
: val.get()
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference_const_type get_value_or(reference_const_type& v) const {
|
||||
|
@ -141,23 +141,23 @@ namespace sprout {
|
|||
}
|
||||
|
||||
SPROUT_CONSTEXPR pointer_const_type operator->() const {
|
||||
return is_initialized() ? val.get_pointer()
|
||||
: throw std::domain_error("optional: value not initialized")
|
||||
return SPROUT_ASSERT(is_initialized()),
|
||||
val.get_pointer()
|
||||
;
|
||||
}
|
||||
pointer_type operator->() {
|
||||
return is_initialized() ? val.get_pointer()
|
||||
: throw std::domain_error("optional: value not initialized")
|
||||
return SPROUT_ASSERT(is_initialized()),
|
||||
val.get_pointer()
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer_const_type get_pointer() const {
|
||||
return is_initialized() ? val.get_pointer()
|
||||
: throw std::domain_error("optional: value not initialized")
|
||||
return SPROUT_ASSERT(is_initialized()),
|
||||
val.get_pointer()
|
||||
;
|
||||
}
|
||||
pointer_type get_pointer() {
|
||||
return is_initialized() ? val.get_pointer()
|
||||
: throw std::domain_error("optional: value not initialized")
|
||||
return SPROUT_ASSERT(is_initialized()),
|
||||
val.get_pointer()
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer_const_type get_ptr() const {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP
|
||||
|
||||
#include <iosfwd>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -16,16 +16,6 @@ namespace sprout {
|
|||
public:
|
||||
typedef int input_type;
|
||||
typedef bool result_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) {
|
||||
return p_arg >= 0 && p_arg <= 1;
|
||||
}
|
||||
static SPROUT_CONSTEXPR RealType arg_check(RealType p_arg) {
|
||||
return arg_check_nothrow(p_arg)
|
||||
? p_arg
|
||||
: throw std::invalid_argument("bernoulli_distribution<>: invalid argument (p_arg >= 0 && p_arg <= 1)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -33,10 +23,6 @@ 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:
|
||||
|
@ -44,7 +30,7 @@ namespace sprout {
|
|||
: p_(RealType(0.5))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(RealType p_arg)
|
||||
: p_(arg_check(p_arg))
|
||||
: p_((SPROUT_ASSERT(p_arg >= RealType(0)), SPROUT_ASSERT(p_arg <= RealType(1)), p_arg))
|
||||
{}
|
||||
SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT {
|
||||
return p_;
|
||||
|
@ -57,7 +43,7 @@ namespace sprout {
|
|||
{
|
||||
RealType p;
|
||||
if (lhs >> p) {
|
||||
if (arg_check_nothrow(p)) {
|
||||
if (p >= RealType(0) && p <= RealType(1)) {
|
||||
rhs.p_ = p;
|
||||
} else {
|
||||
lhs.setstate(std::ios_base::failbit);
|
||||
|
@ -99,7 +85,7 @@ namespace sprout {
|
|||
: p_(RealType(0.5))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR bernoulli_distribution(RealType p_arg)
|
||||
: p_(arg_check(p_arg))
|
||||
: p_((SPROUT_ASSERT(p_arg >= RealType(0)), SPROUT_ASSERT(p_arg <= RealType(1)), p_arg))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR bernoulli_distribution(param_type const& parm)
|
||||
: p_(parm.p())
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <iosfwd>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/cstdlib/abs.hpp>
|
||||
|
@ -14,6 +13,7 @@
|
|||
#include <sprout/math/floor.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||
# include <sprout/workaround/recursive_function_template.hpp>
|
||||
#endif
|
||||
|
@ -69,16 +69,6 @@ namespace sprout {
|
|||
RealType v_r;
|
||||
RealType u_rv_r;
|
||||
};
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType t_arg, RealType p_arg) {
|
||||
return t_arg >= IntType(0) && RealType(0) <= p_arg && p_arg <= RealType(1);
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType arg_check(IntType t_arg, RealType p_arg) {
|
||||
return arg_check_nothrow(t_arg, p_arg)
|
||||
? t_arg
|
||||
: throw std::invalid_argument("binomial_distribution<>: invalid argument (t_arg >= 0 && 0 <= p_arg && p_arg <= 1)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -86,10 +76,6 @@ 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_;
|
||||
|
@ -99,8 +85,8 @@ namespace sprout {
|
|||
, p_(0.5)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(IntType t_arg, RealType p_arg = RealType(0.5))
|
||||
: t_(arg_check(t_arg, p_arg))
|
||||
, p_(p_arg)
|
||||
: t_((SPROUT_ASSERT(t_arg >= IntType(0)), t_arg))
|
||||
, p_((SPROUT_ASSERT(RealType(0) <= p_arg && p_arg <= RealType(1)), p_arg))
|
||||
{}
|
||||
SPROUT_CONSTEXPR IntType t() const SPROUT_NOEXCEPT {
|
||||
return t_;
|
||||
|
@ -117,7 +103,7 @@ namespace sprout {
|
|||
IntType t;
|
||||
RealType p;
|
||||
if (lhs >> t >> std::ws >> p) {
|
||||
if (arg_check_nothrow(t, p)) {
|
||||
if (t >= IntType(0) && RealType(0) <= p && p <= RealType(1)) {
|
||||
rhs.t_ = t;
|
||||
rhs.p_ = p;
|
||||
} else {
|
||||
|
@ -622,8 +608,8 @@ namespace sprout {
|
|||
, q_n_(init_use_inversion(1, RealType(0.5)) ? init_q_n(1, RealType(0.5)) : RealType())
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR binomial_distribution(IntType t_arg, RealType p_arg = RealType(0.5))
|
||||
: t_(arg_check(t_arg, p_arg))
|
||||
, p_(p_arg)
|
||||
: t_((SPROUT_ASSERT(t_arg >= IntType(0)), t_arg))
|
||||
, p_((SPROUT_ASSERT(RealType(0) <= p_arg && p_arg <= RealType(1)), p_arg))
|
||||
, m_(init_m(t_arg, p_arg))
|
||||
, btrd_(!init_use_inversion(t_arg, p_arg) ? init_btrd(t_arg, p_arg) : btrd_type())
|
||||
, q_n_(init_use_inversion(t_arg, p_arg) ? init_q_n(t_arg, p_arg) : RealType())
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define SPROUT_RANDOM_DETAIL_CONST_MOD_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||
# include <sprout/workaround/recursive_function_template.hpp>
|
||||
#endif
|
||||
|
@ -17,10 +17,10 @@ namespace sprout {
|
|||
private:
|
||||
typedef typename std::make_unsigned<IntType>::type unsigned_type;
|
||||
private:
|
||||
SPROUT_STATIC_CONSTEXPR IntType suppress_warnings = m == 0;
|
||||
SPROUT_STATIC_CONSTEXPR IntType modulus = m + suppress_warnings;
|
||||
SPROUT_STATIC_CONSTEXPR IntType supress_warnings = m == 0;
|
||||
SPROUT_STATIC_CONSTEXPR IntType modulus = m + supress_warnings;
|
||||
private:
|
||||
static_assert(suppress_warnings == 0, "suppress_warnings == 0");
|
||||
static_assert(supress_warnings == 0, "supress_warnings == 0");
|
||||
static_assert(modulus == m, "modulus == m");
|
||||
private:
|
||||
static SPROUT_CONSTEXPR IntType pow_1(IntType a, std::uintmax_t exponent, IntType result = 1) {
|
||||
|
@ -30,12 +30,11 @@ namespace sprout {
|
|||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType mult_small(IntType a, IntType x) {
|
||||
return a * x % (m + suppress_warnings);
|
||||
return a * x % (m + supress_warnings);
|
||||
}
|
||||
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 std::domain_error("const_mod<>: domain error (r < q)")
|
||||
return SPROUT_ASSERT(r < q),
|
||||
sub(a * (value % q), r * (value / q))
|
||||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType mult_schrage(IntType a, IntType value) {
|
||||
|
@ -45,7 +44,7 @@ namespace sprout {
|
|||
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 std::domain_error("const_mod<>: Sorry, not implemented.")
|
||||
: (SPROUT_ASSERT_MSG(0, "Sorry, not implemented."), IntType())
|
||||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType sub(IntType a, IntType b) {
|
||||
|
@ -81,9 +80,8 @@ namespace sprout {
|
|||
}
|
||||
template<int D = 16, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian(IntType c) {
|
||||
return c > 0
|
||||
? c == 1 ? 1 : invert_euclidian_1<D + 1>(c, 0, 1, c, m)
|
||||
: throw std::domain_error("const_mod<>: domain error (c > 0)")
|
||||
return SPROUT_ASSERT(c > 0),
|
||||
c == 1 ? 1 : invert_euclidian_1<D + 1>(c, 0, 1, c, m)
|
||||
;
|
||||
}
|
||||
template<int D = 16, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||
|
@ -108,12 +106,11 @@ namespace sprout {
|
|||
}
|
||||
template<int D, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||
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<D + 1>(
|
||||
return SPROUT_ASSERT_MSG(std::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
invert_euclidian0_2<D + 1>(
|
||||
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 std::domain_error("const_mod<>: domain error (numeric_limits<IntType>::max() % n != n - 1)")
|
||||
;
|
||||
}
|
||||
template<int D, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||
|
@ -122,9 +119,8 @@ namespace sprout {
|
|||
}
|
||||
template<int D = 16, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian0(IntType c) {
|
||||
return c > 0
|
||||
? c == 1 ? 1 : invert_euclidian0_1<D + 1>(c, 0, 1, c, m)
|
||||
: throw std::domain_error("const_mod<>: domain error (c > 0)")
|
||||
return SPROUT_ASSERT(c > 0),
|
||||
c == 1 ? 1 : invert_euclidian0_1<D + 1>(c, 0, 1, c, m)
|
||||
;
|
||||
}
|
||||
template<int D = 16, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
|
||||
|
@ -142,9 +138,8 @@ namespace sprout {
|
|||
return invert_euclidian_2(c, l1 + (p / n) * l2, l2, n, p - (p / n) * n);
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian(IntType c) {
|
||||
return c > 0
|
||||
? c == 1 ? 1 : invert_euclidian_1(c, 0, 1, c, m)
|
||||
: throw std::domain_error("const_mod<>: domain error (c > 0)")
|
||||
return SPROUT_ASSERT(c > 0),
|
||||
c == 1 ? 1 : invert_euclidian_1(c, 0, 1, c, m)
|
||||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType invert_euclidian0_3(IntType c, IntType l1, IntType l2, IntType n, IntType p) {
|
||||
|
@ -154,18 +149,16 @@ namespace sprout {
|
|||
return p == 0 ? l2 : invert_euclidian0_3(c, l1, l2 + (n / p) * l1, n - (n / p) * p, p);
|
||||
}
|
||||
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(
|
||||
return SPROUT_ASSERT_MSG(std::numeric_limits<IntType>::max() % n != n - 1, "c must be relatively prime to m."),
|
||||
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 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 std::domain_error("const_mod<>: domain error (c > 0)")
|
||||
return SPROUT_ASSERT(c > 0),
|
||||
c == 1 ? 1 : invert_euclidian0_1(c, 0, 1, c, m)
|
||||
;
|
||||
}
|
||||
#endif
|
||||
|
@ -173,7 +166,7 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR IntType apply(IntType x) {
|
||||
return ((unsigned_m() - 1) & unsigned_m()) == 0
|
||||
? (unsigned_type(x)) & (unsigned_m() - 1)
|
||||
: x % (m + suppress_warnings)
|
||||
: x % (m + supress_warnings)
|
||||
;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType add(IntType x, IntType c) {
|
||||
|
@ -195,7 +188,7 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR IntType mult_add(IntType a, IntType x, IntType c) {
|
||||
return ((unsigned_m() - 1) & unsigned_m()) == 0 ? (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1)
|
||||
: a == 0 ? c
|
||||
: m <= (std::numeric_limits<IntType>::max() - c) / a ? (a * x + c) % (m + suppress_warnings)
|
||||
: m <= (std::numeric_limits<IntType>::max() - c) / a ? (a * x + c) % (m + supress_warnings)
|
||||
: add(mult(a, x), c)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include <ios>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/math/floor.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -20,16 +20,6 @@ namespace sprout {
|
|||
public:
|
||||
typedef RealType input_type;
|
||||
typedef IntType result_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) {
|
||||
return RealType(0) < p_arg && p_arg < RealType(1);
|
||||
}
|
||||
static SPROUT_CONSTEXPR RealType arg_check(RealType p_arg) {
|
||||
return arg_check_nothrow(p_arg)
|
||||
? p_arg
|
||||
: throw std::invalid_argument("geometric_distribution<>: invalid argument (0 < p_arg && p_arg < 1)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -37,10 +27,6 @@ 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:
|
||||
|
@ -48,7 +34,7 @@ namespace sprout {
|
|||
: p_(RealType(0.5))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(RealType p_arg)
|
||||
: p_(arg_check(p_arg))
|
||||
: p_((SPROUT_ASSERT(RealType(0) < p_arg), SPROUT_ASSERT(p_arg < RealType(1)), p_arg))
|
||||
{}
|
||||
SPROUT_CONSTEXPR RealType p() const SPROUT_NOEXCEPT {
|
||||
return p_;
|
||||
|
@ -61,7 +47,7 @@ namespace sprout {
|
|||
{
|
||||
RealType p;
|
||||
if (lhs >> p) {
|
||||
if (arg_check_nothrow(p)) {
|
||||
if (RealType(0) < p && p < RealType(1)) {
|
||||
rhs.p_ = p;
|
||||
} else {
|
||||
lhs.setstate(std::ios_base::failbit);
|
||||
|
@ -112,7 +98,7 @@ namespace sprout {
|
|||
, log_1mp_(init_log_1mp(RealType(0.5)))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR geometric_distribution(RealType p_arg)
|
||||
: p_(arg_check(p_arg))
|
||||
: p_((SPROUT_ASSERT(RealType(0) < p_arg), SPROUT_ASSERT(p_arg < RealType(1)), p_arg))
|
||||
, log_1mp_(init_log_1mp(p_arg))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR geometric_distribution(param_type const& parm)
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <ios>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/detail/const_mod.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/math/comparison.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -33,27 +34,11 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR result_type static_max() SPROUT_NOEXCEPT {
|
||||
return modulus - 1;
|
||||
}
|
||||
private:
|
||||
template<typename T>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<!(b == 0) && std::is_unsigned<T>::value, bool>::type
|
||||
arg_check_nothrow(T const& x0) {
|
||||
return x0 <= static_max();
|
||||
}
|
||||
template<typename T>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<!(!(b == 0) && std::is_unsigned<T>::value), bool>::type
|
||||
arg_check_nothrow(T const& x0) {
|
||||
return x0 >= static_min() && x0 <= static_max();
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType arg_check(IntType const& x0) {
|
||||
return arg_check_nothrow(x0)
|
||||
? x0
|
||||
: throw std::invalid_argument(
|
||||
"inversive_congruential_engine<>: invalid argument (x0 >= static_min() && x0 <= static_max())"
|
||||
)
|
||||
;
|
||||
static SPROUT_CONSTEXPR IntType init_seed_3(IntType const& x0) {
|
||||
return SPROUT_ASSERT(sprout::math::greater_equal(x0, static_min())), SPROUT_ASSERT(x0 <= static_max()), x0;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType init_seed_2(IntType const& x0) {
|
||||
return arg_check(increment == 0 && x0 == 0 ? 1 : x0);
|
||||
return init_seed_3(increment == 0 && x0 == 0 ? 1 : x0);
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType init_seed_1(IntType const& x0) {
|
||||
return init_seed_2(x0 <= 0 && x0 != 0 ? x0 + modulus : x0);
|
||||
|
@ -105,7 +90,7 @@ namespace sprout {
|
|||
{
|
||||
IntType x;
|
||||
if (lhs >> x) {
|
||||
if(arg_check_nothrow(x)) {
|
||||
if (sprout::math::greater_equal(x, static_min()) && x <= static_max()) {
|
||||
rhs.x_ = x;
|
||||
} else {
|
||||
lhs.setstate(std::ios_base::failbit);
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <ios>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/detail/const_mod.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/math/comparison.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -37,23 +38,11 @@ namespace sprout {
|
|||
return m - 1;
|
||||
}
|
||||
private:
|
||||
template<typename T>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<!(c == 0) && std::is_unsigned<T>::value, bool>::type
|
||||
arg_check_nothrow(T const& x0) {
|
||||
return x0 <= static_max();
|
||||
}
|
||||
template<typename T>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<!(!(c == 0) && std::is_unsigned<T>::value), bool>::type
|
||||
arg_check_nothrow(T const& x0) {
|
||||
return x0 >= static_min() && x0 <= static_max();
|
||||
}
|
||||
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 UIntType init_seed_3(UIntType const& x0) {
|
||||
return SPROUT_ASSERT(sprout::math::greater_equal(x0, static_min())), SPROUT_ASSERT(x0 <= static_max()), x0;
|
||||
}
|
||||
static SPROUT_CONSTEXPR UIntType init_seed_2(UIntType const& x0) {
|
||||
return arg_check(increment == 0 && x0 == 0 ? 1 : x0);
|
||||
return init_seed_3(increment == 0 && x0 == 0 ? 1 : x0);
|
||||
}
|
||||
static SPROUT_CONSTEXPR UIntType init_seed_1(UIntType const& x0) {
|
||||
return init_seed_2(x0 <= 0 && x0 != 0 ? x0 + modulus : x0);
|
||||
|
@ -103,7 +92,7 @@ namespace sprout {
|
|||
{
|
||||
UIntType x;
|
||||
if (lhs >> x) {
|
||||
if(arg_check_nothrow(x)) {
|
||||
if (sprout::math::greater_equal(x, static_min()) && x <= static_max()) {
|
||||
rhs.x_ = x;
|
||||
} else {
|
||||
lhs.setstate(std::ios_base::failbit);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <limits>
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
|
@ -13,6 +12,7 @@
|
|||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -26,16 +26,6 @@ namespace sprout {
|
|||
typedef RealType result_type;
|
||||
private:
|
||||
struct private_constructor_tag {};
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType mean_arg, RealType sigma_arg) {
|
||||
return sigma_arg >= RealType(0);
|
||||
}
|
||||
static SPROUT_CONSTEXPR RealType arg_check(RealType mean_arg, RealType sigma_arg) {
|
||||
return arg_check_nothrow(mean_arg, sigma_arg)
|
||||
? mean_arg
|
||||
: throw std::invalid_argument("normal_distribution<>: invalid argument (sigma_arg >= 0)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -43,10 +33,6 @@ namespace sprout {
|
|||
class param_type {
|
||||
public:
|
||||
typedef normal_distribution distribution_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType mean_arg, RealType sigma_arg) {
|
||||
return distribution_type::arg_check_nothrow(mean_arg, sigma_arg);
|
||||
}
|
||||
private:
|
||||
RealType mean_;
|
||||
RealType sigma_;
|
||||
|
@ -56,8 +42,8 @@ namespace sprout {
|
|||
, sigma_(RealType(1.0))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(RealType mean_arg, RealType sigma_arg = RealType(1.0))
|
||||
: mean_(arg_check(mean_arg, sigma_arg))
|
||||
, sigma_(sigma_arg)
|
||||
: mean_(mean_arg)
|
||||
, sigma_((SPROUT_ASSERT(sigma_arg >= RealType(0)), sigma_arg))
|
||||
{}
|
||||
SPROUT_CONSTEXPR RealType mean() const SPROUT_NOEXCEPT {
|
||||
return mean_;
|
||||
|
@ -77,7 +63,7 @@ namespace sprout {
|
|||
RealType mean;
|
||||
RealType sigma;
|
||||
if (lhs >> mean >> std::ws >> sigma) {
|
||||
if (arg_check_nothrow(mean, sigma)) {
|
||||
if (sigma >= RealType(0)) {
|
||||
rhs.mean_ = mean;
|
||||
rhs.sigma_ = sigma;
|
||||
} else {
|
||||
|
@ -174,8 +160,8 @@ namespace sprout {
|
|||
, valid_(false)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR normal_distribution(RealType mean_arg, RealType sigma_arg = RealType(1.0))
|
||||
: mean_(arg_check(mean_arg, sigma_arg))
|
||||
, sigma_(sigma_arg)
|
||||
: mean_(mean_arg)
|
||||
, sigma_((SPROUT_ASSERT(sigma_arg >= RealType(0)), sigma_arg))
|
||||
, r1_(0)
|
||||
, r2_(0)
|
||||
, cached_rho_(0)
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <limits>
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
|
@ -15,6 +14,7 @@
|
|||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/linear_congruential.hpp>
|
||||
#include <sprout/random/detail/signed_unsigned_tools.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -117,7 +117,7 @@ namespace sprout {
|
|||
: sprout::math::less(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 std::domain_error("shuffle_order_engine<>: Sorry, not implemented.")
|
||||
: (SPROUT_ASSERT_MSG(0, "Sorry, not implemented."), sprout::random::random_result<shuffle_order_engine>())
|
||||
);
|
||||
}
|
||||
public:
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
#include <limits>
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/detail/signed_unsigned_tools.hpp>
|
||||
#include <sprout/random/detail/uniform_int_float.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -288,15 +288,6 @@ namespace sprout {
|
|||
public:
|
||||
typedef IntType input_type;
|
||||
typedef IntType result_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) {
|
||||
return min_arg <= max_arg;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType arg_check(IntType min_arg, IntType max_arg) {
|
||||
return arg_check_nothrow(min_arg, max_arg) ? min_arg
|
||||
: throw std::invalid_argument("uniform_int_distribution<>: invalid argument (min_arg <= max_arg)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -304,10 +295,6 @@ 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_;
|
||||
|
@ -317,7 +304,7 @@ namespace sprout {
|
|||
, max_(9)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
SPROUT_CONSTEXPR IntType a() const SPROUT_NOEXCEPT {
|
||||
|
@ -335,7 +322,7 @@ namespace sprout {
|
|||
IntType min;
|
||||
IntType max;
|
||||
if (lhs >> min >> std::ws >> max) {
|
||||
if (arg_check_nothrow(min, max)) {
|
||||
if (min <= max) {
|
||||
rhs.min_ = min;
|
||||
rhs.max_ = max;
|
||||
} else {
|
||||
|
@ -377,7 +364,7 @@ namespace sprout {
|
|||
, max_(9)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_int_distribution(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_int_distribution(param_type const& parm)
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/detail/signed_unsigned_tools.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -47,16 +47,13 @@ namespace sprout {
|
|||
T divisor
|
||||
)
|
||||
{
|
||||
return divisor > 0
|
||||
? numerator >= 0 && numerator <= divisor
|
||||
? sprout::random::detail::generate_uniform_real_false_3(
|
||||
eng,
|
||||
min_value,
|
||||
max_value,
|
||||
numerator / divisor * (max_value - min_value) + min_value
|
||||
)
|
||||
: throw std::domain_error("generate_uniform_real(): domain error (numerator >= 0 && numerator <= divisor)")
|
||||
: throw std::domain_error("generate_uniform_real(): domain error (divisor > 0)")
|
||||
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||
sprout::random::detail::generate_uniform_real_false_3(
|
||||
eng,
|
||||
min_value,
|
||||
max_value,
|
||||
numerator / divisor * (max_value - min_value) + min_value
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Engine, typename T>
|
||||
|
@ -116,16 +113,13 @@ namespace sprout {
|
|||
T divisor
|
||||
)
|
||||
{
|
||||
return divisor > 0
|
||||
? numerator >= 0 && numerator <= divisor
|
||||
? sprout::random::detail::generate_uniform_real_true_3(
|
||||
eng,
|
||||
min_value,
|
||||
max_value,
|
||||
numerator / divisor * (max_value - min_value) + min_value
|
||||
)
|
||||
: throw std::domain_error("generate_uniform_real(): domain error (numerator >= 0 && numerator <= divisor)")
|
||||
: throw std::domain_error("generate_uniform_real(): domain error (divisor > 0)")
|
||||
return SPROUT_ASSERT(divisor > 0), SPROUT_ASSERT(numerator >= 0 && numerator <= divisor),
|
||||
sprout::random::detail::generate_uniform_real_true_3(
|
||||
eng,
|
||||
min_value,
|
||||
max_value,
|
||||
numerator / divisor * (max_value - min_value) + min_value
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Engine, typename T>
|
||||
|
@ -182,16 +176,6 @@ namespace sprout {
|
|||
public:
|
||||
typedef RealType input_type;
|
||||
typedef RealType result_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType min_arg, RealType max_arg) {
|
||||
return min_arg <= max_arg;
|
||||
}
|
||||
static SPROUT_CONSTEXPR RealType arg_check(RealType min_arg, RealType max_arg) {
|
||||
return arg_check_nothrow(min_arg, max_arg)
|
||||
? min_arg
|
||||
: throw std::invalid_argument("uniform_real_distribution<>: invalid argument (min_arg <= max_arg)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -199,10 +183,6 @@ 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_;
|
||||
|
@ -212,7 +192,7 @@ namespace sprout {
|
|||
, max_(RealType(1.0))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(RealType min_arg, RealType max_arg = RealType(1.0))
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
SPROUT_CONSTEXPR RealType a() const SPROUT_NOEXCEPT {
|
||||
|
@ -230,7 +210,7 @@ namespace sprout {
|
|||
RealType min;
|
||||
RealType max;
|
||||
if (lhs >> min >> std::ws >> max) {
|
||||
if (arg_check_nothrow(min, max)) {
|
||||
if (min <= max) {
|
||||
rhs.min_ = min;
|
||||
rhs.max_ = max;
|
||||
} else {
|
||||
|
@ -272,7 +252,7 @@ namespace sprout {
|
|||
, max_(RealType(1.0))
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_real_distribution(RealType min_arg, RealType max_arg = RealType(1.0))
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_real_distribution(param_type const& parm)
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include <iosfwd>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/detail/signed_unsigned_tools.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
|
@ -20,16 +20,6 @@ namespace sprout {
|
|||
public:
|
||||
typedef IntType input_type;
|
||||
typedef IntType result_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) {
|
||||
return min_arg <= max_arg;
|
||||
}
|
||||
static SPROUT_CONSTEXPR IntType arg_check(IntType min_arg, IntType max_arg) {
|
||||
return arg_check_nothrow(min_arg, max_arg)
|
||||
? min_arg
|
||||
: throw std::invalid_argument("uniform_smallint<>: invalid argument (min_arg <= max_arg)")
|
||||
;
|
||||
}
|
||||
public:
|
||||
//
|
||||
// param_type
|
||||
|
@ -37,10 +27,6 @@ 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_;
|
||||
|
@ -50,7 +36,7 @@ namespace sprout {
|
|||
, max_(9)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR param_type(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
SPROUT_CONSTEXPR IntType a() const SPROUT_NOEXCEPT {
|
||||
|
@ -68,7 +54,7 @@ namespace sprout {
|
|||
IntType min;
|
||||
IntType max;
|
||||
if (lhs >> min >> std::ws >> max) {
|
||||
if (arg_check_nothrow(min, max)) {
|
||||
if (min <= max) {
|
||||
rhs.min_ = min;
|
||||
rhs.max_ = max;
|
||||
} else {
|
||||
|
@ -207,7 +193,7 @@ namespace sprout {
|
|||
, max_(9)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_smallint(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
: min_((SPROUT_ASSERT(min_arg <= max_arg), min_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR uniform_smallint(param_type const& parm)
|
||||
|
|
|
@ -18,10 +18,10 @@ namespace sprout {
|
|||
transform(InputRange const& rng, Result const& result, UnaryOperation op) {
|
||||
return sprout::fit::transform(sprout::begin(rng), sprout::end(rng), result, op);
|
||||
}
|
||||
template<typename Input1, typename Input2, typename Result, typename BinaryOperation>
|
||||
template<typename InputRange1, typename InputRange2, typename Result, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
transform(Input1 const& input1, Input2 const& input2, Result const& result, BinaryOperation op) {
|
||||
return sprout::fit::transform(sprout::begin(input1), sprout::end(input1), sprout::begin(input2), result, op);
|
||||
transform(InputRange1 const& rng1, InputRange2 const& rng2, Result const& result, BinaryOperation op) {
|
||||
return sprout::fit::transform(sprout::begin(rng1), sprout::end(rng1), sprout::begin(rng2), result, op);
|
||||
}
|
||||
} // namespace fit
|
||||
} // namespace range
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace sprout {
|
|||
}
|
||||
rational& operator/=(rational const& rhs) {
|
||||
if (rhs.num_ == IntType(0)) {
|
||||
throw bad_rational();
|
||||
throw sprout::bad_rational();
|
||||
}
|
||||
if (num_ == IntType(0)) {
|
||||
return *this;
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR next_char(Iterator f, Iterator l)
|
||||
: c(f != l
|
||||
? *f
|
||||
: throw std::domain_error("string_generator: invalid uuid string (out of range)")
|
||||
: throw std::runtime_error("string_generator: invalid uuid string (out of range)")
|
||||
)
|
||||
, first(sprout::next(f))
|
||||
, last(l)
|
||||
|
@ -46,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 std::domain_error("string_generator: invalid uuid string (invalid character)")
|
||||
: throw std::runtime_error("string_generator: invalid uuid string (invalid character)")
|
||||
;
|
||||
}
|
||||
template<typename Elem>
|
||||
|
@ -117,7 +117,7 @@ namespace sprout {
|
|||
return has_dashes
|
||||
? is_dash(nc.c)
|
||||
? generate_2_2(nc.next(), open_brace, has_dashes, args...)
|
||||
: throw std::domain_error("string_generator: invalid uuid string (dashes not found)")
|
||||
: throw std::runtime_error("string_generator: invalid uuid string (dashes not found)")
|
||||
: generate_2_2(nc, open_brace, has_dashes, args...)
|
||||
;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ namespace sprout {
|
|||
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 std::domain_error("string_generator: invalid uuid string (brace not closed)")
|
||||
: throw std::runtime_error("string_generator: invalid uuid string (brace not closed)")
|
||||
;
|
||||
}
|
||||
template<typename Iterator, typename Char, typename... Args>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <sprout/functional/type_traits/weak_result_type.hpp>
|
||||
#include <sprout/variant/variant_fwd.hpp>
|
||||
#include <sprout/variant/visitor_result.hpp>
|
||||
#include <sprout/math/comparison.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -201,10 +202,7 @@ namespace sprout {
|
|||
I == sizeof...(Types) - 1,
|
||||
Result
|
||||
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
||||
return I == which
|
||||
? sprout::forward<Visitor>(v)(sprout::tuples::get<I>(sprout::forward<Tuple>(t)))
|
||||
: throw std::domain_error("variant<>: bad visit")
|
||||
;
|
||||
return sprout::forward<Visitor>(v)(sprout::tuples::get<I>(sprout::forward<Tuple>(t)));
|
||||
}
|
||||
template<typename Result, int I, typename Tuple, typename Visitor>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<
|
||||
|
@ -293,9 +291,8 @@ namespace sprout {
|
|||
I != sizeof...(Types),
|
||||
typename sprout::tuples::tuple_element<I, tuple_type>::type const&
|
||||
>::type get_at() const {
|
||||
return I == static_cast<std::size_t>(which_)
|
||||
? sprout::tuples::get<I>(tuple_)
|
||||
: (throw std::domain_error("variant<>: bad get"), sprout::tuples::get<I>(tuple_))
|
||||
return SPROUT_ASSERT(I == which_) ? sprout::tuples::get<I>(tuple_)
|
||||
: sprout::tuples::get<I>(tuple_)
|
||||
;
|
||||
}
|
||||
template<std::size_t I>
|
||||
|
@ -303,9 +300,8 @@ namespace sprout {
|
|||
I != sizeof...(Types),
|
||||
typename sprout::tuples::tuple_element<I, tuple_type>::type&
|
||||
>::type get_at() {
|
||||
return I == which_
|
||||
? sprout::tuples::get<I>(tuple_)
|
||||
: (throw std::domain_error("variant<>: bad get"), sprout::tuples::get<I>(tuple_))
|
||||
return SPROUT_ASSERT(I == which_) ? sprout::tuples::get<I>(tuple_)
|
||||
: sprout::tuples::get<I>(tuple_)
|
||||
;
|
||||
}
|
||||
template<typename U>
|
||||
|
@ -327,13 +323,17 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR typename visitor_result<typename std::remove_reference<Visitor>::type, variant const>::type
|
||||
apply_visitor(Visitor&& visitor) const {
|
||||
typedef typename visitor_result<typename std::remove_reference<Visitor>::type, variant const>::type result_type;
|
||||
return visit<result_type, 0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
||||
return SPROUT_ASSERT(0 <= which_ && sprout::math::less(which_, sizeof...(Types))),
|
||||
visit<result_type, 0>(tuple_, sprout::forward<Visitor>(visitor), which_)
|
||||
;
|
||||
}
|
||||
template<typename Visitor>
|
||||
typename visitor_result<typename std::remove_reference<Visitor>::type, variant>::type
|
||||
apply_visitor(Visitor&& visitor) {
|
||||
typedef typename visitor_result<typename std::remove_reference<Visitor>::type, variant>::type result_type;
|
||||
return visit<result_type, 0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
||||
return SPROUT_ASSERT(0 <= which_ && sprout::math::less(which_, sizeof...(Types))),
|
||||
visit<result_type, 0>(tuple_, sprout::forward<Visitor>(visitor), which_)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue