diff --git a/libs/random/example/array.cpp b/libs/random/example/array.cpp index debe733a..e01fba03 100644 --- a/libs/random/example/array.cpp +++ b/libs/random/example/array.cpp @@ -23,7 +23,7 @@ main(){ static constexpr auto result = sprout::generate /* Result type */> - (sprout::random::combine(engine, dist) /*Random generator*/) + (sprout::random::ccombine(engine, dist) /*Random generator*/) ; static_assert( diff --git a/sprout/random/variate_generator.hpp b/sprout/random/variate_generator.hpp index 93533ca0..c29d62c5 100644 --- a/sprout/random/variate_generator.hpp +++ b/sprout/random/variate_generator.hpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include namespace sprout { @@ -37,7 +39,11 @@ namespace sprout { typedef Engine engine_type; typedef Distribution distribution_type; typedef typename distribution_value_type::result_type result_type; - typedef sprout::random::random_result random_result_type; + typedef typename std::conditional< + std::is_reference::value && !std::is_const::type>::value, + result_type, + sprout::random::random_result + >::type random_result_type; private: engine_type engine_; distribution_type distribution_; @@ -109,8 +115,27 @@ namespace sprout { // combine // template + inline SPROUT_CONSTEXPR sprout::random::variate_generator< + typename sprout::lvalue_reference::type, + typename sprout::lvalue_reference::type + > + combine(Engine&& engine, Distribution&& distribution) { + typedef sprout::random::variate_generator< + typename sprout::lvalue_reference::type, + typename sprout::lvalue_reference::type + > type; + return type( + sprout::lvalue_forward(engine), + sprout::lvalue_forward(distribution) + ); + } + + // + // ccombine + // + template inline SPROUT_CONSTEXPR sprout::random::variate_generator - combine(Engine const& engine, Distribution const& distribution) { + ccombine(Engine const& engine, Distribution const& distribution) { return sprout::random::variate_generator(engine, distribution); }