fix recursion depth: some algorithms

This commit is contained in:
bolero-MURAKAMI 2013-01-11 02:55:19 +09:00
parent bb59363682
commit e2b207d3be
34 changed files with 796 additions and 87 deletions

View file

@ -44,6 +44,74 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::is_odd<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::less_than<int>(6)
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::begin(arr1) + 5),
testspr::is_odd<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::begin(arr1) + 5),
testspr::less_than<int>(6)
);
TESTSPR_BOTH_ASSERT(result);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::is_odd<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::less_than<int>(6)
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::is_odd<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::less_than<int>(6)
);
TESTSPR_BOTH_ASSERT(result);
}
#endif
}
}
} // namespace testspr

View file

@ -42,6 +42,72 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(result);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1))
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5)
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
#endif
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1))
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5)
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
#endif
}
}
} // namespace testspr

View file

@ -42,6 +42,70 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5)
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::less<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::less<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5)
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::less<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::less<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#endif
}
}
} // namespace testspr

View file

@ -28,6 +28,42 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::partition_point(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::is_odd<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::partition_point(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::is_odd<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::partition_point(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::is_odd<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::partition_point(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::is_odd<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#endif
}
}
} // namespace testspr

View file

@ -91,6 +91,164 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::reduct_forward(sprout::begin(arr2)),
testspr::reduct_forward(sprout::end(arr2))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::reduct_forward(sprout::begin(arr3)),
testspr::reduct_forward(sprout::end(arr3))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::reduct_forward(sprout::begin(arr2)),
testspr::reduct_forward(sprout::end(arr2))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::reduct_forward(sprout::begin(arr3)),
testspr::reduct_forward(sprout::end(arr3))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::reduct_forward(sprout::begin(arr2)),
testspr::reduct_forward(sprout::end(arr2)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
testspr::reduct_forward(sprout::begin(arr3)),
testspr::reduct_forward(sprout::end(arr3)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::reduct_forward(sprout::begin(arr2)),
testspr::reduct_forward(sprout::end(arr2)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
testspr::reduct_forward(sprout::begin(arr3)),
testspr::reduct_forward(sprout::end(arr3)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr3))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr3))
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr3)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr3)),
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#endif
}
}
} // namespace testspr

View file

@ -89,6 +89,164 @@ namespace testspr {
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
2,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
4,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
2,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
4,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
2,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::end(arr1)),
4,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
2,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_forward(sprout::begin(arr1)),
testspr::reduct_forward(sprout::begin(arr1) + 5),
4,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
2,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
4,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
2,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
4,
5
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
2,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
4,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
2,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::search_n(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::begin(arr1) + 5),
4,
5,
testspr::equal_to<int>()
).base();
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
#endif
}
}
} // namespace testspr

View file

