2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2011-10-12 20:28:33 +00:00
|
|
|
#ifndef SPROUT_RANDOM_RANDOM_RESULT_HPP
|
|
|
|
#define SPROUT_RANDOM_RANDOM_RESULT_HPP
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2011-10-12 20:28:33 +00:00
|
|
|
#include <sprout/iterator/next.hpp>
|
2013-04-22 05:51:38 +00:00
|
|
|
#include <sprout/tuple/tuple.hpp>
|
2014-01-14 15:06:38 +00:00
|
|
|
#include <sprout/generator/functions.hpp>
|
|
|
|
#include <sprout/random/random_result_fwd.hpp>
|
|
|
|
#include <sprout/random/variate_generator.hpp>
|
2012-10-05 15:58:56 +00:00
|
|
|
#include <sprout/utility/swap.hpp>
|
2013-04-22 05:51:38 +00:00
|
|
|
#include <sprout/utility/move.hpp>
|
2013-11-22 12:11:08 +00:00
|
|
|
#include <sprout/type_traits/integral_constant.hpp>
|
2014-05-28 15:25:37 +00:00
|
|
|
#include <sprout/type_traits/identity.hpp>
|
|
|
|
#include <sprout/detail/nil_base.hpp>
|
2011-10-12 20:28:33 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace random {
|
|
|
|
//
|
|
|
|
// random_result
|
|
|
|
//
|
|
|
|
template<typename Engine, typename Distribution>
|
|
|
|
class random_result<
|
|
|
|
Engine,
|
|
|
|
Distribution,
|
|
|
|
typename std::enable_if<!std::is_same<Distribution, void>::value>::type
|
|
|
|
>
|
|
|
|
: public std::iterator<
|
|
|
|
std::input_iterator_tag,
|
|
|
|
typename Distribution::result_type,
|
|
|
|
std::ptrdiff_t,
|
|
|
|
typename Distribution::result_type const*,
|
|
|
|
typename Distribution::result_type const&
|
|
|
|
>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Engine engine_type;
|
|
|
|
typedef Distribution distribution_type;
|
|
|
|
typedef typename distribution_type::result_type result_type;
|
2014-01-14 15:06:38 +00:00
|
|
|
typedef sprout::random::variate_generator<engine_type, distribution_type> generator_type;
|
2011-10-12 20:28:33 +00:00
|
|
|
private:
|
|
|
|
typedef std::iterator<
|
|
|
|
std::input_iterator_tag,
|
|
|
|
result_type,
|
|
|
|
std::ptrdiff_t,
|
|
|
|
result_type const*,
|
|
|
|
result_type const&
|
|
|
|
> base_type;
|
|
|
|
public:
|
|
|
|
typedef typename base_type::iterator_category iterator_category;
|
|
|
|
typedef typename base_type::value_type value_type;
|
|
|
|
typedef typename base_type::difference_type difference_type;
|
|
|
|
typedef typename base_type::pointer pointer;
|
|
|
|
typedef typename base_type::reference reference;
|
|
|
|
private:
|
|
|
|
result_type result_;
|
2014-01-14 15:06:38 +00:00
|
|
|
generator_type generator_;
|
2011-10-12 20:28:33 +00:00
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR random_result()
|
2014-05-28 15:25:37 +00:00
|
|
|
: result_(), generator_()
|
2011-10-12 20:28:33 +00:00
|
|
|
{}
|
2014-01-14 15:06:38 +00:00
|
|
|
random_result(random_result const&) = default;
|
2011-10-12 20:28:33 +00:00
|
|
|
SPROUT_CONSTEXPR random_result(
|
|
|
|
result_type result,
|
2014-05-28 15:25:37 +00:00
|
|
|
engine_type const& engine, distribution_type const& distribution
|
2011-10-12 20:28:33 +00:00
|
|
|
)
|
|
|
|
: result_(result)
|
2014-01-14 15:06:38 +00:00
|
|
|
, generator_(engine, distribution)
|
2011-10-12 20:28:33 +00:00
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR random_result operator()() const {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR result_type& generated_value() SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR generator_type& next_generator() SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR generator_type const& next_generator() const SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CXX14_CONSTEXPR result_type& result() SPROUT_NOEXCEPT {
|
2012-09-27 05:19:25 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT {
|
2012-09-27 05:19:25 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-16 09:59:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR generator_type& next() SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR generator_type const& next() const SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_.engine();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_.engine();
|
2012-09-27 05:19:25 +00:00
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR distribution_type& distribution() SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_.distribution();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR distribution_type const& distribution() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_.distribution();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2013-10-17 09:46:31 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR operator result_type&() SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return result_;
|
2013-10-17 09:46:31 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR operator result_type const&() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return result_;
|
2013-10-17 09:46:31 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return distribution().min();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return distribution().max();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(random_result& other)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF(
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(sprout::swap(result_, other.result_))
|
2014-01-14 15:06:38 +00:00
|
|
|
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(generator_, other.generator_))
|
2012-10-05 15:58:56 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
sprout::swap(result_, other.result_);
|
2014-01-14 15:06:38 +00:00
|
|
|
sprout::swap(generator_, other.generator_);
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return lhs.result_ == rhs.result_
|
2014-01-14 15:06:38 +00:00
|
|
|
&& lhs.generator_ == rhs.generator_
|
2011-10-12 20:28:33 +00:00
|
|
|
;
|
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR reference operator*() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return &result_;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR random_result& operator++() {
|
2011-10-12 20:28:33 +00:00
|
|
|
random_result temp((*this)());
|
|
|
|
temp.swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR random_result operator++(int) {
|
2011-10-12 20:28:33 +00:00
|
|
|
random_result result(*this);
|
|
|
|
++*this;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Engine, typename Distribution>
|
|
|
|
class random_result<
|
|
|
|
Engine,
|
|
|
|
Distribution,
|
|
|
|
typename std::enable_if<std::is_same<Distribution, void>::value>::type
|
|
|
|
>
|
|
|
|
: public std::iterator<
|
|
|
|
std::input_iterator_tag,
|
|
|
|
typename Engine::result_type,
|
|
|
|
std::ptrdiff_t,
|
|
|
|
typename Engine::result_type const*,
|
|
|
|
typename Engine::result_type const&
|
|
|
|
>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Engine engine_type;
|
|
|
|
typedef typename engine_type::result_type result_type;
|
2014-01-14 15:06:38 +00:00
|
|
|
typedef engine_type generator_type;
|
2011-10-12 20:28:33 +00:00
|
|
|
private:
|
|
|
|
typedef std::iterator<
|
|
|
|
std::input_iterator_tag,
|
|
|
|
result_type,
|
|
|
|
std::ptrdiff_t,
|
|
|
|
result_type const*,
|
|
|
|
result_type const&
|
|
|
|
> base_type;
|
|
|
|
public:
|
|
|
|
typedef typename base_type::iterator_category iterator_category;
|
|
|
|
typedef typename base_type::value_type value_type;
|
|
|
|
typedef typename base_type::difference_type difference_type;
|
|
|
|
typedef typename base_type::pointer pointer;
|
|
|
|
typedef typename base_type::reference reference;
|
|
|
|
private:
|
|
|
|
result_type result_;
|
2014-01-14 15:06:38 +00:00
|
|
|
generator_type generator_;
|
2011-10-12 20:28:33 +00:00
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR random_result()
|
2014-05-28 15:25:37 +00:00
|
|
|
: result_(), generator_()
|
2011-10-12 20:28:33 +00:00
|
|
|
{}
|
2014-01-14 15:06:38 +00:00
|
|
|
random_result(random_result const&) = default;
|
2014-05-28 15:25:37 +00:00
|
|
|
SPROUT_CONSTEXPR random_result(result_type result, engine_type const& engine)
|
|
|
|
: result_(result), generator_(engine)
|
2011-10-12 20:28:33 +00:00
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR random_result operator()() const {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR result_type& generated_value() SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR result_type const& generated_value() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR generator_type& next_generator() SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR generator_type const& next_generator() const SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CXX14_CONSTEXPR result_type& result() SPROUT_NOEXCEPT {
|
2012-09-26 09:42:43 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR result_type const& result() const SPROUT_NOEXCEPT {
|
2012-09-26 09:42:43 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2014-01-16 09:59:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR generator_type& next() SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR generator_type const& next() const SPROUT_NOEXCEPT {
|
|
|
|
return generator_;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR engine_type& engine() SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_;
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR engine_type const& engine() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return generator_;
|
2012-09-26 09:42:43 +00:00
|
|
|
}
|
2013-10-17 09:46:31 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR operator result_type&() SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return result_;
|
2013-10-17 09:46:31 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR operator result_type const&() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return result_;
|
2013-10-17 09:46:31 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR result_type min() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return engine().min();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR result_type max() const SPROUT_NOEXCEPT {
|
2014-01-14 15:06:38 +00:00
|
|
|
return engine().max();
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
friend SPROUT_CONSTEXPR bool operator==(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return lhs.result_ == rhs.result_
|
2014-01-14 15:06:38 +00:00
|
|
|
&& lhs.generator_ == rhs.generator_
|
2011-10-12 20:28:33 +00:00
|
|
|
;
|
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
friend SPROUT_CONSTEXPR bool operator!=(random_result const& lhs, random_result const& rhs) SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
2013-11-02 09:28:18 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(random_result& other)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF(
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(sprout::swap(result_, other.result_))
|
2014-01-14 15:06:38 +00:00
|
|
|
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(generator_, other.generator_))
|
2012-10-05 15:58:56 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
sprout::swap(result_, other.result_);
|
2014-01-14 15:06:38 +00:00
|
|
|
sprout::swap(generator_, other.generator_);
|
2011-10-12 20:28:33 +00:00
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR reference operator*() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return result_;
|
|
|
|
}
|
2012-11-16 04:40:19 +00:00
|
|
|
SPROUT_CONSTEXPR pointer operator->() const SPROUT_NOEXCEPT {
|
2011-10-12 20:28:33 +00:00
|
|
|
return &result_;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR random_result& operator++() {
|
2011-10-12 20:28:33 +00:00
|
|
|
random_result temp((*this)());
|
|
|
|
temp.swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR random_result operator++(int) {
|
2011-10-12 20:28:33 +00:00
|
|
|
random_result result(*this);
|
|
|
|
random_result temp((*this)());
|
|
|
|
temp.swap(*this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
2012-09-26 07:31:11 +00:00
|
|
|
|
2011-10-12 20:28:33 +00:00
|
|
|
//
|
|
|
|
// swap
|
|
|
|
//
|
|
|
|
template<typename Engine, typename Distribution>
|
2013-10-30 09:15:57 +00:00
|
|
|
inline SPROUT_CXX14_CONSTEXPR void
|
2012-10-05 15:58:56 +00:00
|
|
|
swap(sprout::random::random_result<Engine, Distribution>& lhs, sprout::random::random_result<Engine, Distribution>& rhs)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
2011-10-12 20:28:33 +00:00
|
|
|
{
|
|
|
|
lhs.swap(rhs);
|
|
|
|
}
|
|
|
|
|
2012-09-26 07:31:11 +00:00
|
|
|
//
|
2012-09-26 09:42:43 +00:00
|
|
|
// iterator_next
|
2012-09-26 07:31:11 +00:00
|
|
|
//
|
|
|
|
template<typename Engine, typename Distribution>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::random::random_result<Engine, Distribution>
|
2012-09-26 09:42:43 +00:00
|
|
|
iterator_next(sprout::random::random_result<Engine, Distribution> const& it) {
|
2012-09-26 07:31:11 +00:00
|
|
|
return it();
|
|
|
|
}
|
|
|
|
} // namespace random
|
2011-10-12 20:28:33 +00:00
|
|
|
|
2013-04-22 05:51:38 +00:00
|
|
|
namespace tuples {
|
|
|
|
namespace detail {
|
|
|
|
template<std::size_t I, typename T>
|
|
|
|
struct tuple_element_impl;
|
2014-05-28 15:25:37 +00:00
|
|
|
template<std::size_t I, typename Engine, typename Distribution>
|
|
|
|
struct tuple_element_impl<I, sprout::random::random_result<Engine, Distribution> >
|
|
|
|
: public sprout::detail::nil_base
|
|
|
|
{};
|
2013-04-22 05:51:38 +00:00
|
|
|
template<typename Engine, typename Distribution>
|
2014-05-28 15:25:37 +00:00
|
|
|
struct tuple_element_impl<0, sprout::random::random_result<Engine, Distribution> >
|
|
|
|
: public sprout::identity<typename sprout::random::random_result<Engine, Distribution>::result_type>
|
|
|
|
{};
|
2013-04-22 05:51:38 +00:00
|
|
|
template<typename Engine, typename Distribution>
|
2014-05-28 15:25:37 +00:00
|
|
|
struct tuple_element_impl<1, sprout::random::random_result<Engine, Distribution> >
|
|
|
|
: public sprout::identity<typename sprout::random::random_result<Engine, Distribution>::generator_type>
|
|
|
|
{};
|
2013-04-22 05:51:38 +00:00
|
|
|
|
|
|
|
template<std::size_t I, typename T>
|
|
|
|
struct get_impl;
|
|
|
|
template<typename Engine, typename Distribution>
|
|
|
|
struct get_impl<0, sprout::random::random_result<Engine, Distribution> > {
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::result_type&
|
|
|
|
operator()(sprout::random::random_result<Engine, Distribution>& t) const {
|
|
|
|
return t.generated_value();
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::result_type const&
|
|
|
|
operator()(sprout::random::random_result<Engine, Distribution> const& t) const {
|
|
|
|
return t.generated_value();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Engine, typename Distribution>
|
|
|
|
struct get_impl<1, sprout::random::random_result<Engine, Distribution> > {
|
|
|
|
public:
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::generator_type&
|
2013-04-22 05:51:38 +00:00
|
|
|
operator()(sprout::random::random_result<Engine, Distribution>& t) const {
|
|
|
|
return t.next_generator();
|
|
|
|
}
|
2014-01-14 15:06:38 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::generator_type const&
|
2013-04-22 05:51:38 +00:00
|
|
|
operator()(sprout::random::random_result<Engine, Distribution> const& t) const {
|
|
|
|
return t.next_generator();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace tuples
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
#if defined(__clang__)
|
|
|
|
# pragma clang diagnostic push
|
|
|
|
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
// tuple_size
|
|
|
|
//
|
|
|
|
template<typename Engine, typename Distribution>
|
|
|
|
struct tuple_size<sprout::random::random_result<Engine, Distribution> >
|
2013-11-22 12:11:08 +00:00
|
|
|
: public sprout::integral_constant<std::size_t, 2>
|
2013-04-22 05:51:38 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// tuple_element
|
|
|
|
//
|
|
|
|
template<std::size_t I, typename Engine, typename Distribution>
|
|
|
|
struct tuple_element<I, sprout::random::random_result<Engine, Distribution> >
|
|
|
|
: public sprout::tuples::detail::tuple_element_impl<I, sprout::random::random_result<Engine, Distribution> >
|
|
|
|
{};
|
|
|
|
#if defined(__clang__)
|
|
|
|
# pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace random {
|
|
|
|
//
|
|
|
|
// tuple_get
|
|
|
|
//
|
|
|
|
template<std::size_t I, typename Engine, typename Distribution>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::random::random_result<Engine, Distribution> >::type&
|
|
|
|
tuple_get(sprout::random::random_result<Engine, Distribution>& t) SPROUT_NOEXCEPT {
|
|
|
|
static_assert(I < 2, "tuple_get: index out of range");
|
|
|
|
return sprout::tuples::detail::get_impl<I, sprout::random::random_result<Engine, Distribution> >()(t);
|
|
|
|
}
|
|
|
|
template<std::size_t I, typename Engine, typename Distribution>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::random::random_result<Engine, Distribution> >::type const&
|
|
|
|
tuple_get(sprout::random::random_result<Engine, Distribution> const& t) SPROUT_NOEXCEPT {
|
|
|
|
static_assert(I < 2, "tuple_get: index out of range");
|
|
|
|
return sprout::tuples::detail::get_impl<I, sprout::random::random_result<Engine, Distribution> >()(t);
|
|
|
|
}
|
|
|
|
template<std::size_t I, typename Engine, typename Distribution>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::random::random_result<Engine, Distribution> >::type&&
|
|
|
|
tuple_get(sprout::random::random_result<Engine, Distribution>&& t) SPROUT_NOEXCEPT {
|
|
|
|
return sprout::move(sprout::tuples::get<I>(t));
|
|
|
|
}
|
|
|
|
} // namespace random
|
2011-10-12 20:28:33 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
2013-03-22 05:24:19 +00:00
|
|
|
#endif // #ifndef SPROUT_RANDOM_RANDOM_RESULT_HPP
|