diff options
author | da-woods <dw-git@d-woods.co.uk> | 2021-07-18 21:41:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-18 22:41:20 +0200 |
commit | 78886392cd6a3c7edaf844c7b8224d67a4474266 (patch) | |
tree | f68984e3f52ca5e16fb644094ee8a4ceea41e6f0 | |
parent | 47850c4023b1e7a239ed597a84d7e7cd074d18ad (diff) | |
download | cython-78886392cd6a3c7edaf844c7b8224d67a4474266.tar.gz |
Add missing "max_element()" in libcpp.algorithms (GH-4271)
-rw-r--r-- | Cython/Includes/libcpp/algorithm.pxd | 2 | ||||
-rw-r--r-- | tests/run/cpp_stl_algo_modifying_sequence_ops.pyx | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Cython/Includes/libcpp/algorithm.pxd b/Cython/Includes/libcpp/algorithm.pxd index c3a6289eb..712ea1757 100644 --- a/Cython/Includes/libcpp/algorithm.pxd +++ b/Cython/Includes/libcpp/algorithm.pxd @@ -245,6 +245,8 @@ cdef extern from "<algorithm>" namespace "std" nogil: # Minimum/maximum operations Iter min_element[Iter](Iter first, Iter last) except + Iter min_element[ExecutionPolicy, Iter](ExecutionPolicy&& policy, Iter first, Iter last) except + + Iter max_element[Iter](Iter first, Iter last) except + + Iter max_element[ExecutionPolicy, Iter](ExecutionPolicy&& policy, Iter first, Iter last) except + # Comparison operations diff --git a/tests/run/cpp_stl_algo_modifying_sequence_ops.pyx b/tests/run/cpp_stl_algo_modifying_sequence_ops.pyx index 156a28a11..f842d430b 100644 --- a/tests/run/cpp_stl_algo_modifying_sequence_ops.pyx +++ b/tests/run/cpp_stl_algo_modifying_sequence_ops.pyx @@ -10,7 +10,7 @@ from libcpp.algorithm cimport copy, copy_if, copy_n, copy_backward, move, move_b from libcpp.algorithm cimport generate, generate_n, remove, remove_if, remove_copy, remove_copy_if, replace, replace_if from libcpp.algorithm cimport replace_copy, replace_copy_if, swap, swap_ranges, iter_swap, reverse, reverse_copy from libcpp.algorithm cimport rotate, rotate_copy, unique, unique_copy -from libcpp.algorithm cimport sort, upper_bound, min_element +from libcpp.algorithm cimport sort, upper_bound, min_element, max_element from libcpp.iterator cimport back_inserter from libcpp.string cimport string from libcpp.vector cimport vector @@ -316,17 +316,19 @@ def test_swap_ranges(): print(a, b) -def selection_sort(vector[int] values): +def selection_sort(vector[int] values, reversed=False): """ - Test iter_swap using cppreference example. + Test iter_swap using cppreference example. Extra "reversed argument tests max_element >>> selection_sort([-7, 6, 2, 4, -1, 6, -9, -1, 2, -5, 10, -9, -5, -3, -5, -3, 6, 6, 1, 8]) [-9, -9, -7, -5, -5, -5, -3, -3, -1, -1, 1, 2, 2, 4, 6, 6, 6, 6, 8, 10] + >>> selection_sort([-7, 6, 2, 4, -1, 6, -9, -1, 2, -5, 10, -9, -5, -3, -5, -3, 6, 6, 1, 8], reversed=True) + [10, 8, 6, 6, 6, 6, 4, 2, 2, 1, -1, -1, -3, -3, -5, -5, -5, -7, -9, -9] """ i = values.begin() end = values.end() while i < end: - iter_swap(i, min_element(i, end)) + iter_swap(i, min_element(i, end) if not reversed else max_element(i,end)) preincrement(i) return values |