@ -6,7 +6,7 @@
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
@ -61,23 +61,23 @@ namespace sprout {
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR ForwardIterator
adjacent_find_impl_check(sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> const& current) {
return !sprout::tuples::get<2>(current) ? sprout::tuples::get<1>(current)
: sprout::tuples::get<0>(current)
adjacent_find_impl_check(ForwardIterator found, ForwardIterator last) {
return sprout::next(found) == last ? last
: found
;
}
template<typename ForwardIterator, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
adjacent_find_impl_1(
sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> const& current,
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, BinaryPredicate pred, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> type;
return sprout::tuples::get<2>(current) || sprout::tuples::get<1>(current) == last ? current
: n == 1 ? pred(*sprout::tuples::get<0>(current), *sprout::tuples::get<1>(current))
? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
: type(sprout::tuples::get<1>(current), sprout::next(sprout::tuples::get<1>(current)), false)
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return current.second == last ? current
: n == 1 ? pred(*current.first, *current.second)
? type(current.first, last)
: type(current.second, sprout::next(current.second))
: sprout::detail::adjacent_find_impl_1(
sprout::detail::adjacent_find_impl_1(
current,
@ -88,14 +88,14 @@ namespace sprout {
;
}
template<typename ForwardIterator, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
adjacent_find_impl(
sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> const& current,
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, BinaryPredicate pred, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> type;
return sprout::tuples::get<2>(current) || sprout::tuples::get<1>(current) == last ? current
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return current.second == last ? current
: sprout::detail::adjacent_find_impl(
sprout::detail::adjacent_find_impl_1(
current,
@ -112,14 +112,15 @@ namespace sprout {
void*
)
{
typedef sprout::tuples::tuple<ForwardIterator, ForwardIterator, bool> type;
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return first == last ? last
: sprout::detail::adjacent_find_impl_check(
sprout::detail::adjacent_find_impl(type(first, sprout::next(first), false), last, pred, 1)
sprout::detail::adjacent_find_impl(type(first, sprout::next(first)), last, pred, 1).first,
last
)
;
}
} //namespace detail
} // namespace detail
// 25.2.8 Adjacent find
//

View file

@ -90,7 +90,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::all_of_impl(type(first, true), last, pred, 1).second;
}
} //namespace detail
} // namespace detail
// 25.2.1 All of
//

View file

@ -53,7 +53,7 @@ namespace sprout {
{
return sprout::detail::all_of_equal_impl(first, last, value);
}
} //namespace detail
} // namespace detail
//
// all_of_equal

View file

@ -90,7 +90,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::any_of_impl(type(first, false), last, pred, 1).second;
}
} //namespace detail
} // namespace detail
// 25.2.2 Any of
//

View file

@ -53,7 +53,7 @@ namespace sprout {
{
return sprout::detail::any_of_equal_impl(first, last, value);
}
} //namespace detail
} // namespace detail
//
// any_of_equal

View file

@ -90,7 +90,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return sprout::detail::count_impl(type(first, 0), last, value, 1).second;
}
} //namespace detail
} // namespace detail
// 25.2.9 Count
//

View file

@ -90,7 +90,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return sprout::detail::count_if_impl(type(first, 0), last, pred, 1).second;
}
} //namespace detail
} // namespace detail
// 25.2.9 Count
//

View file

@ -98,7 +98,7 @@ namespace sprout {
sprout::detail::equal_impl(type(first1, first2, true), last1, pred, 1)
);
}
} //namespace detail
} // namespace detail
// 25.2.11 Equal
//

View file

@ -92,7 +92,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::find_impl(type(first, false), last, value, 1).first;
}
} //namespace detail
} // namespace detail
// 25.2.5 Find
//

View file

@ -145,7 +145,7 @@ namespace sprout {
// 25.2.6 Find end
//
// recursion depth:
// O(log (N1+N2))
// O(log(N1+N2))
//
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR ForwardIterator1

View file

@ -108,12 +108,12 @@ namespace sprout {
typedef sprout::pair<InputIterator1, bool> type;
return sprout::detail::find_first_of_impl(type(first1, false), last1, first2, last2, pred, 1).first;
}
} //namespace detail
} // namespace detail
// 25.2.7 Find first
//
// recursion depth:
// O(log (N1+N2))
// O(log(N1+N2))
//
template<typename InputIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR InputIterator1

View file

@ -92,7 +92,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::find_if_impl(type(first, false), last, pred, 1).first;
}
} //namespace detail
} // namespace detail
// 25.2.5 Find
//

View file

@ -92,7 +92,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::find_if_not_impl(type(first, false), last, pred, 1).first;
}
} //namespace detail
} // namespace detail
// 25.2.5 Find
//

View file

@ -66,7 +66,7 @@ namespace sprout {
{
return sprout::detail::includes_impl(first1, last1, first2, comp);
}
} //namespace detail
} // namespace detail
// 25.4.5.1 includes
//

View file

