diff --git a/libs/algorithm/test/binary_search.cpp b/libs/algorithm/test/binary_search.cpp index 5a7176c9..c7ec0b1e 100644 --- a/libs/algorithm/test/binary_search.cpp +++ b/libs/algorithm/test/binary_search.cpp @@ -29,6 +29,46 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(!result); } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + 7 + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + 7, + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + 7 + ); + TESTSPR_BOTH_ASSERT(result); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + 7, + testspr::less() + ); + TESTSPR_BOTH_ASSERT(!result); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/equal_range.cpp b/libs/algorithm/test/equal_range.cpp index 2b659b07..5c413ade 100644 --- a/libs/algorithm/test/equal_range.cpp +++ b/libs/algorithm/test/equal_range.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace testspr { @@ -20,7 +21,7 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 6); TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr1) + 9); - TESTSPR_BOTH_ASSERT(found.second - found.first == 3); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first, found.second) == 3); } { SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range( @@ -31,8 +32,54 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5); TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr1) + 5); - TESTSPR_BOTH_ASSERT(found.second - found.first == 0); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first, found.second) == 0); } + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + 7 + ); + TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 6); + TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 3); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + 7, + testspr::less() + ); + TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5); + TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 5); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 0); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + 7 + ); + TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 6); + TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 9); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 3); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + 7, + testspr::less() + ); + TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5); + TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 5); + TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 0); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/lower_bound.cpp b/libs/algorithm/test/lower_bound.cpp index 5442d142..7130d33c 100644 --- a/libs/algorithm/test/lower_bound.cpp +++ b/libs/algorithm/test/lower_bound.cpp @@ -29,6 +29,44 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); } + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + 7 + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 6); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + 7, + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + 7 + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 6); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + 7, + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } +#endif } } } // namespace testspr diff --git a/libs/algorithm/test/upper_bound.cpp b/libs/algorithm/test/upper_bound.cpp index 8f846bd3..fab9dd17 100644 --- a/libs/algorithm/test/upper_bound.cpp +++ b/libs/algorithm/test/upper_bound.cpp @@ -29,6 +29,44 @@ namespace testspr { ); TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); } + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::end(arr1)), + 7 + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound( + testspr::reduct_forward(sprout::begin(arr1)), + testspr::reduct_forward(sprout::begin(arr1) + 5), + 7, + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } + +#if defined(__clang__) + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::end(arr1)), + 7 + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 9); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound( + testspr::reduct_random_access(sprout::begin(arr1)), + testspr::reduct_random_access(sprout::begin(arr1) + 5), + 7, + testspr::less() + ).base(); + TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5); + } +#endif } } } // namespace testspr diff --git a/sprout/algorithm/binary_search.hpp b/sprout/algorithm/binary_search.hpp index 45f1add6..39ef394e 100644 --- a/sprout/algorithm/binary_search.hpp +++ b/sprout/algorithm/binary_search.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_ALGORITHM_BINARY_SEARCH_HPP #define SPROUT_ALGORITHM_BINARY_SEARCH_HPP +#include #include #include #include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT @@ -17,8 +18,7 @@ namespace sprout { // 25.4.3.4 binary_search // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR bool diff --git a/sprout/algorithm/equal_range.hpp b/sprout/algorithm/equal_range.hpp index bd79726d..0705b554 100644 --- a/sprout/algorithm/equal_range.hpp +++ b/sprout/algorithm/equal_range.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_ALGORITHM_EQUAL_RANGE_HPP #define SPROUT_ALGORITHM_EQUAL_RANGE_HPP +#include #include #include #include @@ -13,13 +14,15 @@ namespace sprout { // 25.4.3.3 equal_range // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template - inline SPROUT_CONSTEXPR pair + inline SPROUT_CONSTEXPR sprout::pair equal_range(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) { - return {sprout::lower_bound(first, last, value, comp), sprout::upper_bound(first, last, value, comp)}; + return sprout::pair{ + sprout::lower_bound(first, last, value, comp), + sprout::upper_bound(first, last, value, comp) + }; } template diff --git a/sprout/algorithm/lower_bound.hpp b/sprout/algorithm/lower_bound.hpp index 06e50661..974bca39 100644 --- a/sprout/algorithm/lower_bound.hpp +++ b/sprout/algorithm/lower_bound.hpp @@ -12,8 +12,7 @@ namespace sprout { // 25.4.3.1 lower_bound // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR ForwardIterator diff --git a/sprout/algorithm/upper_bound.hpp b/sprout/algorithm/upper_bound.hpp index e1331629..051f4708 100644 --- a/sprout/algorithm/upper_bound.hpp +++ b/sprout/algorithm/upper_bound.hpp @@ -12,8 +12,7 @@ namespace sprout { // 25.4.3.2 upper_bound // // recursion depth: - // [first, last) is RandomAccessIterator -> O(log N) - // otherwise -> O(N) + // O(log N) // template inline SPROUT_CONSTEXPR ForwardIterator