2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2012-09-28 04:15:17 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_FIXED_RECURRENCE_HPP
|
|
|
|
#define SPROUT_ALGORITHM_FIXED_RECURRENCE_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2012-09-28 04:15:17 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
|
|
|
#include <sprout/iterator/operation.hpp>
|
2013-11-20 13:04:11 +00:00
|
|
|
#include <sprout/algorithm/fixed/results.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/pit/pit.hpp>
|
2012-09-28 04:15:17 +00:00
|
|
|
#include <sprout/detail/container_complate.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace fixed {
|
|
|
|
namespace detail {
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
InitSize == 0,
|
|
|
|
typename sprout::container_traits<Container>::value_type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
2013-07-22 13:00:09 +00:00
|
|
|
call_gen(Generator const& gen, Args const&...) {
|
2012-09-28 04:15:17 +00:00
|
|
|
return gen();
|
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
InitSize != 0 && InitSize == sizeof...(Args) + 1,
|
|
|
|
typename sprout::container_traits<Container>::value_type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
call_gen(Generator const& gen, Head const& head, Args const&... args) {
|
2012-09-28 04:15:17 +00:00
|
|
|
return gen(head, args...);
|
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
InitSize != 0 && InitSize != sizeof...(Args) + 1,
|
|
|
|
typename sprout::container_traits<Container>::value_type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
2013-07-22 13:00:09 +00:00
|
|
|
call_gen(Generator const& gen, Head const&, Args const&... args) {
|
2012-09-28 04:15:17 +00:00
|
|
|
return call_gen<InitSize, Container>(gen, args...);
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
recurrence_impl_drop(
|
2013-07-22 13:00:09 +00:00
|
|
|
Container const& cont, Generator const&,
|
|
|
|
typename sprout::container_traits<Container>::size_type
|
2012-09-28 04:15:17 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::detail::container_complate(cont);
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator, typename Head, typename... Inits>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
(sprout::container_traits<Container>::static_size >= sizeof...(Inits) + 1),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl_drop(
|
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2012-09-29 08:10:46 +00:00
|
|
|
Head const& head, Inits const&... inits
|
2012-09-28 04:15:17 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return size < sizeof...(Inits) + 1
|
|
|
|
? sprout::fixed::detail::recurrence_impl_drop(cont, gen, size, inits...)
|
|
|
|
: sprout::detail::container_complate(cont, head, inits...)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator, typename Head, typename... Inits>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
(sprout::container_traits<Container>::static_size < sizeof...(Inits) + 1),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl_drop(
|
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
2013-07-22 13:00:09 +00:00
|
|
|
Head const&, Inits const&... inits
|
2012-09-28 04:15:17 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::fixed::detail::recurrence_impl_drop(cont, gen, size, inits...);
|
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
sprout::container_traits<Container>::static_size == sizeof...(Args),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl_1(
|
2013-07-22 13:00:09 +00:00
|
|
|
Container const& cont, Generator const&,
|
|
|
|
typename sprout::container_traits<Container>::size_type,
|
2012-09-28 04:15:17 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::remake<Container>(cont, sprout::size(cont), args...);
|
|
|
|
}
|
|
|
|
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
sprout::container_traits<Container>::static_size != sizeof...(Args),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl_1(
|
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sizeof...(Args) < size
|
2012-09-29 08:10:46 +00:00
|
|
|
? sprout::fixed::detail::recurrence_impl_1<InitSize>(
|
|
|
|
cont, gen,
|
|
|
|
size,
|
|
|
|
args..., sprout::fixed::detail::call_gen<InitSize, Container>(gen, args...)
|
|
|
|
)
|
2012-09-28 04:15:17 +00:00
|
|
|
: sprout::detail::container_complate(cont, args...)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
(sprout::container_traits<Container>::static_size > sizeof...(Inits)),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl(
|
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
|
|
|
Inits const&... inits
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sizeof...(Inits) < size
|
|
|
|
? sprout::fixed::detail::recurrence_impl_1<sizeof...(Inits)>(cont, gen, size, inits...)
|
|
|
|
: sprout::fixed::detail::recurrence_impl_drop(cont, gen, size, inits...)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
(sprout::container_traits<Container>::static_size <= sizeof...(Inits)),
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
>::type
|
|
|
|
recurrence_impl(
|
|
|
|
Container const& cont, Generator const& gen,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
|
|
|
Inits const&... inits
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::fixed::detail::recurrence_impl_drop(cont, gen, size, inits...);
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// recurrence
|
|
|
|
//
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-29 08:10:46 +00:00
|
|
|
recurrence(Container const& cont, Generator const& gen, Inits const&... inits) {
|
2012-09-28 04:15:17 +00:00
|
|
|
return sprout::fixed::detail::recurrence_impl(cont, gen, sprout::size(cont), inits...);
|
|
|
|
}
|
2013-01-19 23:53:20 +00:00
|
|
|
|
|
|
|
template<typename Container, typename Generator, typename... Inits>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Container>::type
|
2013-01-19 23:53:20 +00:00
|
|
|
recurrence(Generator const& gen, Inits const&... inits) {
|
|
|
|
return sprout::fixed::recurrence(sprout::pit<Container>(), gen, inits...);
|
|
|
|
}
|
2012-09-28 04:15:17 +00:00
|
|
|
} // namespace fixed
|
|
|
|
|
|
|
|
using sprout::fixed::recurrence;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ALGORITHM_FIXED_RECURRENCE_HPP
|