From 10e9a7679d6f2bc44890b6756faae9130a7af81a Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 27 Sep 2012 21:57:51 +0900 Subject: [PATCH] fix generator_iterator fix random::begin, end add random::combine_copy --- sprout/iterator/generator_iterator.hpp | 13 ++++++++----- sprout/random/iterator.hpp | 25 ++++++++++++------------- sprout/random/random_result.hpp | 16 ++++++++-------- sprout/random/variate_generator.hpp | 16 +++++++++++----- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/sprout/iterator/generator_iterator.hpp b/sprout/iterator/generator_iterator.hpp index 39e4fee3..16a15326 100644 --- a/sprout/iterator/generator_iterator.hpp +++ b/sprout/iterator/generator_iterator.hpp @@ -17,16 +17,16 @@ namespace sprout { class generator_iterator : public std::iterator< std::forward_iterator_tag, - typename std::remove_reference()))>::type, + typename std::remove_reference()))>::type, std::ptrdiff_t, - typename std::remove_reference()))>::type*, - decltype(sprout::generators::generated_value(std::declval())) + typename std::remove_reference()))>::type*, + decltype(sprout::generators::generated_value(std::declval())) > { public: typedef Generator generator_type; typedef std::forward_iterator_tag iterator_category; - typedef decltype(sprout::generators::generated_value(std::declval())) reference; + typedef decltype(sprout::generators::generated_value(std::declval())) reference; typedef typename std::remove_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 { diff --git a/sprout/random/iterator.hpp b/sprout/random/iterator.hpp index f5fb6f6a..dfad5893 100644 --- a/sprout/random/iterator.hpp +++ b/sprout/random/iterator.hpp @@ -1,7 +1,6 @@ #ifndef SPROUT_RANDOM_ITERATOR_HPP #define SPROUT_RANDOM_ITERATOR_HPP -#include #include #include #include @@ -14,26 +13,26 @@ namespace sprout { // template< typename Engine, typename Distribution, - typename sprout::enabler_if::value>::tyep = sprout::enabler + typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR auto begin( Engine const& engine, Distribution const& distribution, - typename sprout::generator_iterator::type>::difference_type count = -1 + typename sprout::generator_iterator::type>::difference_type count = -1 ) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { - return sprout::generator_iterator::type>(distribution(engine), count); + return sprout::generator_iterator::type>(distribution(engine), count); } template inline SPROUT_CONSTEXPR auto begin( Engine const& engine, - typename sprout::generator_iterator::type>::difference_type count = -1 + typename sprout::generator_iterator::type>::difference_type count = -1 ) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { - return sprout::generator_iterator::type>(engine(), count); + return sprout::generator_iterator::type>(engine(), count); } // @@ -41,20 +40,20 @@ namespace sprout { // template< typename Engine, typename Distribution, - typename sprout::enabler_if::value>::tyep = sprout::enabler + typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR auto end(Engine const& engine, Distribution const& distribution) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { - return sprout::generator_iterator::type>(); + return sprout::generator_iterator::type>(); } template inline SPROUT_CONSTEXPR auto end(Engine const& engine) - -> sprout::generator_iterator::type> + -> sprout::generator_iterator::type> { - return sprout::generator_iterator::type>(); + return sprout::generator_iterator::type>(); } } // namespace random } // namespace sprout diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index 3fb21266..a823dab2 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -280,13 +280,13 @@ namespace sprout { // generated_value // template - inline SPROUT_CONSTEXPR typename sprout::random::random_result::result_type const& - generated_value(sprout::random::random_result const& t) { + inline typename sprout::random::random_result::result_type& + generated_value(sprout::random::random_result& t) { return t.generated_value(); } template - inline typename sprout::random::random_result::result_type& - generated_value(sprout::random::random_result& t) { + inline SPROUT_CONSTEXPR typename sprout::random::random_result::result_type const& + generated_value(sprout::random::random_result const& t) { return t.generated_value(); } @@ -294,13 +294,13 @@ namespace sprout { // next_generator // template - inline SPROUT_CONSTEXPR typename sprout::random::random_result const& - next_generator(sprout::random::random_result const& t) { + inline typename sprout::random::random_result& + next_generator(sprout::random::random_result& t) { return t.next_generator(); } template - inline typename sprout::random::random_result& - next_generator(sprout::random::random_result& t) { + inline SPROUT_CONSTEXPR typename sprout::random::random_result const& + next_generator(sprout::random::random_result const& t) { return t.next_generator(); } } // namespace random diff --git a/sprout/random/variate_generator.hpp b/sprout/random/variate_generator.hpp index 23dc9f8b..208d21b2 100644 --- a/sprout/random/variate_generator.hpp +++ b/sprout/random/variate_generator.hpp @@ -67,13 +67,19 @@ namespace sprout { // combine // template - SPROUT_CONSTEXPR sprout::random::variate_generator combine( - Engine const& engine, - Distribution const& distribution - ) - { + inline SPROUT_CONSTEXPR sprout::random::variate_generator + combine(Engine const& engine, Distribution const& distribution) { return sprout::random::variate_generator(engine, distribution); } + + // + // combine_copy + // + template + inline SPROUT_CONSTEXPR sprout::random::variate_generator + combine_copy(Engine const& engine, Distribution const& distribution) { + return sprout::random::variate_generator(engine, distribution); + } } // namespace random using sprout::random::variate_generator;