2011-09-01 02:48:32 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_FIXED_GENERATE_HPP
|
|
|
|
#define SPROUT_ALGORITHM_FIXED_GENERATE_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2011-09-03 13:26:26 +00:00
|
|
|
#include <sprout/algorithm/fixed/result_of.hpp>
|
2012-09-21 06:43:30 +00:00
|
|
|
#include <sprout/generator/functions.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/pit/pit.hpp>
|
2011-10-27 10:55:58 +00:00
|
|
|
#include <sprout/detail/container_complate.hpp>
|
2011-09-01 02:48:32 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace fixed {
|
|
|
|
namespace detail {
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Next, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-21 06:43:30 +00:00
|
|
|
sprout::container_traits<Container>::static_size == sizeof...(Args) + 1,
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
generate_impl_1(
|
2012-09-28 04:15:17 +00:00
|
|
|
Container const& cont, Next const& next,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-09-01 02:48:32 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return sprout::remake<Container>(cont, size, args..., sprout::generators::generated_value(next));
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Next, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-21 06:43:30 +00:00
|
|
|
sprout::container_traits<Container>::static_size != sizeof...(Args) + 1,
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type
|
|
|
|
generate_impl_1(
|
2012-09-28 04:15:17 +00:00
|
|
|
Container const& cont, Next const& next,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-09-01 02:48:32 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-09-21 06:43:30 +00:00
|
|
|
return sizeof...(Args) + 1 < size
|
|
|
|
? sprout::fixed::detail::generate_impl_1(
|
2012-09-28 04:15:17 +00:00
|
|
|
cont, sprout::generators::next_generator(next)(), size,
|
|
|
|
args..., sprout::generators::generated_value(next)
|
2012-09-21 06:43:30 +00:00
|
|
|
)
|
2012-09-28 04:15:17 +00:00
|
|
|
: sprout::detail::container_complate(cont, args..., sprout::generators::generated_value(next))
|
2011-10-27 10:55:58 +00:00
|
|
|
;
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename Container, typename Generator>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-21 06:43:30 +00:00
|
|
|
sprout::container_traits<Container>::static_size == 0,
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
generate_impl(
|
2012-09-28 04:15:17 +00:00
|
|
|
Container const& cont, Generator const& next,
|
2012-09-21 06:43:30 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2012-09-21 06:43:30 +00:00
|
|
|
return sprout::remake<Container>(cont, size);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename Container, typename Generator>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-21 06:43:30 +00:00
|
|
|
sprout::container_traits<Container>::static_size != 0,
|
2011-10-27 10:55:58 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type
|
|
|
|
generate_impl(
|
2012-09-27 13:15:29 +00:00
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-21 06:43:30 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return size > 0
|
2012-09-21 06:43:30 +00:00
|
|
|
? sprout::fixed::detail::generate_impl_1(cont, gen(), size)
|
|
|
|
: sprout::detail::container_complate(cont)
|
|
|
|
;
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// generate
|
|
|
|
//
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename Container, typename Generator>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
|
2012-09-27 13:15:29 +00:00
|
|
|
generate(Container const& cont, Generator const& gen) {
|
2012-09-21 06:43:30 +00:00
|
|
|
return sprout::fixed::detail::generate_impl(cont, gen, sprout::size(cont));
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2013-01-19 23:53:20 +00:00
|
|
|
|
|
|
|
template<typename Container, typename Generator>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
|
|
|
|
generate(Generator const& gen) {
|
|
|
|
return sprout::fixed::generate(sprout::pit<Container>());
|
|
|
|
}
|
2011-09-01 02:48:32 +00:00
|
|
|
} // namespace fixed
|
2011-09-03 13:26:26 +00:00
|
|
|
|
|
|
|
using sprout::fixed::generate;
|
2011-09-01 02:48:32 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ALGORITHM_FIXED_GENERATE_HPP
|