diff --git a/libs/algorithm/test/copy_until.cpp b/libs/algorithm/test/copy_until.cpp new file mode 100644 index 00000000..e90bc1b7 --- /dev/null +++ b/libs/algorithm/test/copy_until.cpp @@ -0,0 +1,112 @@ +#ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP +#define SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_until_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 6 未満をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_until( + sprout::begin(arr1), + sprout::end(arr1), + arr2, + testspr::greater_than(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{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(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5}} + )); + } + // 8 未満をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_until( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::greater_than(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_until( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::greater_than(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{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(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5, 0}} + )); + TESTSPR_BOTH_ASSERT(testspr::equal( + sprout::get_internal(copied), + array{{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(5) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5}} + )); + TESTSPR_BOTH_ASSERT(testspr::equal( + sprout::get_internal(copied), + array{{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 +#endif + +#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_UNTIL_CPP diff --git a/libs/algorithm/test/copy_while.cpp b/libs/algorithm/test/copy_while.cpp new file mode 100644 index 00000000..85c4bce0 --- /dev/null +++ b/libs/algorithm/test/copy_while.cpp @@ -0,0 +1,112 @@ +#ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP +#define SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_while_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 6 未満をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_while( + sprout::begin(arr1), + sprout::end(arr1), + arr2, + testspr::less_than(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{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(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5}} + )); + } + // 8 未満をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_while( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::less_than(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_while( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::less_than(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{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(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5, 0}} + )); + TESTSPR_BOTH_ASSERT(testspr::equal( + sprout::get_internal(copied), + array{{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(6) + ); + TESTSPR_BOTH_ASSERT(testspr::equal( + copied, + array{{1, 2, 3, 4, 5}} + )); + TESTSPR_BOTH_ASSERT(testspr::equal( + sprout::get_internal(copied), + array{{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 +#endif + +#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_COPY_WHILE_CPP diff --git a/libs/algorithm/test/modifying.cpp b/libs/algorithm/test/modifying.cpp index e7d703e6..de05297c 100644 --- a/libs/algorithm/test/modifying.cpp +++ b/libs/algorithm/test/modifying.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(); diff --git a/sprout/algorithm/copy_until.hpp b/sprout/algorithm/copy_until.hpp new file mode 100644 index 00000000..4e113959 --- /dev/null +++ b/sprout/algorithm/copy_until.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_ALGORITHM_COPY_UNTIL_HPP +#define SPROUT_ALGORITHM_COPY_UNTIL_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_ALGORITHM_COPY_UNTIL_HPP diff --git a/sprout/algorithm/copy_while.hpp b/sprout/algorithm/copy_while.hpp new file mode 100644 index 00000000..f243a196 --- /dev/null +++ b/sprout/algorithm/copy_while.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_ALGORITHM_COPY_WHILE_HPP +#define SPROUT_ALGORITHM_COPY_WHILE_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_ALGORITHM_COPY_WHILE_HPP diff --git a/sprout/algorithm/fit.hpp b/sprout/algorithm/fit.hpp index 2a2a83f1..2450e0d0 100644 --- a/sprout/algorithm/fit.hpp +++ b/sprout/algorithm/fit.hpp @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/sprout/algorithm/fit/copy_until.hpp b/sprout/algorithm/fit/copy_until.hpp new file mode 100644 index 00000000..950167ce --- /dev/null +++ b/sprout/algorithm/fit/copy_until.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_ALGORITHM_FIT_COPY_UNTIL_HPP +#define SPROUT_ALGORITHM_FIT_COPY_UNTIL_HPP + +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type + copy_until_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::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 + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::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 diff --git a/sprout/algorithm/fit/copy_while.hpp b/sprout/algorithm/fit/copy_while.hpp new file mode 100644 index 00000000..fc66186e --- /dev/null +++ b/sprout/algorithm/fit/copy_while.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_ALGORITHM_FIT_COPY_WHILE_HPP +#define SPROUT_ALGORITHM_FIT_COPY_WHILE_HPP + +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::type + copy_while_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::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 + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::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 diff --git a/sprout/algorithm/fixed.hpp b/sprout/algorithm/fixed.hpp index 30d0dde1..1f876455 100644 --- a/sprout/algorithm/fixed.hpp +++ b/sprout/algorithm/fixed.hpp @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/sprout/algorithm/fixed/copy_until.hpp b/sprout/algorithm/fixed/copy_until.hpp new file mode 100644 index 00000000..a3d3a1f1 --- /dev/null +++ b/sprout/algorithm/fixed/copy_until.hpp @@ -0,0 +1,80 @@ +#ifndef SPROUT_ALGORITHM_FIXED_COPY_UNTIL_HPP +#define SPROUT_ALGORITHM_FIXED_COPY_UNTIL_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fixed { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type + copy_until_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::size_type size, + Args const&... args + ) + { + return sprout::remake(result, sprout::size(result), args...); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size != sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type + copy_until_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::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 + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + copy_until(InputIterator first, InputIterator last, Result const& result, Predicate pred) { + typedef typename std::iterator_traits::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 diff --git a/sprout/algorithm/fixed/copy_while.hpp b/sprout/algorithm/fixed/copy_while.hpp new file mode 100644 index 00000000..f595d3cf --- /dev/null +++ b/sprout/algorithm/fixed/copy_while.hpp @@ -0,0 +1,80 @@ +#ifndef SPROUT_ALGORITHM_FIXED_COPY_WHILE_HPP +#define SPROUT_ALGORITHM_FIXED_COPY_WHILE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + namespace fixed { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type + copy_while_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::size_type size, + Args const&... args + ) + { + return sprout::remake(result, sprout::size(result), args...); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size != sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type + copy_while_impl( + InputIterator first, InputIterator last, Result const& result, Predicate pred, + typename sprout::container_traits::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 + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type + copy_while(InputIterator first, InputIterator last, Result const& result, Predicate pred) { + typedef typename std::iterator_traits::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 diff --git a/sprout/range/algorithm/copy_until.hpp b/sprout/range/algorithm/copy_until.hpp new file mode 100644 index 00000000..d4395a25 --- /dev/null +++ b/sprout/range/algorithm/copy_until.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP +#define SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_COPY_UNTIL_HPP diff --git a/sprout/range/algorithm/copy_while.hpp b/sprout/range/algorithm/copy_while.hpp new file mode 100644 index 00000000..ce3518d6 --- /dev/null +++ b/sprout/range/algorithm/copy_while.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP +#define SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_COPY_WHILE_HPP diff --git a/sprout/range/algorithm/fit.hpp b/sprout/range/algorithm/fit.hpp index 39bd5a72..0c361619 100644 --- a/sprout/range/algorithm/fit.hpp +++ b/sprout/range/algorithm/fit.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include diff --git a/sprout/range/algorithm/fit/copy_until.hpp b/sprout/range/algorithm/fit/copy_until.hpp new file mode 100644 index 00000000..03444fb4 --- /dev/null +++ b/sprout/range/algorithm/fit/copy_until.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_UNTIL_HPP +#define SPROUT_RANGE_ALGORITHM_FIT_COPY_UNTIL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fit { + // + // copy_until + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::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 diff --git a/sprout/range/algorithm/fit/copy_while.hpp b/sprout/range/algorithm/fit/copy_while.hpp new file mode 100644 index 00000000..58d6b814 --- /dev/null +++ b/sprout/range/algorithm/fit/copy_while.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIT_COPY_WHILE_HPP +#define SPROUT_RANGE_ALGORITHM_FIT_COPY_WHILE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fit { + // + // copy_while + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm::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 diff --git a/sprout/range/algorithm/fixed.hpp b/sprout/range/algorithm/fixed.hpp index dbda6ff9..6be80fca 100644 --- a/sprout/range/algorithm/fixed.hpp +++ b/sprout/range/algorithm/fixed.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include diff --git a/sprout/range/algorithm/fixed/copy_until.hpp b/sprout/range/algorithm/fixed/copy_until.hpp new file mode 100644 index 00000000..f7e59c27 --- /dev/null +++ b/sprout/range/algorithm/fixed/copy_until.hpp @@ -0,0 +1,27 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_UNTIL_HPP +#define SPROUT_RANGE_ALGORITHM_FIXED_COPY_UNTIL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fixed { + // + // copy_until + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 diff --git a/sprout/range/algorithm/fixed/copy_while.hpp b/sprout/range/algorithm/fixed/copy_while.hpp new file mode 100644 index 00000000..373d0eeb --- /dev/null +++ b/sprout/range/algorithm/fixed/copy_while.hpp @@ -0,0 +1,27 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIXED_COPY_WHILE_HPP +#define SPROUT_RANGE_ALGORITHM_FIXED_COPY_WHILE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fixed { + // + // copy_while + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::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 diff --git a/testspr/tools.hpp b/testspr/tools.hpp index 98a960cd..e6e71663 100644 --- a/testspr/tools.hpp +++ b/testspr/tools.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 + 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 + 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 //