mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
add SPROUT_ASSERT
This commit is contained in:
parent
a5e14e71e1
commit
07f052fb6e
32 changed files with 386 additions and 284 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue