mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix generator_iterator
fix random::begin, end add random::combine_copy
This commit is contained in:
parent
f40ee0a2ff
commit
10e9a7679d
4 changed files with 39 additions and 31 deletions
|
@ -17,16 +17,16 @@ namespace sprout {
|
|||
class generator_iterator
|
||||
: public std::iterator<
|
||||
std::forward_iterator_tag,
|
||||
typename std::remove_reference<decltype(sprout::generators::generated_value(std::declval<Generator>()))>::type,
|
||||
typename std::remove_reference<decltype(sprout::generators::generated_value(std::declval<Generator const>()))>::type,
|
||||
std::ptrdiff_t,
|
||||
typename std::remove_reference<decltype(sprout::generators::generated_value(std::declval<Generator>()))>::type*,
|
||||
decltype(sprout::generators::generated_value(std::declval<Generator>()))
|
||||
typename std::remove_reference<decltype(sprout::generators::generated_value(std::declval<Generator const>()))>::type*,
|
||||
decltype(sprout::generators::generated_value(std::declval<Generator const>()))
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef Generator generator_type;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef decltype(sprout::generators::generated_value(std::declval<Generator>())) reference;
|
||||
typedef decltype(sprout::generators::generated_value(std::declval<Generator const>())) reference;
|
||||
typedef typename std::remove_reference<reference>::type value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef value_type* pointer;
|
||||
|
@ -96,7 +96,10 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return count_ != 0
|
||||
? sprout::generators::generated_value(gen_)
|
||||
: (throw std::out_of_range("generator_iterator<>: dereference at out of range"), gen_.result())
|
||||
: (
|
||||
throw std::out_of_range("generator_iterator<>: dereference at out of range"),
|
||||
sprout::generators::generated_value(gen_)
|
||||
)
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SPROUT_RANDOM_ITERATOR_HPP
|
||||
#define SPROUT_RANDOM_ITERATOR_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/generator_iterator.hpp>
|
||||
|
@ -14,26 +13,26 @@ namespace sprout {
|
|||
//
|
||||
template<
|
||||
typename Engine, typename Distribution,
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::tyep = sprout::enabler
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
begin(
|
||||
Engine const& engine, Distribution const& distribution,
|
||||
typename sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>::difference_type count = -1
|
||||
typename sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>::difference_type count = -1
|
||||
)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>
|
||||
-> sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>(distribution(engine), count);
|
||||
return sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>(distribution(engine), count);
|
||||
}
|
||||
template<typename Engine>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
begin(
|
||||
Engine const& engine,
|
||||
typename sprout::generator_iterator<typename std::decay<decltype(engine())>::type>::difference_type count = -1
|
||||
typename sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>::difference_type count = -1
|
||||
)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(engine())>::type>
|
||||
-> sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(engine())>::type>(engine(), count);
|
||||
return sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>(engine(), count);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -41,20 +40,20 @@ namespace sprout {
|
|||
//
|
||||
template<
|
||||
typename Engine, typename Distribution,
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::tyep = sprout::enabler
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
end(Engine const& engine, Distribution const& distribution)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>
|
||||
-> sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>();
|
||||
return sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>();
|
||||
}
|
||||
template<typename Engine>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
end(Engine const& engine)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(engine())>::type>
|
||||
-> sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(engine())>::type>();
|
||||
return sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>();
|
||||
}
|
||||
} // namespace random
|
||||
} // namespace sprout
|
||||
|
|
|
@ -280,13 +280,13 @@ namespace sprout {
|
|||
// generated_value
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::result_type const&
|
||||
generated_value(sprout::random::random_result<Engine, Distribution> const& t) {
|
||||
inline typename sprout::random::random_result<Engine, Distribution>::result_type&
|
||||
generated_value(sprout::random::random_result<Engine, Distribution>& t) {
|
||||
return t.generated_value();
|
||||
}
|
||||
template<typename Engine, typename Distribution>
|
||||
inline typename sprout::random::random_result<Engine, Distribution>::result_type&
|
||||
generated_value(sprout::random::random_result<Engine, Distribution>& t) {
|
||||
inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::result_type const&
|
||||
generated_value(sprout::random::random_result<Engine, Distribution> const& t) {
|
||||
return t.generated_value();
|
||||
}
|
||||
|
||||
|
@ -294,13 +294,13 @@ namespace sprout {
|
|||
// next_generator
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution> const&
|
||||
next_generator(sprout::random::random_result<Engine, Distribution> const& t) {
|
||||
inline typename sprout::random::random_result<Engine, Distribution>&
|
||||
next_generator(sprout::random::random_result<Engine, Distribution>& t) {
|
||||
return t.next_generator();
|
||||
}
|
||||
template<typename Engine, typename Distribution>
|
||||
inline typename sprout::random::random_result<Engine, Distribution>&
|
||||
next_generator(sprout::random::random_result<Engine, Distribution>& t) {
|
||||
inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution> const&
|
||||
next_generator(sprout::random::random_result<Engine, Distribution> const& t) {
|
||||
return t.next_generator();
|
||||
}
|
||||
} // namespace random
|
||||
|
|
|
@ -67,13 +67,19 @@ namespace sprout {
|
|||
// combine
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
SPROUT_CONSTEXPR sprout::random::variate_generator<Engine const&, Distribution const&> combine(
|
||||
Engine const& engine,
|
||||
Distribution const& distribution
|
||||
)
|
||||
{
|
||||
inline SPROUT_CONSTEXPR sprout::random::variate_generator<Engine const&, Distribution const&>
|
||||
combine(Engine const& engine, Distribution const& distribution) {
|
||||
return sprout::random::variate_generator<Engine const&, Distribution const&>(engine, distribution);
|
||||
}
|
||||
|
||||
//
|
||||
// combine_copy
|
||||
//
|
||||
template<typename Engine, typename Distribution>
|
||||
inline SPROUT_CONSTEXPR sprout::random::variate_generator<Engine, Distribution>
|
||||
combine_copy(Engine const& engine, Distribution const& distribution) {
|
||||
return sprout::random::variate_generator<Engine, Distribution>(engine, distribution);
|
||||
}
|
||||
} // namespace random
|
||||
|
||||
using sprout::random::variate_generator;
|
||||
|
|
Loading…
Reference in a new issue