1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

add algorithm copy_while, copy_until

This commit is contained in:
bolero-MURAKAMI 2012-10-13 22:11:32 +09:00
parent f53be1a3d5
commit 9b9956f810
20 changed files with 649 additions and 0 deletions

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_COPY_UNTIL_HPP
#define SPROUT_ALGORITHM_COPY_UNTIL_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/copy_until.hpp>
#include <sprout/algorithm/fit/copy_until.hpp>
#endif // #ifndef SPROUT_ALGORITHM_COPY_UNTIL_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_ALGORITHM_COPY_WHILE_HPP
#define SPROUT_ALGORITHM_COPY_WHILE_HPP
#include <sprout/config.hpp>
#include <sprout/algorithm/fixed/copy_while.hpp>
#include <sprout/algorithm/fit/copy_while.hpp>
#endif // #ifndef SPROUT_ALGORITHM_COPY_WHILE_HPP

View file

@ -52,6 +52,8 @@
#include <sprout/algorithm/fit/sort_heap.hpp>
#include <sprout/algorithm/fit/next_permutation.hpp>
#include <sprout/algorithm/fit/prev_permutation.hpp>
#include <sprout/algorithm/fit/copy_while.hpp>
#include <sprout/algorithm/fit/copy_until.hpp>
#include <sprout/algorithm/fit/clamp_range_copy.hpp>
#include <sprout/algorithm/fit/clamp_range.hpp>
#include <sprout/algorithm/fit/random_swap.hpp>

View file

@ -0,0 +1,44 @@
#ifndef SPROUT_ALGORITHM_FIT_COPY_UNTIL_HPP
#define SPROUT_ALGORITHM_FIT_COPY_UNTIL_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fixed/copy_until.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fit {
namespace detail {
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_until_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::copy_until(first, last, result, pred)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min(
NS_SSCRISK_CEL_OR_SPROUT::distance(first, NS_SSCRISK_CEL_OR_SPROUT::find_if(first, last, pred)),
sprout::size(result)
)
);
}
} // namespace detail
//
// copy_until
//
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_until(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
return sprout::fit::detail::copy_until_impl(first, last, result, pred, sprout::internal_begin_offset(result));
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_COPY_UNTIL_HPP

View file

@ -0,0 +1,44 @@
#ifndef SPROUT_ALGORITHM_FIT_COPY_WHILE_HPP
#define SPROUT_ALGORITHM_FIT_COPY_WHILE_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fixed/copy_while.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/sub_array.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fit {
namespace detail {
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_while_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::copy_while(first, last, result, pred)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min(
NS_SSCRISK_CEL_OR_SPROUT::distance(first, NS_SSCRISK_CEL_OR_SPROUT::find_if_not(first, last, pred)),
sprout::size(result)
)
);
}
} // namespace detail
//
// copy_while
//
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_while(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
return sprout::fit::detail::copy_while_impl(first, last, result, pred, sprout::internal_begin_offset(result));
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIT_COPY_WHILE_HPP

View file

@ -52,6 +52,8 @@
#include <sprout/algorithm/fixed/sort_heap.hpp>
#include <sprout/algorithm/fixed/next_permutation.hpp>
#include <sprout/algorithm/fixed/prev_permutation.hpp>
#include <sprout/algorithm/fixed/copy_while.hpp>
#include <sprout/algorithm/fixed/copy_until.hpp>
#include <sprout/algorithm/fixed/clamp_range_copy.hpp>
#include <sprout/algorithm/fixed/clamp_range.hpp>
#include <sprout/algorithm/fixed/swap_element.hpp>

View file

@ -0,0 +1,80 @@
#ifndef SPROUT_ALGORITHM_FIXED_COPY_UNTIL_HPP
#define SPROUT_ALGORITHM_FIXED_COPY_UNTIL_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy.hpp>
#include <sprout/detail/container_complate.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fixed {
namespace detail {
template<typename RandomAccessIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_until(
RandomAccessIterator first, RandomAccessIterator last, Result const& result, Predicate pred,
std::random_access_iterator_tag*
)
{
return sprout::fixed::copy(first, NS_SSCRISK_CEL_OR_SPROUT::find_if(first, last, pred), result);
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type
copy_until_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::size_type size,
Args const&... args
)
{
return sprout::remake<Result>(result, sprout::size(result), args...);
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type
copy_until_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::size_type size,
Args const&... args
)
{
return first != last && sizeof...(Args) < size && !pred(*first)
? sprout::fixed::detail::copy_until_impl(sprout::next(first), last, result, pred, size, args..., *first)
: sprout::detail::container_complate(result, args...)
;
}
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_until(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
void*
)
{
return sprout::fixed::detail::copy_until_impl(first, last, result, pred, sprout::size(result));
}
} // namespace detail
//
// copy_until
//
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_until(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
return sprout::fixed::detail::copy_until(first, last, result, pred, category());
}
} // namespace fixed
using sprout::fixed::copy_until;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_UNTIL_HPP

View file

