mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-14 15:04:09 +00:00
add generator_iterator
rename fix random/random_iterator.hpp -> random/iterator.hpp
This commit is contained in:
parent
ebadf4fa7c
commit
f40ee0a2ff
8 changed files with 235 additions and 331 deletions
62
sprout/random/iterator.hpp
Normal file
62
sprout/random/iterator.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#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>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace random {
|
||||
//
|
||||
// begin
|
||||
//
|
||||
template<
|
||||
typename Engine, typename Distribution,
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::tyep = 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
|
||||
)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<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
|
||||
)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(engine())>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(engine())>::type>(engine(), count);
|
||||
}
|
||||
|
||||
//
|
||||
// end
|
||||
//
|
||||
template<
|
||||
typename Engine, typename Distribution,
|
||||
typename sprout::enabler_if<!std::is_integral<Distribution>::value>::tyep = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
end(Engine const& engine, Distribution const& distribution)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(distribution(engine))>::type>();
|
||||
}
|
||||
template<typename Engine>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
end(Engine const& engine)
|
||||
-> sprout::generator_iterator<typename std::decay<decltype(engine())>::type>
|
||||
{
|
||||
return sprout::generator_iterator<typename std::decay<decltype(engine())>::type>();
|
||||
}
|
||||
} // namespace random
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_ITERATOR_HPP
|
Loading…
Add table
Add a link
Reference in a new issue