mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add algorithm copy_while, copy_until
This commit is contained in:
parent
f53be1a3d5
commit
9b9956f810
20 changed files with 649 additions and 0 deletions
112
libs/algorithm/test/copy_until.cpp
Normal file
112
libs/algorithm/test/copy_until.cpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP
|
||||
|
||||
#include <sprout/algorithm/copy_until.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_copy_until_test() {
|
||||
using namespace sprout;
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
|
||||
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
|
||||
|
||||
// 6 未満をコピー
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr2,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 10>{{1, 2, 3, 4, 5, 0, 0, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr2,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 5>{{1, 2, 3, 4, 5}}
|
||||
));
|
||||
}
|
||||
// 8 未満をコピー
|
||||
// 出力範囲をオーバーする場合
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr3,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr3,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
}
|
||||
// 8 未満をコピー
|
||||
// 出力範囲の切り出し
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
sprout::sub(arr2, 2, 8),
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 6>{{1, 2, 3, 4, 5, 0}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(copied),
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
sprout::sub(arr2, 2, 8),
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 5>{{1, 2, 3, 4, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(copied),
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_copy_until_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP
|
112
libs/algorithm/test/copy_while.cpp
Normal file
112
libs/algorithm/test/copy_while.cpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP
|
||||
|
||||
#include <sprout/algorithm/copy_while.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_copy_while_test() {
|
||||
using namespace sprout;
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
|
||||
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
|
||||
|
||||
// 6 未満をコピー
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr2,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 10>{{1, 2, 3, 4, 5, 0, 0, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr2,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 5>{{1, 2, 3, 4, 5}}
|
||||
));
|
||||
}
|
||||
// 8 未満をコピー
|
||||
// 出力範囲をオーバーする場合
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr3,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
arr3,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
}
|
||||
// 8 未満をコピー
|
||||
// 出力範囲の切り出し
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
sprout::sub(arr2, 2, 8),
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 6>{{1, 2, 3, 4, 5, 0}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(copied),
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_while(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
sprout::sub(arr2, 2, 8),
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
copied,
|
||||
array<int, 5>{{1, 2, 3, 4, 5}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(copied),
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_copy_while_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP
|
|
@ -56,6 +56,8 @@
|
|||
#include "./sort_heap.cpp"
|
||||
#include "./next_permutation.cpp"
|
||||
#include "./prev_permutation.cpp"
|
||||
#include "./copy_while.cpp"
|
||||
#include "./copy_until.cpp"
|
||||
#include "./clamp_range_copy.cpp"
|
||||
#include "./clamp_range.cpp"
|
||||
#include "./swap_element.cpp"
|
||||
|
@ -123,6 +125,8 @@ namespace testspr {
|
|||
testspr::algorithm_sort_heap_test();
|
||||
testspr::algorithm_next_permutation_test();
|
||||
testspr::algorithm_prev_permutation_test();
|
||||
testspr::algorithm_copy_while_test();
|
||||
testspr::algorithm_copy_until_test();
|
||||
testspr::algorithm_clamp_range_copy_test();
|
||||
testspr::algorithm_clamp_range_test();
|
||||
testspr::algorithm_swap_element_test();
|
||||
|
|
8
sprout/algorithm/copy_until.hpp
Normal file
8
sprout/algorithm/copy_until.hpp
Normal 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
|
8
sprout/algorithm/copy_while.hpp
Normal file
8
sprout/algorithm/copy_while.hpp
Normal 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
|
|
@ -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>
|
||||
|
|
44
sprout/algorithm/fit/copy_until.hpp
Normal file
44
sprout/algorithm/fit/copy_until.hpp
Normal 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
|
44
sprout/algorithm/fit/copy_while.hpp
Normal file
44
sprout/algorithm/fit/copy_while.hpp
Normal 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
|
|
@ -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>
|
||||
|
|
80
sprout/algorithm/fixed/copy_until.hpp
Normal file
80
sprout/algorithm/fixed/copy_until.hpp
Normal 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
|
80
sprout/algorithm/fixed/copy_while.hpp
Normal file
80
sprout/algorithm/fixed/copy_while.hpp
Normal 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
|
8
sprout/range/algorithm/copy_until.hpp
Normal file
8
sprout/range/algorithm/copy_until.hpp
Normal 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
|
8
sprout/range/algorithm/copy_while.hpp
Normal file
8
sprout/range/algorithm/copy_while.hpp
Normal 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
|
|
@ -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>
|
||||
|
||||
|
|
25
sprout/range/algorithm/fit/copy_until.hpp
Normal file
25
sprout/range/algorithm/fit/copy_until.hpp
Normal 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
|
25
sprout/range/algorithm/fit/copy_while.hpp
Normal file
25
sprout/range/algorithm/fit/copy_while.hpp
Normal 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
|
|
@ -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>
|
||||
|
||||
|
|
27
sprout/range/algorithm/fixed/copy_until.hpp
Normal file
27
sprout/range/algorithm/fixed/copy_until.hpp
Normal 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
|
27
sprout/range/algorithm/fixed/copy_while.hpp
Normal file
27
sprout/range/algorithm/fixed/copy_while.hpp
Normal 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
|
|
@ -129,6 +129,35 @@ namespace testspr {
|
|||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; }
|
||||
};
|
||||
|
||||
//
|
||||
// less_than
|
||||
//
|
||||
template<typename T>
|
||||
struct less_than {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
T value;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR less_than(T const& value) : value(value) {}
|
||||
SPROUT_CONSTEXPR bool operator()(T const& x) const { return x < value; }
|
||||
};
|
||||
//
|
||||
// greater_than
|
||||
//
|
||||
template<typename T>
|
||||
struct greater_than {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
T value;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR greater_than(T const& value) : value(value) {}
|
||||
SPROUT_CONSTEXPR bool operator()(T const& x) const { return x > value; }
|
||||
};
|
||||
|
||||
//
|
||||
// x2
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue