/*============================================================================= Copyright (c) 2011-2015 Bolero MURAKAMI 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) =============================================================================*/ #ifndef SPROUT_RANDOM_GENERATE_ARRAY_HPP #define SPROUT_RANDOM_GENERATE_ARRAY_HPP #include #include #include #include #include #include #include #include namespace sprout { namespace random { // // generate_array // template inline SPROUT_CXX14_CONSTEXPR sprout::array generate_array(RandomNumberGenerator& rng) { sprout::array result{{}}; for (std::size_t i = 0; i != N; ++i) { result[i] = rng(); } return result; } template inline SPROUT_CXX14_CONSTEXPR sprout::array::type::result_type, N> generate_array(RandomNumberGenerator& rng, Distribution&& dist) { sprout::array::type::result_type, N> result{{}}; for (std::size_t i = 0; i != N; ++i) { result[i] = SPROUT_FORWARD(Distribution, dist)(rng); } return result; } namespace detail { template static SPROUT_CONSTEXPR typename std::enable_if< (sizeof...(Args) + 1 == N), sprout::pair< sprout::array::type, N>, typename sprout::generators::results::next_generator::type > const >::type generate_array_impl(Random const& rnd, Args const&... args) { typedef sprout::pair< sprout::array::type, N>, typename sprout::generators::results::next_generator::type > const pair_type; return pair_type{ sprout::array{{args..., sprout::random::result(rnd)}}, sprout::random::next(rnd) }; } template static SPROUT_CONSTEXPR typename std::enable_if< (sizeof...(Args) + 1 < N), sprout::pair< sprout::array::type, N>, typename sprout::generators::results::next_generator::type > const >::type generate_array_impl(Random const& rnd, Args const&... args) { return sprout::random::detail::generate_array_impl( sprout::random::next(rnd)(), args..., sprout::random::result(rnd) ); } } // namespace detail // // generate_array // template inline SPROUT_CONSTEXPR sprout::pair< sprout::array::type, N>, typename sprout::generators::results::next_generator::type > const generate_array(RandomNumberGenerator const& rng) { return sprout::random::detail::generate_array_impl(rng()); } } // namespace random } // namespace sprout #endif // #ifndef SPROUT_RANDOM_GENERATE_ARRAY_HPP