mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
random_iterator 修正
This commit is contained in:
parent
3c03c120fb
commit
a7c392cda8
4 changed files with 90 additions and 22 deletions
|
@ -65,7 +65,8 @@ namespace sprout {
|
|||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR linear_congruential_engine()
|
||||
: x_(init_seed(default_seed))
|
||||
//: x_(init_seed(default_seed)) // ???
|
||||
: x_(init_seed(1)) // ???
|
||||
{}
|
||||
SPROUT_CONSTEXPR explicit linear_congruential_engine(IntType const& x0)
|
||||
: x_(init_seed(x0))
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace sprout {
|
|||
random_result_type random_;
|
||||
difference_type count_;
|
||||
public:
|
||||
//random_iterator() = default; // ???
|
||||
SPROUT_CONSTEXPR random_iterator()
|
||||
: random_()
|
||||
, count_()
|
||||
|
@ -118,7 +119,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return count_ != 0
|
||||
? random_.result()
|
||||
: throw "assert(count_ != 0)"
|
||||
: (throw "assert(count_ != 0)", random_.result())
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
|
@ -165,6 +166,7 @@ namespace sprout {
|
|||
random_result_type random_;
|
||||
difference_type count_;
|
||||
public:
|
||||
//random_iterator() = default; // ???
|
||||
SPROUT_CONSTEXPR random_iterator()
|
||||
: random_()
|
||||
, count_()
|
||||
|
@ -230,7 +232,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return count_ != 0
|
||||
? random_.result()
|
||||
: throw "assert(count_ != 0)"
|
||||
: (throw "assert(count_ != 0)", random_.result())
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
|
@ -263,18 +265,62 @@ namespace sprout {
|
|||
}
|
||||
|
||||
//
|
||||
// next
|
||||
// begin
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::random_iterator<Engine, Distribution> next(
|
||||
sprout::random::random_iterator<Engine, Distribution> const& it
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!std::is_integral<Distribution>::value,
|
||||
sprout::random::random_iterator<Engine, Distribution>
|
||||
>::type begin(
|
||||
Engine const& engine,
|
||||
Distribution const& distribution,
|
||||
typename sprout::random::random_iterator<Engine, Distribution>::difference_type count = -1
|
||||
)
|
||||
{
|
||||
return it();
|
||||
return sprout::random::random_iterator<Engine, Distribution>(engine, distribution, count);
|
||||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_iterator<Engine> begin(
|
||||
Engine const& engine,
|
||||
typename sprout::random::random_iterator<Engine>::difference_type count = -1
|
||||
)
|
||||
{
|
||||
return sprout::random::random_iterator<Engine>(engine, count);
|
||||
}
|
||||
|
||||
//
|
||||
// end
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::random_iterator<Engine, Distribution> end(
|
||||
Engine const& engine,
|
||||
Distribution const& distribution
|
||||
)
|
||||
{
|
||||
return sprout::random::random_iterator<Engine, Distribution>();
|
||||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_iterator<Engine> end(
|
||||
Engine const& engine
|
||||
)
|
||||
{
|
||||
return sprout::random::random_iterator<Engine>();
|
||||
}
|
||||
} // namespace random
|
||||
|
||||
//
|
||||
// next
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::random_iterator<Engine, Distribution> next(
|
||||
sprout::random::random_iterator<Engine, Distribution> const& it
|
||||
)
|
||||
{
|
||||
return it();
|
||||
}
|
||||
|
||||
using sprout::random::random_iterator;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_RANDOM_ITERATOR_HPP
|
||||
|
||||
|
|
|
@ -53,6 +53,12 @@ namespace sprout {
|
|||
engine_type engine_;
|
||||
distribution_type distribution_;
|
||||
public:
|
||||
//random_result() = default; // ???
|
||||
SPROUT_CONSTEXPR random_result()
|
||||
: result_()
|
||||
, engine_()
|
||||
, distribution_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR random_result(
|
||||
result_type result,
|
||||
engine_type const& engine,
|
||||
|
@ -159,6 +165,11 @@ namespace sprout {
|
|||
result_type result_;
|
||||
engine_type engine_;
|
||||
public:
|
||||
//random_result() = default; // ???
|
||||
SPROUT_CONSTEXPR random_result()
|
||||
: result_()
|
||||
, engine_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR random_result(
|
||||
result_type result,
|
||||
engine_type const& engine
|
||||
|
@ -232,19 +243,19 @@ namespace sprout {
|
|||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// next
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, Distribution> next(
|
||||
sprout::random::random_result<Engine, Distribution> const& it
|
||||
)
|
||||
{
|
||||
return it();
|
||||
}
|
||||
} // namespace random
|
||||
|
||||
//
|
||||
// next
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, Distribution> next(
|
||||
sprout::random::random_result<Engine, Distribution> const& it
|
||||
)
|
||||
{
|
||||
return it();
|
||||
}
|
||||
|
||||
using sprout::random::random_result;
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -37,7 +37,11 @@ namespace sprout {
|
|||
IntType min_;
|
||||
IntType max_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR param_type(IntType min_arg = 0, IntType max_arg = 9)
|
||||
SPROUT_CONSTEXPR param_type()
|
||||
: min_(0)
|
||||
, max_(9)
|
||||
{}
|
||||
SPROUT_CONSTEXPR explicit param_type(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(arg_check(min_arg, max_arg))
|
||||
, max_(max_arg)
|
||||
{}
|
||||
|
@ -180,11 +184,17 @@ namespace sprout {
|
|||
);
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9)
|
||||
: min_(min_arg), max_(max_arg)
|
||||
SPROUT_CONSTEXPR uniform_smallint()
|
||||
: min_(0)
|
||||
, max_(9)
|
||||
{}
|
||||
SPROUT_CONSTEXPR explicit uniform_smallint(IntType min_arg, IntType max_arg = 9)
|
||||
: min_(min_arg)
|
||||
, max_(max_arg)
|
||||
{}
|
||||
explicit uniform_smallint(param_type const& parm)
|
||||
: min_(parm.a()), max_(parm.b())
|
||||
: min_(parm.a())
|
||||
, max_(parm.b())
|
||||
{}
|
||||
SPROUT_CONSTEXPR result_type a() const {
|
||||
return min_;
|
||||
|
|
Loading…
Reference in a new issue