/*============================================================================= Copyright (c) 2011-2013 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_ALGORITHM_FIXED_GENERATE_HPP #define SPROUT_ALGORITHM_FIXED_GENERATE_HPP #include #include #include #include #include #include #include #include namespace sprout { namespace fixed { namespace detail { template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == sizeof...(Args) + 1, typename sprout::fixed::results::algorithm::type >::type generate_impl_1( Container const& cont, Next const& next, typename sprout::container_traits::size_type size, Args const&... args ) { return sprout::remake(cont, size, args..., sprout::generators::generated_value(next)); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != sizeof...(Args) + 1, typename sprout::fixed::results::algorithm::type >::type generate_impl_1( Container const& cont, Next const& next, typename sprout::container_traits::size_type size, Args const&... args ) { return sizeof...(Args) + 1 < size ? sprout::fixed::detail::generate_impl_1( cont, sprout::generators::next_generator(next)(), size, args..., sprout::generators::generated_value(next) ) : sprout::detail::container_complate(cont, args..., sprout::generators::generated_value(next)) ; } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size == 0, typename sprout::fixed::results::algorithm::type >::type generate_impl( Container const& cont, Generator const&, typename sprout::container_traits::size_type size ) { return sprout::remake(cont, size); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::container_traits::static_size != 0, typename sprout::fixed::results::algorithm::type >::type generate_impl( Container const& cont, Generator const& gen, typename sprout::container_traits::size_type size ) { return size > 0 ? sprout::fixed::detail::generate_impl_1(cont, gen(), size) : sprout::detail::container_complate(cont) ; } } // namespace detail // // generate // template inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type generate(Container const& cont, Generator const& gen) { return sprout::fixed::detail::generate_impl(cont, gen, sprout::size(cont)); } template inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type generate(Generator const& gen) { return sprout::fixed::generate(sprout::pit(), gen); } } // namespace fixed using sprout::fixed::generate; } // namespace sprout #endif // #ifndef SPROUT_ALGORITHM_FIXED_GENERATE_HPP