sprout/algorithm/fixed/generate.hpp 修正

This commit is contained in:
bolero-MURAKAMI 2011-10-27 19:55:58 +09:00
parent 068656e0b7
commit f4aba3218c
4 changed files with 84 additions and 262 deletions

View file

@ -93,12 +93,7 @@ namespace sprout {
void*
)
{
return sprout::fixed::detail::copy_impl(
first,
last,
result,
sprout::size(result)
);
return sprout::fixed::detail::copy_impl(first, last, result, sprout::size(result));
}
} // namespace detail
//
@ -112,12 +107,7 @@ namespace sprout {
)
{
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
return sprout::fixed::detail::copy(
first,
last,
result,
category()
);
return sprout::fixed::detail::copy(first, last, result, category());
}
} // namespace fixed

View file

@ -7,42 +7,21 @@
#include <sprout/fixed_container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/detail/container_complate.hpp>
namespace sprout {
namespace fixed {
namespace detail {
template<typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_3(
Result const& result,
Args const&... args
)
{
return sprout::remake_clone<Result, Result>(result, sprout::size(result), args...);
}
template<typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_3(
Result const& result,
Args const&... args
)
{
return copy_if_impl_3(result, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args)));
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_2(
>::type copy_if_impl(
InputIterator first,
InputIterator last,
Result const& result,
Predicate pred,
typename sprout::fixed_container_traits<Result>::difference_type offset,
typename sprout::fixed_container_traits<Result>::size_type size,
Args const&... args
)
{
@ -52,65 +31,22 @@ namespace sprout {
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_2(
>::type copy_if_impl(
InputIterator first,
InputIterator last,
Result const& result,
Predicate pred,
typename sprout::fixed_container_traits<Result>::difference_type offset,
typename sprout::fixed_container_traits<Result>::size_type size,
Args const&... args
)
{
return first != last && sizeof...(Args) < static_cast<std::size_t>(offset)
return first != last && sizeof...(Args) < size
? pred(*first)
? copy_if_impl_2(sprout::next(first), last, result, pred, offset, args..., *first)
: copy_if_impl_2(sprout::next(first), last, result, pred, offset, args...)
: copy_if_impl_3(result, args...)
? sprout::fixed::detail::copy_if_impl(sprout::next(first), last, result, pred, size, args..., *first)
: sprout::fixed::detail::copy_if_impl(sprout::next(first), last, result, pred, size, args...)
: sprout::detail::container_complate(result, args...)
;
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_1(
InputIterator first,
InputIterator last,
Result const& result,
Predicate pred,
typename sprout::fixed_container_traits<Result>::difference_type offset,
Args const&... args
)
{
return sprout::remake_clone<Result, Result>(result, sprout::size(result), args...);
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_if_impl_1(
InputIterator first,
InputIterator last,
Result const& result,
Predicate pred,
typename sprout::fixed_container_traits<Result>::difference_type offset,
Args const&... args
)
{
return sizeof...(Args) < static_cast<std::size_t>(offset)
? copy_if_impl_1(first, last, result, pred, offset, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args)))
: copy_if_impl_2(first, last, result, pred, offset + sprout::size(result), args...)
;
}
template<typename InputIterator, typename Result, typename Predicate>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type copy_if_impl(
InputIterator first,
InputIterator last,
Result const& result,
Predicate pred
)
{
return copy_if_impl_1(first, last, result, pred, sprout::fixed_begin_offset(result));
}
} // namespace detail
//
// copy_if
@ -123,7 +59,7 @@ namespace sprout {
Predicate pred
)
{
return sprout::fixed::detail::copy_if_impl(first, last, result, pred);
return sprout::fixed::detail::copy_if_impl(first, last, result, pred, sprout::size(result));
}
} // namespace fixed

View file

@ -9,6 +9,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy.hpp>
#include <sprout/detail/container_complate.hpp>
namespace sprout {
namespace fixed {
@ -21,39 +22,13 @@ namespace sprout {
std::random_access_iterator_tag*
)
{
return sprout::fixed::copy(
first,
sprout::next(first, n),
result
);
}
template<typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_3(
Result const& result,
Args const&... args
)
{
return sprout::remake_clone<Result, Result>(result, sprout::size(result), args...);
}
template<typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_3(
Result const& result,
Args const&... args
)
{
return copy_n_impl_3(result, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args)));
return sprout::fixed::copy(first, sprout::next(first, n), result);
}
template<typename InputIterator, typename Size, typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_2(
>::type copy_n_impl(
InputIterator first,
Size n,
Result const& result,
@ -67,7 +42,7 @@ namespace sprout {
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_2(
>::type copy_n_impl(
InputIterator first,
Size n,
Result const& result,
@ -76,50 +51,10 @@ namespace sprout {
)
{
return n != 0 && sizeof...(Args) < static_cast<std::size_t>(offset)
? copy_n_impl_2(sprout::next(first), n - 1, result, offset, args..., *first)
: copy_n_impl_3(result, args...)
? sprout::fixed::detail::copy_n_impl(sprout::next(first), n - 1, result, offset, args..., *first)
: sprout::detail::container_complate(result, args...)
;
}
template<typename InputIterator, typename Size, typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_1(
InputIterator first,
Size n,
Result const& result,
typename sprout::fixed_container_traits<Result>::difference_type offset,
Args const&... args
)
{
return sprout::remake_clone<Result, Result>(result, sprout::size(result), args...);
}
template<typename InputIterator, typename Size, typename Result, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Result>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type copy_n_impl_1(
InputIterator first,
Size n,
Result const& result,
typename sprout::fixed_container_traits<Result>::difference_type offset,
Args const&... args
)
{
return sizeof...(Args) < static_cast<std::size_t>(offset)
? copy_n_impl_1(first, n, result, offset, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args)))
: copy_n_impl_2(first, n, result, offset + sprout::size(result), args...)
;
}
template<typename InputIterator, typename Size, typename Result>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type copy_n_impl(
InputIterator first,
Size n,
Result const& result
)
{
return copy_n_impl_1(first, n, result, sprout::fixed_begin_offset(result));
}
template<typename InputIterator, typename Size, typename Result>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type copy_n(
InputIterator first,
@ -128,11 +63,7 @@ namespace sprout {
void*
)
{
return sprout::fixed::detail::copy_n_impl(
first,
n,
result
);
return sprout::fixed::detail::copy_n_impl(first, n, result, sprout::size(result));
}
} // namespace detail
//
@ -146,12 +77,7 @@ namespace sprout {
)
{
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
return sprout::fixed::detail::copy_n(
first,
n,
result,
category()
);
return sprout::fixed::detail::copy_n(first, n, result, category());
}
} // namespace fixed

View file

@ -8,13 +8,25 @@
#include <sprout/fixed_container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/detail/container_complate.hpp>
namespace sprout {
namespace fixed {
namespace detail {
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
InitSize == 0,
typename sprout::fixed_container_traits<Container>::value_type
>::type call_gen(
Generator gen,
Args const&... args
)
{
return gen();
}
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
InitSize == sizeof...(Args) + 1,
InitSize != 0 && InitSize == sizeof...(Args) + 1,
typename sprout::fixed_container_traits<Container>::value_type
>::type call_gen(
Generator gen,
@ -26,7 +38,7 @@ namespace sprout {
}
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
InitSize != sizeof...(Args) + 1,
InitSize != 0 && InitSize != sizeof...(Args) + 1,
typename sprout::fixed_container_traits<Container>::value_type
>::type call_gen(
Generator gen,
@ -36,105 +48,46 @@ namespace sprout {
{
return call_gen<InitSize, Container>(gen, args...);
}
template<typename Container, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Container>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_4(
Container const& cont,
Args const&... args
)
{
return sprout::remake_clone<Container, Container>(cont, sprout::size(cont), args...);
}
template<typename Container, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Container>::fixed_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_4(
Container const& cont,
Args const&... args
)
{
return generate_impl_4(cont, args..., *sprout::next(sprout::fixed_begin(cont), sizeof...(Args)));
}
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Container>::fixed_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_3(
template<typename Container, typename Generator>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Container>::type generate_impl_drop(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::difference_type offset,
Args const&... args
typename sprout::fixed_container_traits<Container>::size_type size
)
{
return sprout::remake_clone<Container, Container>(cont, sprout::size(cont), args...);
return sprout::detail::container_complate(cont);
}
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
template<typename Container, typename Generator, typename Head, typename... Inits>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Container>::fixed_size != sizeof...(Args),
(sprout::fixed_container_traits<Container>::fixed_size >= sizeof...(Inits) + 1),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_3(
>::type generate_impl_drop(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::difference_type offset,
Args const&... args
)
{
return sizeof...(Args) < static_cast<std::size_t>(offset)
? generate_impl_3<InitSize>(cont, gen, offset, args..., call_gen<InitSize, Container>(gen, args...))
: generate_impl_4(cont, args...)
;
}
template<typename Container, typename Head, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sizeof...(Args) == 0,
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_2_drop(
Container const& cont,
typename sprout::fixed_container_traits<Container>::size_type dropped_size,
Head const& head,
Args const&... args
)
{
return sprout::remake_clone<Container, Container>(cont, sprout::size(cont), args...);
}
template<typename Container, typename Head, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sizeof...(Args) != 0,
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_2_drop(
Container const& cont,
typename sprout::fixed_container_traits<Container>::size_type dropped_size,
Head const& head,
Args const&... args
)
{
return sizeof...(Args) + 1 != dropped_size
? generate_impl_2_drop(cont, dropped_size, args...)
: generate_impl_4(cont, head, args...)
;
}
template<std::size_t InitSize, typename Container, typename Generator, typename Head, typename... Args>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Container>::type generate_impl_2(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::difference_type offset,
typename sprout::fixed_container_traits<Container>::size_type size,
std::size_t remain,
Head const& head,
Args const&... args
Inits const&... inits
)
{
return InitSize - remain != size
? (remain > 1
? generate_impl_2<InitSize>(cont, gen, offset, size, remain - 1, args..., head)
: generate_impl_3<InitSize>(cont, gen, offset + size, args..., head)
)
: generate_impl_2_drop(cont, offset + size, head, args...)
return size < sizeof...(Inits) + 1
? sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...)
: sprout::detail::container_complate(cont, head, inits...)
;
}
template<typename Container, typename Generator, typename Head, typename... Inits>
SPROUT_CONSTEXPR inline typename std::enable_if<
(sprout::fixed_container_traits<Container>::fixed_size < sizeof...(Inits) + 1),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl_drop(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::size_type size,
Head const& head,
Inits const&... inits
)
{
return sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...);
}
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::fixed_container_traits<Container>::fixed_size == sizeof...(Args),
@ -142,12 +95,11 @@ namespace sprout {
>::type generate_impl_1(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::difference_type offset,
typename sprout::fixed_container_traits<Container>::size_type size,
Args const&... args
)
{
return generate_impl_2<InitSize>(cont, gen, offset, size, InitSize, args...);
return sprout::remake_clone<Container, Container>(cont, sprout::size(cont), args...);
}
template<std::size_t InitSize, typename Container, typename Generator, typename... Args>
SPROUT_CONSTEXPR inline typename std::enable_if<
@ -156,25 +108,43 @@ namespace sprout {
>::type generate_impl_1(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::difference_type offset,
typename sprout::fixed_container_traits<Container>::size_type size,
Args const&... args
)
{
return sizeof...(Args) - InitSize < static_cast<std::size_t>(offset)
? generate_impl_1<InitSize>(cont, gen, offset, size, args..., *sprout::next(sprout::fixed_begin(cont), sizeof...(Args) - InitSize))
: generate_impl_2<InitSize>(cont, gen, offset, size, InitSize, args...)
return sizeof...(Args) < size
? generate_impl_1<InitSize>(cont, gen, size, args..., sprout::fixed::detail::call_gen<InitSize, Container>(gen, args...))
: sprout::detail::container_complate(cont, args...)
;
}
template<typename Container, typename Generator, typename... Inits>
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Container>::type generate_impl(
SPROUT_CONSTEXPR inline typename std::enable_if<
(sprout::fixed_container_traits<Container>::fixed_size > sizeof...(Inits)),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::size_type size,
Inits const&... inits
)
{
return generate_impl_1<sizeof...(Inits)>(cont, gen, sprout::fixed_begin_offset(cont), size, inits...);
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...)
;
}
template<typename Container, typename Generator, typename... Inits>
SPROUT_CONSTEXPR inline typename std::enable_if<
(sprout::fixed_container_traits<Container>::fixed_size <= sizeof...(Inits)),
typename sprout::fixed::result_of::algorithm<Container>::type
>::type generate_impl(
Container const& cont,
Generator gen,
typename sprout::fixed_container_traits<Container>::size_type size,
Inits const&... inits
)
{
return sprout::fixed::detail::generate_impl_drop(cont, gen, size, inits...);
}
} // namespace detail
//