2012-09-27 12:26:32 +00:00
|
|
|
#ifndef SPROUT_RANDOM_ITERATOR_HPP
|
|
|
|
#define SPROUT_RANDOM_ITERATOR_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/iterator/generator_iterator.hpp>
|
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace random {
|
|
|
|
//
|
|
|
|
// begin
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename Engine, typename Distribution,
|
2012-09-27 12:57:51 +00:00
|
|
|
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::type = sprout::enabler
|
2012-09-27 12:26:32 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
begin(
|
|
|
|
Engine const& engine, Distribution const& distribution,
|
2012-09-27 12:57:51 +00:00
|
|
|
typename sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>::difference_type count = -1
|
2012-09-27 12:26:32 +00:00
|
|
|
)
|
2012-10-05 15:58:56 +00:00
|
|
|
-> sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>
|
2012-09-27 12:26:32 +00:00
|
|
|
{
|
2012-11-24 04:04:02 +00:00
|
|
|
return count >= 0
|
|
|
|
? sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>(distribution(engine), count)
|
|
|
|
: sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>(distribution(engine))
|
|
|
|
;
|
2012-09-27 12:26:32 +00:00
|
|
|
}
|
|
|
|
template<typename Engine>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
begin(
|
|
|
|
Engine const& engine,
|
2012-09-27 12:57:51 +00:00
|
|
|
typename sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>::difference_type count = -1
|
2012-09-27 12:26:32 +00:00
|
|
|
)
|
2012-10-05 15:58:56 +00:00
|
|
|
-> sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>
|
2012-09-27 12:26:32 +00:00
|
|
|
{
|
2012-11-24 04:04:02 +00:00
|
|
|
return count >= 0
|
|
|
|
? sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>(engine(), count)
|
|
|
|
: sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>(engine())
|
|
|
|
;
|
2012-09-27 12:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// end
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename Engine, typename Distribution,
|
2012-09-27 12:57:51 +00:00
|
|
|
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::type = sprout::enabler
|
2012-09-27 12:26:32 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
end(Engine const& engine, Distribution const& distribution)
|
2012-10-05 15:58:56 +00:00
|
|
|
-> sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>
|
2012-09-27 12:26:32 +00:00
|
|
|
{
|
2012-09-27 12:57:51 +00:00
|
|
|
return sprout::generator_iterator<typename std::remove_reference<decltype(distribution(engine))>::type>();
|
2012-09-27 12:26:32 +00:00
|
|
|
}
|
|
|
|
template<typename Engine>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
end(Engine const& engine)
|
2012-10-05 15:58:56 +00:00
|
|
|
-> sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>
|
2012-09-27 12:26:32 +00:00
|
|
|
{
|
2012-09-27 12:57:51 +00:00
|
|
|
return sprout::generator_iterator<typename std::remove_reference<decltype(engine())>::type>();
|
2012-09-27 12:26:32 +00:00
|
|
|
}
|
|
|
|
} // namespace random
|
|
|
|
} // namespace sprout
|
|
|
|
|
2013-03-22 05:24:19 +00:00
|
|
|
#endif // #ifndef SPROUT_RANDOM_ITERATOR_HPP
|