1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

random_iterator 修正

This commit is contained in:
bolero-MURAKAMI 2011-10-02 21:07:58 +09:00
parent 3c03c120fb
commit a7c392cda8
4 changed files with 90 additions and 22 deletions

View file

@ -65,7 +65,8 @@ namespace sprout {
} }
public: public:
SPROUT_CONSTEXPR linear_congruential_engine() 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) SPROUT_CONSTEXPR explicit linear_congruential_engine(IntType const& x0)
: x_(init_seed(x0)) : x_(init_seed(x0))

View file

@ -46,6 +46,7 @@ namespace sprout {
random_result_type random_; random_result_type random_;
difference_type count_; difference_type count_;
public: public:
//random_iterator() = default; // ???
SPROUT_CONSTEXPR random_iterator() SPROUT_CONSTEXPR random_iterator()
: random_() : random_()
, count_() , count_()
@ -118,7 +119,7 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator*() const { SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0 return count_ != 0
? random_.result() ? random_.result()
: throw "assert(count_ != 0)" : (throw "assert(count_ != 0)", random_.result())
; ;
} }
SPROUT_CONSTEXPR pointer operator->() const { SPROUT_CONSTEXPR pointer operator->() const {
@ -165,6 +166,7 @@ namespace sprout {
random_result_type random_; random_result_type random_;
difference_type count_; difference_type count_;
public: public:
//random_iterator() = default; // ???
SPROUT_CONSTEXPR random_iterator() SPROUT_CONSTEXPR random_iterator()
: random_() : random_()
, count_() , count_()
@ -230,7 +232,7 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator*() const { SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0 return count_ != 0
? random_.result() ? random_.result()
: throw "assert(count_ != 0)" : (throw "assert(count_ != 0)", random_.result())
; ;
} }
SPROUT_CONSTEXPR pointer operator->() const { SPROUT_CONSTEXPR pointer operator->() const {
@ -262,6 +264,50 @@ namespace sprout {
lhs.swap(rhs); lhs.swap(rhs);
} }
//
// begin
//
template<typename Engine, typename Distribution>
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 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 // next
// //
@ -272,9 +318,9 @@ namespace sprout {
{ {
return it(); return it();
} }
} // namespace random
using sprout::random::random_iterator; using sprout::random::random_iterator;
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_RANDOM_RANDOM_ITERATOR_HPP #endif // #ifndef SPROUT_RANDOM_RANDOM_ITERATOR_HPP

View file

@ -53,6 +53,12 @@ namespace sprout {
engine_type engine_; engine_type engine_;
distribution_type distribution_; distribution_type distribution_;
public: public:
//random_result() = default; // ???
SPROUT_CONSTEXPR random_result()
: result_()
, engine_()
, distribution_()
{}
SPROUT_CONSTEXPR random_result( SPROUT_CONSTEXPR random_result(
result_type result, result_type result,
engine_type const& engine, engine_type const& engine,
@ -159,6 +165,11 @@ namespace sprout {
result_type result_; result_type result_;
engine_type engine_; engine_type engine_;
public: public:
//random_result() = default; // ???
SPROUT_CONSTEXPR random_result()
: result_()
, engine_()
{}
SPROUT_CONSTEXPR random_result( SPROUT_CONSTEXPR random_result(
result_type result, result_type result,
engine_type const& engine engine_type const& engine
@ -232,6 +243,7 @@ namespace sprout {
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
} // namespace random
// //
// next // next
@ -243,7 +255,6 @@ namespace sprout {
{ {
return it(); return it();
} }
} // namespace random
using sprout::random::random_result; using sprout::random::random_result;
} // namespace sprout } // namespace sprout

View file

@ -37,7 +37,11 @@ namespace sprout {
IntType min_; IntType min_;
IntType max_; IntType max_;
public: 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)) : min_(arg_check(min_arg, max_arg))
, max_(max_arg) , max_(max_arg)
{} {}
@ -180,11 +184,17 @@ namespace sprout {
); );
} }
public: public:
SPROUT_CONSTEXPR explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9) SPROUT_CONSTEXPR uniform_smallint()
: min_(min_arg), max_(max_arg) : 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) 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 { SPROUT_CONSTEXPR result_type a() const {
return min_; return min_;