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

fix variate_generator

This commit is contained in:
bolero-MURAKAMI 2016-04-28 10:48:50 +09:00
parent 51614b1356
commit 42133b805e
2 changed files with 28 additions and 3 deletions

View file

@ -23,7 +23,7 @@ main(){
static constexpr auto result = sprout::generate static constexpr auto result = sprout::generate
<sprout::array<int, 10> /* Result type */> <sprout::array<int, 10> /* Result type */>
(sprout::random::combine(engine, dist) /*Random generator*/) (sprout::random::ccombine(engine, dist) /*Random generator*/)
; ;
static_assert( static_assert(

View file

@ -12,6 +12,8 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/random/detail/ptr_helper.hpp> #include <sprout/random/detail/ptr_helper.hpp>
#include <sprout/random/random_result_fwd.hpp> #include <sprout/random/random_result_fwd.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/utility/swap.hpp> #include <sprout/utility/swap.hpp>
namespace sprout { namespace sprout {
@ -37,7 +39,11 @@ namespace sprout {
typedef Engine engine_type; typedef Engine engine_type;
typedef Distribution distribution_type; typedef Distribution distribution_type;
typedef typename distribution_value_type::result_type result_type; typedef typename distribution_value_type::result_type result_type;
typedef sprout::random::random_result<engine_value_type, distribution_value_type> random_result_type; typedef typename std::conditional<
std::is_reference<engine_type>::value && !std::is_const<typename std::remove_reference<engine_type>::type>::value,
result_type,
sprout::random::random_result<engine_value_type, distribution_value_type>
>::type random_result_type;
private: private:
engine_type engine_; engine_type engine_;
distribution_type distribution_; distribution_type distribution_;
@ -109,8 +115,27 @@ namespace sprout {
// combine // combine
// //
template<typename Engine, typename Distribution> template<typename Engine, typename Distribution>
inline SPROUT_CONSTEXPR sprout::random::variate_generator<
typename sprout::lvalue_reference<Engine>::type,
typename sprout::lvalue_reference<Distribution>::type
>
combine(Engine&& engine, Distribution&& distribution) {
typedef sprout::random::variate_generator<
typename sprout::lvalue_reference<Engine>::type,
typename sprout::lvalue_reference<Distribution>::type
> type;
return type(
sprout::lvalue_forward<Engine>(engine),
sprout::lvalue_forward<Distribution>(distribution)
);
}
//
// ccombine
//
template<typename Engine, typename Distribution>
inline SPROUT_CONSTEXPR sprout::random::variate_generator<Engine const&, Distribution const&> inline SPROUT_CONSTEXPR sprout::random::variate_generator<Engine const&, Distribution const&>
combine(Engine const& engine, Distribution const& distribution) { ccombine(Engine const& engine, Distribution const& distribution) {
return sprout::random::variate_generator<Engine const&, Distribution const&>(engine, distribution); return sprout::random::variate_generator<Engine const&, Distribution const&>(engine, distribution);
} }