2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2019-01-07 08:47:17 +00:00
|
|
|
Copyright (c) 2011-2019 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-21 06:43:30 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_FIXED_UNFOLD_HPP
|
|
|
|
#define SPROUT_ALGORITHM_FIXED_UNFOLD_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2013-11-20 13:04:11 +00:00
|
|
|
#include <sprout/algorithm/fixed/results.hpp>
|
2012-09-28 04:15:17 +00:00
|
|
|
#include <sprout/generator/functions.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/pit/pit.hpp>
|
2012-09-21 06:43:30 +00:00
|
|
|
#include <sprout/detail/container_complate.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace fixed {
|
|
|
|
namespace detail {
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Generator, typename Next, typename... Args>
|
2012-09-21 06:43:30 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-28 04:15:17 +00:00
|
|
|
sprout::container_traits<Container>::static_size == sizeof...(Args) + 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
|
|
|
|
unfold_impl_1(
|
2013-07-22 13:00:09 +00:00
|
|
|
Container const& cont, Generator const&, Next const& next,
|
2012-09-21 06:43:30 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return sprout::remake<Container>(cont, size, args..., sprout::generators::generated_value(next));
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Generator, typename Next, typename... Args>
|
2012-09-21 06:43:30 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-28 04:15:17 +00:00
|
|
|
sprout::container_traits<Container>::static_size != sizeof...(Args) + 1,
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-28 04:15:17 +00:00
|
|
|
>::type
|
|
|
|
unfold_impl_1(
|
|
|
|
Container const& cont, Generator const& gen, Next const& next,
|
2012-09-21 06:43:30 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size,
|
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return sizeof...(Args) + 1 < size
|
|
|
|
? sprout::fixed::detail::unfold_impl_1(
|
|
|
|
cont, gen, gen(sprout::generators::next_generator(next)), size,
|
|
|
|
args..., sprout::generators::generated_value(next)
|
|
|
|
)
|
|
|
|
: sprout::detail::container_complate(cont, args..., sprout::generators::generated_value(next))
|
2012-09-21 06:43:30 +00:00
|
|
|
;
|
|
|
|
}
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Generator, typename Init>
|
2012-09-21 06:43:30 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-28 04:15:17 +00:00
|
|
|
sprout::container_traits<Container>::static_size == 0,
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type unfold_impl(
|
2013-07-22 13:00:09 +00:00
|
|
|
Container const& cont, Generator const&, Init const&,
|
2012-09-28 04:15:17 +00:00
|
|
|
typename sprout::container_traits<Container>::size_type size
|
2012-09-21 06:43:30 +00:00
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return sprout::remake<Container>(cont, size);
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Generator, typename Init>
|
2012-09-21 06:43:30 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-09-28 04:15:17 +00:00
|
|
|
sprout::container_traits<Container>::static_size != 0,
|
2013-11-20 13:04:11 +00:00
|
|
|
typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-28 04:15:17 +00:00
|
|
|
>::type
|
|
|
|
unfold_impl(
|
|
|
|
Container const& cont, Generator const& gen, Init const& init,
|
|
|
|
typename sprout::container_traits<Container>::size_type size
|
2012-09-21 06:43:30 +00:00
|
|
|
)
|
|
|
|
{
|
2012-09-28 04:15:17 +00:00
|
|
|
return size > 0
|
2012-09-28 07:05:09 +00:00
|
|
|
? sprout::fixed::detail::unfold_impl_1(cont, gen, gen(init), size)
|
2012-09-28 04:15:17 +00:00
|
|
|
: sprout::detail::container_complate(cont)
|
|
|
|
;
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// unfold
|
|
|
|
//
|
2012-09-28 04:15:17 +00:00
|
|
|
template<typename Container, typename Generator, typename Init>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Container>::type
|
2012-09-28 04:15:17 +00:00
|
|
|
unfold(Container const& cont, Generator const& gen, Init const& init) {
|
|
|
|
return sprout::fixed::detail::unfold_impl(cont, gen, init, sprout::size(cont));
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
2013-01-19 23:53:20 +00:00
|
|
|
|
|
|
|
template<typename Container, typename Generator, typename Init>
|
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
|
|
|
unfold(Generator const& gen, Init const& init) {
|
|
|
|
return sprout::fixed::unfold(sprout::pit<Container>(), gen, init);
|
|
|
|
}
|
2012-09-21 06:43:30 +00:00
|
|
|
} // namespace fixed
|
|
|
|
|
|
|
|
using sprout::fixed::unfold;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ALGORITHM_FIXED_UNFOLD_HPP
|