mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix recursion depth: all_of, any_of, none_of, one_of, find, find_if, find_if_not
This commit is contained in:
parent
74729ce14f
commit
54400ea7d0
16 changed files with 757 additions and 29 deletions
|
@ -6,6 +6,7 @@
|
|||
# define TESTSPR_CPP_INCLUDE
|
||||
#endif
|
||||
|
||||
#include "./non_modifying.cpp"
|
||||
#include "./modifying.cpp"
|
||||
|
||||
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_ALGORITHM_CPP
|
||||
|
@ -14,6 +15,7 @@
|
|||
|
||||
namespace testspr {
|
||||
static void algorithm_test() {
|
||||
testspr::algorithm_non_modifying_test();
|
||||
testspr::algorithm_modifying_test();
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
56
libs/algorithm/test/all_of.cpp
Normal file
56
libs/algorithm/test/all_of.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_ALL_OF_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_ALL_OF_CPP
|
||||
|
||||
#include <sprout/algorithm/all_of.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_all_of_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 result = sprout::all_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less_than<int>(11)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::all_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::all_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less_than<int>(11)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::all_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_all_of_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_ALL_OF_CPP
|
56
libs/algorithm/test/any_of.cpp
Normal file
56
libs/algorithm/test/any_of.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_ANY_OF_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_ANY_OF_CPP
|
||||
|
||||
#include <sprout/algorithm/any_of.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_any_of_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 result = sprout::any_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::any_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::any_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::any_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_any_of_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_ANY_OF_CPP
|
56
libs/algorithm/test/find.cpp
Normal file
56
libs/algorithm/test/find.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_FIND_CPP
|
||||
|
||||
#include <sprout/algorithm/find.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_find_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 found = sprout::find(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
8
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 7);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
11
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
8
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
11
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_find_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_CPP
|
56
libs/algorithm/test/find_if.cpp
Normal file
56
libs/algorithm/test/find_if.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_CPP
|
||||
|
||||
#include <sprout/algorithm/find_if.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_find_if_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 found = sprout::find_if(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(7)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 7);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(7)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_find_if_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_CPP
|
56
libs/algorithm/test/find_if_not.cpp
Normal file
56
libs/algorithm/test/find_if_not.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_NOT_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_NOT_CPP
|
||||
|
||||
#include <sprout/algorithm/find_if_not.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_find_if_not_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 found = sprout::find_if_not(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less_than<int>(8)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 7);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if_not(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less_than<int>(11)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::end(arr1));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if_not(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less_than<int>(8)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_if_not(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less_than<int>(11)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_find_if_not_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_FIND_IF_NOT_CPP
|
38
libs/algorithm/test/non_modifying.cpp
Normal file
38
libs/algorithm/test/non_modifying.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||
# define TESTSPR_CPP_INCLUDE
|
||||
#endif
|
||||
|
||||
#include "./all_of.cpp"
|
||||
#include "./any_of.cpp"
|
||||
#include "./none_of.cpp"
|
||||
#include "./one_of.cpp"
|
||||
#include "./find.cpp"
|
||||
#include "./find_if.cpp"
|
||||
#include "./find_if_not.cpp"
|
||||
|
||||
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||
# undef TESTSPR_CPP_INCLUDE
|
||||
#endif
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_non_modifying_test() {
|
||||
testspr::algorithm_all_of_test();
|
||||
testspr::algorithm_any_of_test();
|
||||
testspr::algorithm_none_of_test();
|
||||
testspr::algorithm_one_of_test();
|
||||
testspr::algorithm_find_test();
|
||||
testspr::algorithm_find_if_test();
|
||||
testspr::algorithm_find_if_not_test();
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_non_modifying_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
56
libs/algorithm/test/none_of.cpp
Normal file
56
libs/algorithm/test/none_of.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_NONE_OF_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_NONE_OF_CPP
|
||||
|
||||
#include <sprout/algorithm/none_of.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_none_of_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 result = sprout::none_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::none_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::none_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(5)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::none_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(10)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_none_of_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_NONE_OF_CPP
|
56
libs/algorithm/test/one_of.cpp
Normal file
56
libs/algorithm/test/one_of.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_ONE_OF_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_ONE_OF_CPP
|
||||
|
||||
#include <sprout/algorithm/one_of.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_one_of_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 result = sprout::one_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::one_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::greater_than<int>(9)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::one_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(4)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::one_of(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::greater_than<int>(9)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_one_of_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_ONE_OF_CPP
|
|
@ -1,19 +1,68 @@
|
|||
#ifndef SPROUT_ALGORITHM_ALL_OF_HPP
|
||||
#define SPROUT_ALGORITHM_ALL_OF_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
all_of_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? pred(*first)
|
||||
: sprout::detail::all_of_impl_ra(
|
||||
first, sprout::next(first, pivot), pred,
|
||||
pivot / 2
|
||||
)
|
||||
&& sprout::detail::all_of_impl_ra(
|
||||
sprout::next(first, pivot), last, pred,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
all_of(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? true
|
||||
: sprout::detail::all_of_impl_ra(first, last, pred, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
all_of_impl(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? true
|
||||
: pred(*first) && sprout::detail::all_of_impl(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
all_of(
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::all_of_impl(first, last, pred);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.1 All of
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
all_of(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? true
|
||||
: pred(*first) && sprout::all_of(sprout::next(first), last, pred)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::all_of(first, last, pred, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,19 +1,68 @@
|
|||
#ifndef SPROUT_ALGORITHM_ANY_OF_HPP
|
||||
#define SPROUT_ALGORITHM_ANY_OF_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
any_of_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? pred(*first)
|
||||
: sprout::detail::any_of_impl_ra(
|
||||
first, sprout::next(first, pivot), pred,
|
||||
pivot / 2
|
||||
)
|
||||
|| sprout::detail::any_of_impl_ra(
|
||||
sprout::next(first, pivot), last, pred,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
any_of(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? false
|
||||
: sprout::detail::any_of_impl_ra(first, last, pred, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
any_of_impl(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? false
|
||||
: pred(*first) || sprout::detail::any_of_impl(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
any_of(
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::any_of_impl(first, last, pred);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.2 Any of
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
any_of(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? false
|
||||
: pred(*first) || sprout::any_of(sprout::next(first), last, pred)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::any_of(first, last, pred, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,19 +1,70 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, T const& value,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot, RandomAccessIterator found
|
||||
)
|
||||
{
|
||||
return found != first ? found
|
||||
: pivot == 0 ? (*first == value ? first : last)
|
||||
: sprout::detail::find_impl_ra(
|
||||
sprout::next(first, pivot), last, value,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2,
|
||||
sprout::detail::find_impl_ra(
|
||||
first, sprout::next(first, pivot), value,
|
||||
pivot / 2,
|
||||
first
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find(
|
||||
RandomAccessIterator first, RandomAccessIterator last, T const& value,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? first
|
||||
: sprout::detail::find_impl_ra(first, last, value, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, first)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_impl(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last || *first == value ? first
|
||||
: sprout::detail::find_impl(sprout::next(first), last, value)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find(
|
||||
InputIterator first, InputIterator last, T const& value,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_impl(first, last, value);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.5 Find
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last || *first == value ? first
|
||||
: sprout::find(sprout::next(first), last, value)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::find(first, last, value, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,19 +1,70 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_IF_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_IF_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find_if_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot, RandomAccessIterator found
|
||||
)
|
||||
{
|
||||
return found != first ? found
|
||||
: pivot == 0 ? (pred(*first) ? first : last)
|
||||
: sprout::detail::find_if_impl_ra(
|
||||
sprout::next(first, pivot), last, pred,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2,
|
||||
sprout::detail::find_if_impl_ra(
|
||||
first, sprout::next(first, pivot), pred,
|
||||
pivot / 2,
|
||||
first
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find_if(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? first
|
||||
: sprout::detail::find_if_impl_ra(first, last, pred, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, first)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if_impl(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last || pred(*first) ? first
|
||||
: sprout::detail::find_if_impl(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if(
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_if_impl(first, last, pred);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.5 Find
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last || pred(*first) ? first
|
||||
: sprout::find_if(sprout::next(first), last, pred)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::find_if(first, last, pred, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,19 +1,70 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_IF_NOT_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_IF_NOT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find_if_not_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot, RandomAccessIterator found
|
||||
)
|
||||
{
|
||||
return found != first ? found
|
||||
: pivot == 0 ? (!pred(*first) ? first : last)
|
||||
: sprout::detail::find_if_not_impl_ra(
|
||||
sprout::next(first, pivot), last, pred,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2,
|
||||
sprout::detail::find_if_not_impl_ra(
|
||||
first, sprout::next(first, pivot), pred,
|
||||
pivot / 2,
|
||||
first
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR RandomAccessIterator
|
||||
find_if_not(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? first
|
||||
: sprout::detail::find_if_not_impl_ra(first, last, pred, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, first)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if_not_impl(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last || !pred(*first) ? first
|
||||
: sprout::detail::find_if_not_impl(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if_not(
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_if_not_impl(first, last, pred);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.5 Find
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_if_not(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last || !pred(*first) ? first
|
||||
: sprout::find_if_not(sprout::next(first), last, pred)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::find_if_not(first, last, pred, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -5,15 +5,62 @@
|
|||
#include <sprout/iterator/operation.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
none_of_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? !pred(*first)
|
||||
: sprout::detail::none_of_impl_ra(
|
||||
first, sprout::next(first, pivot), pred,
|
||||
pivot / 2
|
||||
)
|
||||
&& sprout::detail::none_of_impl_ra(
|
||||
sprout::next(first, pivot), last, pred,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
none_of(
|
||||
RandomAccessIterator first, RandomAccessIterator last, Predicate pred,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? true
|
||||
: sprout::detail::none_of_impl_ra(first, last, pred, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2)
|
||||
;
|
||||
}
|
||||
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
none_of_impl(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? true
|
||||
: !pred(*first) && sprout::detail::none_of_impl(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
none_of(
|
||||
InputIterator first, InputIterator last, Predicate pred,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::detail::none_of_impl(first, last, pred);
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
// 25.2.3 None of
|
||||
template <typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
none_of(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return first == last ? true
|
||||
: !pred(*first) && sprout::none_of(sprout::next(first), last, pred)
|
||||
;
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::none_of(first, last, pred, category());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/find_if.hpp>
|
||||
#include <sprout/algorithm/none_of.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -11,7 +12,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR bool
|
||||
one_of_impl(InputIterator found, InputIterator last, Predicate pred) {
|
||||
return found != last
|
||||
&& NS_SSCRISK_CEL_OR_SPROUT::none_of(sprout::next(found), last, pred)
|
||||
&& sprout::none_of(sprout::next(found), last, pred)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
@ -21,10 +22,7 @@ namespace sprout {
|
|||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
one_of(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return sprout::detail::one_of_impl(
|
||||
sprout::find_if(first, last, pred), last,
|
||||
pred
|
||||
);
|
||||
return sprout::detail::one_of_impl(sprout::find_if(first, last, pred), last, pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
Loading…
Reference in a new issue