fix shufle_order: support clang 3.3 or later (default template depth 256)

This commit is contained in:
bolero-MURAKAMI 2014-01-11 16:05:18 +09:00
parent 14f8d9d042
commit e7b8d74c0f
4 changed files with 104 additions and 3 deletions

View file

@ -0,0 +1,62 @@
/*=============================================================================
Copyright (c) 2011-2014 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 <cstddef>
#include <sprout/config.hpp>
#include <sprout/array/array.hpp>
#include <sprout/utility/pair/pair.hpp>
namespace sprout {
namespace random {
//
// generate_array
//
template<std::size_t N, typename URNG>
inline SPROUT_CXX14_CONSTEXPR sprout::array<typename URNG::result_type, N>
generate_array(URNG& rng) {
sprout::array<typename URNG::result_type, N> result{{}};
for (std::size_t i = 0; i != N; ++i) {
result[i] = rng();
}
return result;
}
namespace detail {
template<std::size_t N, typename URNG, typename Random, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
(sizeof...(Args) + 1 == N),
sprout::pair<sprout::array<typename URNG::result_type, N>, URNG> const
>::type generate_array_impl(Random const& rnd, Args const&... args) {
typedef sprout::pair<sprout::array<typename URNG::result_type, N>, URNG> const pair_type;
return pair_type{
sprout::array<typename URNG::result_type, N>{{args..., rnd.result()}},
rnd.engine()
};
}
template<std::size_t N, typename URNG, typename Random, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
(sizeof...(Args) + 1 < N),
sprout::pair<sprout::array<typename URNG::result_type, N>, URNG> const
>::type generate_array_impl(Random const& rnd, Args const&... args) {
return sprout::random::detail::generate_array_impl<N, URNG>(rnd(), args..., rnd.result());
}
} // namespace detail
//
// generate_array
//
template<std::size_t N, typename URNG>
inline SPROUT_CONSTEXPR sprout::pair<sprout::array<typename URNG::result_type, N>, URNG> const
generate_array(URNG const& rng) {
return sprout::random::detail::generate_array_impl<N, URNG>(rng());
}
} // namespace random
} // namespace sprout
#endif // #ifndef SPROUT_RANDOM_GENERATE_ARRAY_HPP

View file

@ -23,8 +23,10 @@
#include <sprout/random/linear_congruential.hpp>
#include <sprout/random/detail/signed_unsigned_tools.hpp>
#include <sprout/random/type_traits.hpp>
#include <sprout/random/generate_array.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/assert.hpp>
#include <sprout/workaround/recursive_function_template.hpp>
namespace sprout {
namespace random {
@ -77,6 +79,36 @@ namespace sprout {
return base_type::static_max();
}
private:
template<std::size_t M, typename Random, typename... Args, sprout::index_t... Indexes>
static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) == k),
member_type
>::type init_member_4(sprout::index_tuple<Indexes...>, sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) {
return member_type{
rnd.engine(),
sprout::array<result_type, k>{{a[Indexes]..., args...}},
rnd.result()
};
}
template<std::size_t M, typename Random, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) == k),
member_type
>::type init_member_3(sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) {
return init_member_4(sprout::make_index_tuple<M>::make(), a, rnd, args...);
}
template<std::size_t M, typename Random, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
(M + sizeof...(Args) < k),
member_type
>::type init_member_3(sprout::array<result_type, M> const& a, Random const& rnd, Args const&... args) {
return init_member_3(a, rnd(), args..., rnd.result());
}
template<typename Pair>
static SPROUT_CONSTEXPR member_type init_member_2(Pair const& p) {
return init_member_3(p.first, p.second());
}
template<typename Random, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
(sizeof...(Args) == k),
@ -95,9 +127,15 @@ namespace sprout {
>::type init_member_1(Random const& rnd, Args const&... args) {
return init_member_1(rnd(), args..., rnd.result());
}
static SPROUT_CONSTEXPR member_type init_member(base_type const& rng) {
static SPROUT_CONSTEXPR member_type init_member_0(base_type const& rng, std::true_type) {
return init_member_2(sprout::random::generate_array<k / 2>(rng));
}
static SPROUT_CONSTEXPR member_type init_member_0(base_type const& rng, std::false_type) {
return init_member_1(rng());
}
static SPROUT_CONSTEXPR member_type init_member(base_type const& rng) {
return init_member_0(rng, std::integral_constant<bool, (k >= SPROUT_RECURSIVE_FUNCTION_TEMPLATE_INSTANTIATION_LIMIT)>());
}
private:
using member_type::rng_;
using member_type::v_;

View file

@ -11,6 +11,7 @@
#include <sprout/config.hpp>
#include <sprout/random/random_result.hpp>
#include <sprout/random/generate_canonical.hpp>
#include <sprout/random/generate_array.hpp>
#include <sprout/random/variate_generator.hpp>
#include <sprout/random/iterator.hpp>
#include <sprout/random/range.hpp>

View file

@ -23,8 +23,8 @@ std="c++11"
declare -a common_options=()
declare -a version_options=()
declare -A version_specific_options=(
[clang-3.3]='-ftemplate-depth=512'
[clang-3.4]='-ftemplate-depth=512'
# [clang-3.3]='-ftemplate-depth=512'
# [clang-3.4]='-ftemplate-depth=512'
)
test_cpp=$(cd $(dirname $0); pwd)/test.cpp
test_py=$(cd $(dirname $0); pwd)/test.py