2011-09-01 02:48:32 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_FIXED_GENERATE_HPP
|
|
|
|
#define SPROUT_ALGORITHM_FIXED_GENERATE_HPP
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#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-10-10 01:20:21 +00:00
|
|
|
#include <sprout/iterator/operation.hpp>
|
2011-09-03 13:26:26 +00:00
|
|
|
#include <sprout/algorithm/fixed/result_of.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 {
|
2011-10-27 10:55:58 +00:00
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2011-10-27 10:55:58 +00:00
|
|
|
InitSize == 0,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::value_type
|
2011-09-01 02:48:32 +00:00
|
|
|
>::type call_gen(
|
|
|
|
Generator gen,
|
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return gen();
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
|
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2011-10-27 10:55:58 +00:00
|
|
|
InitSize != 0 && InitSize == sizeof...(Args) + 1,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::value_type
|
2011-09-01 02:48:32 +00:00
|
|
|
>::type call_gen(
|
|
|
|
Generator gen,
|
|
|
|
Head const& head,
|
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return gen(head, args...);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2011-10-27 10:55:58 +00:00
|
|
|
InitSize != 0 && InitSize != sizeof...(Args) + 1,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::value_type
|
2011-10-27 10:55:58 +00:00
|
|
|
>::type call_gen(
|
|
|
|
Generator gen,
|
|
|
|
Head const& head,
|
2011-09-01 02:48:32 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return call_gen<InitSize, Container>(gen, args...);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<typename Container, typename Generator>
|
|
|
|
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Container>::type generate_impl_drop(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return sprout::detail::container_complate(cont);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<typename Container, typename Generator, typename Head, typename... Inits>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size >= sizeof...(Inits) + 1),
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2011-10-27 10:55:58 +00:00
|
|
|
>::type generate_impl_drop(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-10-27 10:55:58 +00:00
|
|
|
Head const& head,
|
|
|
|
Inits const&... inits
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return size < sizeof...(Inits) + 1
|
|
|
|
? sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...)
|
|
|
|
: sprout::detail::container_complate(cont, head, inits...)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<typename Container, typename Generator, typename Head, typename... Inits>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size < sizeof...(Inits) + 1),
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2011-10-27 10:55:58 +00:00
|
|
|
>::type generate_impl_drop(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
2011-10-27 10:55:58 +00:00
|
|
|
Generator gen,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-09-01 02:48:32 +00:00
|
|
|
Head const& head,
|
2011-10-27 10:55:58 +00:00
|
|
|
Inits const&... inits
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Container>::static_size == sizeof...(Args),
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2011-10-27 10:55:58 +00:00
|
|
|
>::type generate_impl_1(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
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-03-31 07:24:13 +00:00
|
|
|
return sprout::remake<Container>(cont, sprout::size(cont), args...);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Container>::static_size != sizeof...(Args),
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2011-09-01 02:48:32 +00:00
|
|
|
>::type generate_impl_1(
|
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
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
|
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return sizeof...(Args) < size
|
2011-10-28 12:45:00 +00:00
|
|
|
? sprout::fixed::detail::generate_impl_1<InitSize>(cont, gen, size, args..., sprout::fixed::detail::call_gen<InitSize, Container>(gen, args...))
|
2011-10-27 10:55:58 +00:00
|
|
|
: sprout::detail::container_complate(cont, args...)
|
|
|
|
;
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
2011-10-27 10:55:58 +00:00
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
2011-09-01 02:48:32 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size > sizeof...(Inits)),
|
2011-09-03 13:26:26 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
2011-10-27 10:55:58 +00:00
|
|
|
>::type generate_impl(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-10-27 10:55:58 +00:00
|
|
|
Inits const&... inits
|
2011-09-01 02:48:32 +00:00
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return sizeof...(Inits) < size
|
|
|
|
? sprout::fixed::detail::generate_impl_1<sizeof...(Inits)>(cont, gen, size, inits...)
|
|
|
|
: sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...)
|
2011-09-01 02:48:32 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
2011-10-27 10:55:58 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
(sprout::container_traits<Container>::static_size <= sizeof...(Inits)),
|
2011-10-27 10:55:58 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Container>::type
|
|
|
|
>::type generate_impl(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2011-09-01 02:48:32 +00:00
|
|
|
Inits const&... inits
|
|
|
|
)
|
|
|
|
{
|
2011-10-27 10:55:58 +00:00
|
|
|
return sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...);
|
2011-09-01 02:48:32 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// generate
|
|
|
|
//
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
2011-09-03 13:26:26 +00:00
|
|
|
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Container>::type generate(
|
2011-09-01 02:48:32 +00:00
|
|
|
Container const& cont,
|
|
|
|
Generator gen,
|
|
|
|
Inits const&... inits
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::fixed::detail::generate_impl(cont, gen, sprout::size(cont), inits...);
|
|
|
|
}
|
|
|
|
} // 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
|