@ -1,21 +1,101 @@
#ifndef SPROUT_ALGORITHM_IS_PARTITIONED_HPP
#define SPROUT_ALGORITHM_IS_PARTITIONED_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/algorithm/none_of.hpp>
#include <sprout/algorithm/find_if_not.hpp>
namespace sprout {
namespace detail {
template<typename RandomAccessIterator, typename Predicate>
inline SPROUT_CONSTEXPR bool
is_partitioned_impl_ra(RandomAccessIterator first, RandomAccessIterator last, Predicate pred) {
return first == last ? true
: sprout::none_of(sprout::next(first), last, pred)
;
}
template<typename RandomAccessIterator, typename Predicate>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::value,
bool
>::type
is_partitioned(
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
std::random_access_iterator_tag*
)
{
return sprout::detail::is_partitioned_impl_ra(
sprout::find_if_not(first, last, pred),
last, pred
);
}
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type>
is_partitioned_impl_1(
sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> const& current,
InputIterator last, Predicate pred, typename std::iterator_traits<InputIterator>::difference_type n
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return current.second > 1 || current.first == last ? current
: n == 1 ? current.second == 0
? type(sprout::next(current.first), pred(*current.first) ? 0 : 1)
: !pred(*current.first) ? type(sprout::next(current.first), 1) : type(current.first, 2)
: sprout::detail::is_partitioned_impl_1(
sprout::detail::is_partitioned_impl_1(
current,
last, pred, n / 2
),
last, pred, n - n / 2
)
;
}
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type>
is_partitioned_impl(
sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> const& current,
InputIterator last, Predicate pred, typename std::iterator_traits<InputIterator>::difference_type n
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return current.second > 1 || current.first == last ? current
: sprout::detail::is_partitioned_impl(
sprout::detail::is_partitioned_impl_1(
current,
last, pred, n
),
last, pred, n * 2
)
;
}
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR bool
is_partitioned(
InputIterator first, InputIterator last, Predicate pred,
void*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return sprout::detail::is_partitioned_impl(type(first, 0), last, pred, 1).second <= 1;
}
} // namespace detail
// 25.3.13 Partitions
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
// O(log N)
//
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR bool
is_partitioned(InputIterator first, InputIterator last, Predicate pred) {
return sprout::none_of(sprout::find_if_not(first, last, pred), last, pred);
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
return sprout::detail::is_partitioned(first, last, pred, category());
}
} // namespace sprout

View file

@ -2,8 +2,10 @@
#define SPROUT_ALGORITHM_IS_SORTED_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/algorithm/is_sorted_until.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
@ -28,7 +30,10 @@ namespace sprout {
;
}
template<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR bool
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::value,
bool
>::type
is_sorted(
RandomAccessIterator first, RandomAccessIterator last, Compare comp,
std::random_access_iterator_tag*
@ -52,13 +57,12 @@ namespace sprout {
{
return sprout::is_sorted_until(first, last, comp) == last;
}
} //namespace detail
} // namespace detail
// 25.4.1.5 is_sorted
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
// O(log N)
//
template<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR bool

View file

@ -2,8 +2,11 @@
#define SPROUT_ALGORITHM_IS_SORTED_UNTIL_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
@ -29,7 +32,10 @@ namespace sprout {
;
}
template<typename RandomAccessIterator, typename Compare>
inline SPROUT_CONSTEXPR RandomAccessIterator
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator>::value,
RandomAccessIterator
>::type
is_sorted_until(
RandomAccessIterator first, RandomAccessIterator last, Compare comp,
std::random_access_iterator_tag*
@ -45,13 +51,43 @@ namespace sprout {
;
}
// Copyright (C) 2011 RiSK (sscrisk)
template<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
is_sorted_until_impl(ForwardIterator first, ForwardIterator next, ForwardIterator last, Compare comp) {
return next == last ? last
: comp(*next, *first) ? first
: sprout::detail::is_sorted_until_impl(next, sprout::next(next), last, comp)
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
is_sorted_until_impl_1(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return current.second == last ? current
: n == 1 ? comp(*current.second, *current.first)
? type(current.first, last)
: type(current.second, sprout::next(current.second))
: sprout::detail::is_sorted_until_impl_1(
sprout::detail::is_sorted_until_impl_1(
current,
last, comp, n / 2
),
last, comp, n - n / 2
)
;
}
template<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
is_sorted_until_impl(
sprout::pair<ForwardIterator, ForwardIterator> const& current,
ForwardIterator last, Compare comp, typename std::iterator_traits<ForwardIterator>::difference_type n
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return current.second == last ? current
: sprout::detail::is_sorted_until_impl(
sprout::detail::is_sorted_until_impl_1(
current,
last, comp, n
),
last, comp, n * 2
)
;
}
template<typename ForwardIterator, typename Compare>
@ -61,17 +97,19 @@ namespace sprout {
void*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;
return first == last ? last
: sprout::detail::is_sorted_until_impl(first, sprout::next(first), last, comp)
: sprout::next(
sprout::detail::is_sorted_until_impl(type(first, sprout::next(first)), last, comp, 1).first
)
;
}
} //namespace detail
} // namespace detail
// 25.4.1.5 is_sorted
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
// O(log N)
//
template<typename ForwardIterator, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator

View file

@ -93,7 +93,7 @@ namespace sprout {
{
return sprout::detail::lexicographical_compare_impl(first1, last1, first2, last2, comp);
}
} //namespace detail
} // namespace detail
// 25.4.8 Lexicographical comparison
//

View file

@ -119,7 +119,7 @@ namespace sprout {
sprout::detail::mismatch_impl(type(first1, first2, false), last1, pred, 1)
);
}
} //namespace detail
} // namespace detail
// 25.2.10 Mismatch
//

View file

@ -90,7 +90,7 @@ namespace sprout {
typedef sprout::pair<InputIterator, bool> type;
return sprout::detail::none_of_impl(type(first, true), last, pred, 1).second;
}
} //namespace detail
} // namespace detail
// 25.2.3 None of
//

View file

@ -53,7 +53,7 @@ namespace sprout {
{
return sprout::detail::none_of_equal_impl(first, last, value);
}
} //namespace detail
} // namespace detail
//
// none_of_equal

View file

@ -1,10 +1,12 @@
#ifndef SPROUT_ALGORITHM_ONE_OF_HPP
#define SPROUT_ALGORITHM_ONE_OF_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/find_if.hpp>
#include <sprout/algorithm/none_of.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/utility/pair.hpp>
namespace sprout {
namespace detail {

View file

@ -14,7 +14,7 @@ namespace sprout {
return mid == last ? mid
: pred(*mid) ? sprout::detail::partition_point_impl(
sprout::next(mid), last, pred,
sprout::next(mid, 1 + sprout::distance(sprout::next(mid), last) / 2)
sprout::next(mid, 1 + (sprout::distance(mid, last) - 1) / 2)
)
: sprout::detail::partition_point_impl(
first, mid, pred,
@ -27,8 +27,7 @@ namespace sprout {
// 25.3.13 Partitions
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
// O(log N)
//
template<typename ForwardIterator, typename Predicate>
inline SPROUT_CONSTEXPR ForwardIterator

View file

@ -1,9 +1,13 @@
#ifndef SPROUT_ALGORITHM_SEARCH_HPP
#define SPROUT_ALGORITHM_SEARCH_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/type_traits/is_iterator.hpp>
#include <sprout/functional/equal_to.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/detail/algorithm/search_one.hpp>
namespace sprout {
@ -31,7 +35,10 @@ namespace sprout {
;
}
template<typename RandomAccessIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR RandomAccessIterator1
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator1>::value,
RandomAccessIterator1
>::type
search(
RandomAccessIterator1 first1, RandomAccessIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
@ -47,19 +54,53 @@ namespace sprout {
;
}
template<typename ForwardIterator1>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator1, bool>
search_impl_check(sprout::pair<ForwardIterator1, bool> const& current, ForwardIterator1 last1, ForwardIterator1 searched) {
typedef sprout::pair<ForwardIterator1, bool> type;
return searched == current.first || searched == last1 ? type(searched, true)
: type(sprout::next(current.first), false)
;
}
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR ForwardIterator1
search_impl(
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred,
ForwardIterator1 searched
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator1, bool>
search_impl_1(
sprout::pair<ForwardIterator1, bool> const& current,
ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred,
typename std::iterator_traits<ForwardIterator1>::difference_type n
)
{
return searched == first1 || searched == last1 ? searched
typedef sprout::pair<ForwardIterator1, bool> type;
return current.second || current.first == last1 ? current
: n == 1 ? sprout::detail::search_impl_check(
current, last1,
sprout::detail::search_one(current.first, last1, first2, last2, pred)
)
: sprout::detail::search_impl_1(
sprout::detail::search_impl_1(
current,
last1, first2, last2, pred, n / 2
),
last1, first2, last2, pred, n - n / 2
)
;
}
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator1, bool>
search_impl(
sprout::pair<ForwardIterator1, bool> const& current,
ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred,
typename std::iterator_traits<ForwardIterator1>::difference_type n
)
{
typedef sprout::pair<ForwardIterator1, bool> type;
return current.second || current.first == last1 ? current
: sprout::detail::search_impl(
sprout::next(first1), last1, first2, last2, pred,
sprout::detail::search_one(sprout::next(first1), last1, first2, last2, pred)
sprout::detail::search_impl_1(
current,
last1, first2, last2, pred, n
),
last1, first2, last2, pred, n * 2
)
;
}
@ -72,20 +113,15 @@ namespace sprout {
void*
)
{
return sprout::detail::search_impl(
first1, last1, first2, last2, pred,
sprout::detail::search_one(first1, last1, first2, last2, pred)
);
typedef sprout::pair<ForwardIterator1, bool> type;
return sprout::detail::search_impl(type(first1, false), last1, first2, last2, pred, 1).first;
}
} //namespace detail
} // namespace detail
// 25.2.13 Search
//
// recursion depth:
// [first1, last1) is RandomAccessIterator -> O(log N1)
// otherwise -> O(N1)
// [first2, last2) is RandomAccessIterator -> O(log N2)
// otherwise -> O(N2)
// O(log(N1+N2))
//
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR ForwardIterator1

View file

@ -1,6 +1,7 @@
#ifndef SPROUT_ALGORITHM_SEARCH_N_HPP
#define SPROUT_ALGORITHM_SEARCH_N_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/value_iterator.hpp>
@ -11,17 +12,15 @@ namespace sprout {
// 25.2.13 Search
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
// O(log(N1+N2))
//
template<typename ForwardIterator, typename Size, typename T, typename BinaryPredicate>
inline SPROUT_CONSTEXPR ForwardIterator
search_n(ForwardIterator first, ForwardIterator last, Size count, T const& value, BinaryPredicate pred) {
typedef sprout::value_iterator<T const&> iterator;
typedef typename iterator::difference_type difference_type;
return sprout::search(
first, last,
iterator(value, static_cast<difference_type>(count)), iterator(value, 0),
iterator(value, static_cast<typename std::iterator_traits<iterator>::difference_type>(count)), iterator(value, 0),
pred
);
}

View file

@ -96,7 +96,7 @@ namespace sprout {
{
return sprout::detail::tristate_lexicographical_compare_impl(first1, last1, first2, last2, comp);
}
} //namespace detail
} // namespace detail
//
// tristate_lexicographical_compare
@ -233,7 +233,7 @@ namespace sprout {
{
return sprout::detail::tristate_lexicographical_compare_2_impl(first1, last1, delim1, first2, last2, delim2, comp);
}
} //namespace detail
} // namespace detail
//
// tristate_lexicographical_compare

View file

@ -98,7 +98,7 @@ namespace sprout {
// search_one
//
// recursion depth:
// O(log (N1+N2))
// O(log(N1+N2))
//
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR ForwardIterator1
@ -111,7 +111,7 @@ namespace sprout {
search_one(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2) {
return sprout::detail::search_one(first1, last1, first2, last2, sprout::equal_to<>());
}
} //namespace detail
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_DETAIL_ALGORITHM_SEARCH_ONE_HPP

View file

@ -286,6 +286,6 @@ namespace sprout {
return sprout::to_hash(v);
}
};
} //namespace sprout
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_HPP