Compare commits

...

7 Commits

7 changed files with 12 additions and 12 deletions

View File

@ -28,7 +28,7 @@ the use of `std::find()`:
auto rfirst = std::make_reverse_iterator(last); auto rfirst = std::make_reverse_iterator(last);
auto rlast = std::make_reverse_iterator(first); auto rlast = std::make_reverse_iterator(first);
auto it = std::find(rfirst, rlast); auto it = std::find(rfirst, rlast, x);
// Use it here... // Use it here...
That seems nicer in that there is no raw loop, but it has two major drawbacks. That seems nicer in that there is no raw loop, but it has two major drawbacks.

View File

@ -15,19 +15,19 @@ equal to the given value.
Consider this use of `find()`: 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); 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 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 the first occurrance of any number besides `1` in `vec`? We have to write an
unfortunate amount of code: 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; }); auto it = std::find_if(vec.begin(), vec.end(), [](int i) { return i != 1; });
With `find_not()` the code gets much more terse: 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); auto it = find_not(vec.begin(), vec.end(), 1);
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`. The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.

View File

@ -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. The header file `<boost/algorithm/cxx11/is_sorted.hpp>` contains functions for determining if a sequence is ordered.
[heading is_sorted] [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 { namespace boost { namespace algorithm {

View File

@ -41,15 +41,16 @@ void
apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_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; using std::swap;
Diff size = std::distance(item_begin, item_end); Diff size = std::distance(item_begin, item_end);
for (Diff i = 0; i < size; i++) for (Diff i = 0; i < size; i++)
{ {
auto current = i; Diff current = i;
while (i != ind_begin[current]) while (i != ind_begin[current])
{ {
auto next = ind_begin[current]; Index next = ind_begin[current];
swap(item_begin[current], item_begin[next]); swap(item_begin[current], item_begin[next]);
ind_begin[current] = current; ind_begin[current] = current;
current = next; current = next;
@ -75,7 +76,7 @@ apply_reverse_permutation(
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_begin,
RandomAccessIterator2 ind_end) RandomAccessIterator2 ind_end)
{ {
using Diff = typename std::iterator_traits<RandomAccessIterator2>::difference_type; typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Diff;
using std::swap; using std::swap;
Diff length = std::distance(item_begin, item_end); Diff length = std::distance(item_begin, item_end);
for (Diff i = 0; i < length; i++) for (Diff i = 0; i < length; i++)

View File

@ -15,7 +15,7 @@ alias unit_test_framework
; ;
{ {
test-suite algorithm/minmax: test-suite algorithm/minmax
: [ run minmax_element_test.cpp unit_test_framework : [ run minmax_element_test.cpp unit_test_framework
: : : : minmax_element ] : : : : minmax_element ]
[ run minmax_test.cpp unit_test_framework [ run minmax_test.cpp unit_test_framework

View File

@ -16,7 +16,7 @@ alias unit_test_framework
{ {
test-suite algorithm: test-suite algorithm
# Search tests # Search tests
: [ run empty_search_test.cpp unit_test_framework : : : : empty_search_test ] : [ run empty_search_test.cpp unit_test_framework : : : : empty_search_test ]
[ run search_test1.cpp unit_test_framework : : : : search_test1 ] [ run search_test1.cpp unit_test_framework : : : : search_test1 ]

View File

@ -12,7 +12,6 @@
#include <boost/algorithm/apply_permutation.hpp> #include <boost/algorithm/apply_permutation.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN #define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>