mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 12:01:39 +02:00
Compare commits
7 Commits
boost-1.69
...
boost-1.69
Author | SHA1 | Date | |
---|---|---|---|
5af3e3b174 | |||
1cbe285841 | |||
b6c04d6dc5 | |||
bf2b49e57e | |||
01b0dd8648 | |||
6763d75683 | |||
435cc61af8 |
@ -28,7 +28,7 @@ the use of `std::find()`:
|
||||
|
||||
auto rfirst = std::make_reverse_iterator(last);
|
||||
auto rlast = std::make_reverse_iterator(first);
|
||||
auto it = std::find(rfirst, rlast);
|
||||
auto it = std::find(rfirst, rlast, x);
|
||||
// Use it here...
|
||||
|
||||
That seems nicer in that there is no raw loop, but it has two major drawbacks.
|
||||
|
@ -15,19 +15,19 @@ equal to the given value.
|
||||
|
||||
Consider this use of `find()`:
|
||||
|
||||
auto std::vector<int> vec = { 1, 1, 2 };
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = std::find(vec.begin(), vec.end(), 1);
|
||||
|
||||
This gives us the first occurance of `1` in `vec`. What if we want to find
|
||||
the first occurrance of any number besides `1` in `vec`? We have to write an
|
||||
unfortunate amount of code:
|
||||
|
||||
auto std::vector<int> vec = { 1, 1, 2 };
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = std::find_if(vec.begin(), vec.end(), [](int i) { return i != 1; });
|
||||
|
||||
With `find_not()` the code gets much more terse:
|
||||
|
||||
auto std::vector<int> vec = { 1, 1, 2 };
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = find_not(vec.begin(), vec.end(), 1);
|
||||
|
||||
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.
|
||||
|
@ -15,7 +15,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
The header file `<boost/algorithm/cxx11/is_sorted.hpp>` contains functions for determining if a sequence is ordered.
|
||||
|
||||
[heading is_sorted]
|
||||
The function `is_sorted(sequence)` determines whether or not a sequence is completely sorted according so some criteria. If no comparison predicate is specified, then std::less_equal is used (i.e, the test is to see if the sequence is non-decreasing)
|
||||
The function `is_sorted(sequence)` determines whether or not a sequence is completely sorted according so some criteria. If no comparison predicate is specified, then `std::less` is used (i.e, the test is to see if the sequence is non-decreasing)
|
||||
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
|
@ -41,15 +41,16 @@ void
|
||||
apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end)
|
||||
{
|
||||
using Diff = typename std::iterator_traits<RandomAccessIterator1>::difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator1>::difference_type Diff;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Index;
|
||||
using std::swap;
|
||||
Diff size = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < size; i++)
|
||||
{
|
||||
auto current = i;
|
||||
Diff current = i;
|
||||
while (i != ind_begin[current])
|
||||
{
|
||||
auto next = ind_begin[current];
|
||||
Index next = ind_begin[current];
|
||||
swap(item_begin[current], item_begin[next]);
|
||||
ind_begin[current] = current;
|
||||
current = next;
|
||||
@ -75,7 +76,7 @@ apply_reverse_permutation(
|
||||
RandomAccessIterator2 ind_begin,
|
||||
RandomAccessIterator2 ind_end)
|
||||
{
|
||||
using Diff = typename std::iterator_traits<RandomAccessIterator2>::difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Diff;
|
||||
using std::swap;
|
||||
Diff length = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < length; i++)
|
||||
|
@ -15,7 +15,7 @@ alias unit_test_framework
|
||||
;
|
||||
|
||||
{
|
||||
test-suite algorithm/minmax:
|
||||
test-suite algorithm/minmax
|
||||
: [ run minmax_element_test.cpp unit_test_framework
|
||||
: : : : minmax_element ]
|
||||
[ run minmax_test.cpp unit_test_framework
|
||||
|
@ -16,7 +16,7 @@ alias unit_test_framework
|
||||
|
||||
|
||||
{
|
||||
test-suite algorithm:
|
||||
test-suite algorithm
|
||||
# Search tests
|
||||
: [ run empty_search_test.cpp unit_test_framework : : : : empty_search_test ]
|
||||
[ run search_test1.cpp unit_test_framework : : : : search_test1 ]
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/algorithm/apply_permutation.hpp>
|
||||
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MAIN
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
Reference in New Issue
Block a user