/*============================================================================= 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_UNIQUE_SEED_HPP #define SPROUT_RANDOM_UNIQUE_SEED_HPP #include #include #include #include #include #include #include namespace sprout { // // make_seed // template SPROUT_CONSTEXPR std::uint_least32_t make_seed(T const& v) { return static_cast(sprout::to_hash(v)); } namespace detail { template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) + 1 == N, sprout::array >::type make_seed_seq_impl(T const&, std::size_t seed, Args const&... args) { return sprout::array{{args..., static_cast(seed)}}; } template SPROUT_CONSTEXPR typename std::enable_if< sizeof...(Args) + 1 != N, sprout::array >::type make_seed_seq_impl(T const& v, std::size_t seed, Args const&... args) { return sprout::detail::make_seed_seq_impl(v, sprout::hash_combine(seed, v), args..., static_cast(seed)); } } // namespace detail // // make_seed_seq // template SPROUT_CONSTEXPR sprout::array make_seed_seq(T const& v) { return sprout::detail::make_seed_seq_impl(v, sprout::to_hash(v)); } } // namespace sprout // // SPROUT_UNIQUE_SEED // #define SPROUT_UNIQUE_SEED (::sprout::make_seed(SPROUT_PP_UNIQUE_STRING)) // // SPROUT_UNIQUE_SEED_SEQ // #define SPROUT_UNIQUE_SEED_SEQ(N) (::sprout::make_seed_seq(SPROUT_PP_UNIQUE_STRING)) #endif // #ifndef SPROUT_RANDOM_UNIQUE_SEED_HPP