@ -0,0 +1,80 @@
#ifndef SPROUT_ALGORITHM_FIXED_COPY_WHILE_HPP
#define SPROUT_ALGORITHM_FIXED_COPY_WHILE_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy.hpp>
#include <sprout/detail/container_complate.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace fixed {
namespace detail {
template<typename RandomAccessIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_while(
RandomAccessIterator first, RandomAccessIterator last, Result const& result, Predicate pred,
std::random_access_iterator_tag*
)
{
return sprout::fixed::copy(first, NS_SSCRISK_CEL_OR_SPROUT::find_if_not(first, last, pred), result);
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type
copy_while_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::size_type size,
Args const&... args
)
{
return sprout::remake<Result>(result, sprout::size(result), args...);
}
template<typename InputIterator, typename Result, typename Predicate, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size != sizeof...(Args),
typename sprout::fixed::result_of::algorithm<Result>::type
>::type
copy_while_impl(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
typename sprout::container_traits<Result>::size_type size,
Args const&... args
)
{
return first != last && sizeof...(Args) < size && pred(*first)
? sprout::fixed::detail::copy_while_impl(sprout::next(first), last, result, pred, size, args..., *first)
: sprout::detail::container_complate(result, args...)
;
}
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_while(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
void*
)
{
return sprout::fixed::detail::copy_while_impl(first, last, result, pred, sprout::size(result));
}
} // namespace detail
//
// copy_while
//
template<typename InputIterator, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_while(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
return sprout::fixed::detail::copy_while(first, last, result, pred, category());
}
} // namespace fixed
using sprout::fixed::copy_while;
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_WHILE_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP
#define SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP
#include <sprout/config.hpp>
#include <sprout/range/algorithm/fixed/copy_until.hpp>
#include <sprout/range/algorithm/fit/copy_until.hpp>
#endif // #ifndef SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP
#define SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP
#include <sprout/config.hpp>
#include <sprout/range/algorithm/fixed/copy_while.hpp>
#include <sprout/range/algorithm/fit/copy_while.hpp>
#endif // #ifndef SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP

View file

@ -20,6 +20,8 @@
#include <sprout/range/algorithm/fit/set_intersection.hpp>
#include <sprout/range/algorithm/fit/set_difference.hpp>
#include <sprout/range/algorithm/fit/set_symmetric_difference.hpp>
#include <sprout/range/algorithm/fit/copy_while.hpp>
#include <sprout/range/algorithm/fit/copy_until.hpp>
#include <sprout/range/algorithm/fit/clamp_range_copy.hpp>
#include <sprout/range/algorithm/fit/swap_element_copy.hpp>

View file

@ -0,0 +1,25 @@
#ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_UNTIL_HPP
#define SPROUT_RANGE_ALGORITHM_FIT_COPY_UNTIL_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/algorithm/fit/copy_until.hpp>
namespace sprout {
namespace range {
namespace fit {
//
// copy_until
//
template<typename Input, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_until(Input const& input, Result const& result, Predicate pred) {
return sprout::fit::copy_until(sprout::begin(input), sprout::end(input), result, pred);
}
} // namespace fit
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_UNTIL_HPP

View file

@ -0,0 +1,25 @@
#ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_WHILE_HPP
#define SPROUT_RANGE_ALGORITHM_FIT_COPY_WHILE_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fit/result_of.hpp>
#include <sprout/algorithm/fit/copy_while.hpp>
namespace sprout {
namespace range {
namespace fit {
//
// copy_while
//
template<typename Input, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Result>::type
copy_while(Input const& input, Result const& result, Predicate pred) {
return sprout::fit::copy_while(sprout::begin(input), sprout::end(input), result, pred);
}
} // namespace fit
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_WHILE_HPP

View file

@ -20,6 +20,8 @@
#include <sprout/range/algorithm/fixed/set_intersection.hpp>
#include <sprout/range/algorithm/fixed/set_difference.hpp>
#include <sprout/range/algorithm/fixed/set_symmetric_difference.hpp>
#include <sprout/range/algorithm/fixed/copy_while.hpp>
#include <sprout/range/algorithm/fixed/copy_until.hpp>
#include <sprout/range/algorithm/fixed/clamp_range_copy.hpp>
#include <sprout/range/algorithm/fixed/swap_element_copy.hpp>

View file

@ -0,0 +1,27 @@
#ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_UNTIL_HPP
#define SPROUT_RANGE_ALGORITHM_FIXED_COPY_UNTIL_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy_until.hpp>
namespace sprout {
namespace range {
namespace fixed {
//
// copy_until
//
template<typename Input, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_until(Input const& input, Result const& result, Predicate pred) {
return sprout::fixed::copy_until(sprout::begin(input), sprout::end(input), result);
}
} // namespace fixed
using sprout::range::fixed::copy_until;
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_UNTIL_HPP

View file

@ -0,0 +1,27 @@
#ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_WHILE_HPP
#define SPROUT_RANGE_ALGORITHM_FIXED_COPY_WHILE_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include <sprout/algorithm/fixed/copy_while.hpp>
namespace sprout {
namespace range {
namespace fixed {
//
// copy_while
//
template<typename Input, typename Result, typename Predicate>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_while(Input const& input, Result const& result, Predicate pred) {
return sprout::fixed::copy_while(sprout::begin(input), sprout::end(input), result);
}
} // namespace fixed
using sprout::range::fixed::copy_while;
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_WHILE_HPP