mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 12:01:39 +02:00
Compare commits
15 Commits
boost-1.69
...
boost-1.71
Author | SHA1 | Date | |
---|---|---|---|
1b65b8de02 | |||
77bbc6ce43 | |||
0a57ec30a2 | |||
9477cd8be0 | |||
f39107f228 | |||
5af3e3b174 | |||
1cbe285841 | |||
b6c04d6dc5 | |||
bf2b49e57e | |||
01b0dd8648 | |||
6763d75683 | |||
435cc61af8 | |||
45baad2431 | |||
5408a17020 | |||
c6f784cb70 |
@ -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++)
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_ALGORITHM_FIND_BACKWARD_HPP
|
||||
#define BOOST_ALGORITHM_FIND_BACKWARD_HPP
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_ALGORITHM_FIND_NOT_HPP
|
||||
#define BOOST_ALGORITHM_FIND_NOT_HPP
|
||||
|
@ -71,7 +71,11 @@ namespace boost {
|
||||
inline SequenceSequenceT&
|
||||
iter_find(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
FinderT Finder )
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((
|
||||
@ -142,7 +146,11 @@ namespace boost {
|
||||
inline SequenceSequenceT&
|
||||
iter_split(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
FinderT Finder )
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((
|
||||
|
@ -61,7 +61,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& find_all(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
Range1T&& Input,
|
||||
#else
|
||||
Range1T& Input,
|
||||
#endif
|
||||
const Range2T& Search)
|
||||
{
|
||||
return ::boost::algorithm::iter_find(
|
||||
@ -96,7 +100,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& ifind_all(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
Range1T&& Input,
|
||||
#else
|
||||
Range1T& Input,
|
||||
#endif
|
||||
const Range2T& Search,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
@ -139,7 +147,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
|
||||
inline SequenceSequenceT& split(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
PredicateT Pred,
|
||||
token_compress_mode_type eCompress=token_compress_off )
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ namespace boost {
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b);
|
||||
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/ BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class T, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
@ -38,77 +38,77 @@ Synopsis of <tt><boost/algorithm/minmax_element.hpp></tt></h3>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
// Variants
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator first_min_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator first_min_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator last_min_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator last_min_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
@ -95,7 +95,7 @@ namespace boost {
|
||||
tuple<T const&, T const&>
|
||||
minmax(const T& a, const T& b);
|
||||
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class T, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
tuple<T const&, T const&>
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
@ -109,11 +109,11 @@ Synopsis of <tt><boost/algorithm/minmax_element.hpp></tt></h3>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
@ -190,26 +190,26 @@ in <a href="../../../boost/algorithm/minmax_element.hpp">minmax_element.hpp</a>.
|
||||
<a name="reqs">
|
||||
<h3>
|
||||
Requirements on types</h3>
|
||||
For minmax, <tt>T</tt> must be a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
For minmax, <tt>T</tt> must be a model of <a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a>.
|
||||
<p>For all the other function templates, versions with two template parameters:
|
||||
<ul>
|
||||
<li>
|
||||
<tt>ForwardIterator</tt> is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
|
||||
<tt>ForwardIterator</tt> is a model of <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">Forward
|
||||
Iterator</a>.</li>
|
||||
|
||||
<li>
|
||||
<tt>ForwardIterator</tt>'s value type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
<tt>ForwardIterator</tt>'s value type is <a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a>.</li>
|
||||
</ul>
|
||||
For the versions with three template parameters:
|
||||
<ul>
|
||||
<li>
|
||||
<tt>ForwardIterator</tt> is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
|
||||
<tt>ForwardIterator</tt> is a model of <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">Forward
|
||||
Iterator</a>.</li>
|
||||
|
||||
<li>
|
||||
<tt>BinaryPredicate</tt> is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary
|
||||
<tt>BinaryPredicate</tt> is a model of <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">Binary
|
||||
Predicate</a>.</li>
|
||||
|
||||
<li>
|
||||
@ -285,8 +285,8 @@ the library under
|
||||
assert( result1.get<0>() == 0 );
|
||||
assert( result1.get<1>() == 1 );
|
||||
|
||||
<a href="http://www.sgi.com/tech/stl/List.html">list</a><int> L;
|
||||
<a href="http://www.sgi.com/tech/stl/generate_n.html">generate_n</a>(<a href="http://www.sgi.com/tech/stl/front_insert_iterator.html">front_inserter</a>(L), 1000, rand);
|
||||
<a href="https://www.boost.org/sgi/stl/List.html">list</a><int> L;
|
||||
<a href="https://www.boost.org/sgi/stl/generate_n.html">generate_n</a>(<a href="https://www.boost.org/sgi/stl/front_insert_iterator.html">front_inserter</a>(L), 1000, rand);
|
||||
|
||||
typedef list<int>::const_iterator iterator;
|
||||
pair< iterator, iterator > result2 = boost::minmax_element(L.begin(), L.end());
|
||||
@ -512,13 +512,13 @@ release, Eric Niebler noted the bad behavior of <tt>std::pair</tt> for
|
||||
All my thanks for the excellent advice and reviews from all.
|
||||
<h3>
|
||||
See also</h3>
|
||||
<tt><a href="http://www.sgi.com/tech/stl/min.html">min</a></tt>, <tt><a href="http://www.sgi.com/tech/stl/max.html">max</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/min_element.html">min_element</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/max_element.html">max_element</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
<tt><a href="https://www.boost.org/sgi/stl/min.html">min</a></tt>, <tt><a href="https://www.boost.org/sgi/stl/max.html">max</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/min_element.html">min_element</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/max_element.html">max_element</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/sort.html">sort</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/nth_element.html">nth_element</a></tt>
|
||||
<tt><a href="https://www.boost.org/sgi/stl/sort.html">sort</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/nth_element.html">nth_element</a></tt>
|
||||
.
|
||||
<hr SIZE="6">
|
||||
<br>Last modified 2012-12-10
|
||||
|
@ -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
|
||||
|
@ -31,7 +31,7 @@
|
||||
typedef <i>implementation defined </i> foo_type;</code><p >The corresponding external concept is the ExternalFooConcept.</p><p >A type <code>T</code> fullfills the ExternalFooConcept if these
|
||||
free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br>
|
||||
int bar( T& ); <br>
|
||||
foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="http://www.sgi.com/tech/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk).
|
||||
foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="https://www.boost.org/sgi/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk).
|
||||
<br>Use, modification and distribution is subject to the Boost
|
||||
Software License, Version 1.0. (See accompanying file
|
||||
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
// equals predicate is used for result comparison
|
||||
@ -82,6 +84,28 @@ void iterator_test()
|
||||
string("xx") );
|
||||
deep_compare( tokens, vtokens );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// If using a compiler that supports forwarding references, we should be able to use rvalues, too
|
||||
find_all(
|
||||
tokens,
|
||||
string("xx-abc--xx-abb"),
|
||||
"xx" );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==2 );
|
||||
BOOST_CHECK( tokens[0]==string("xx") );
|
||||
BOOST_CHECK( tokens[1]==string("xx") );
|
||||
|
||||
ifind_all(
|
||||
tokens,
|
||||
string("Xx-abc--xX-abb-xx"),
|
||||
"xx" );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==3 );
|
||||
BOOST_CHECK( tokens[0]==string("Xx") );
|
||||
BOOST_CHECK( tokens[1]==string("xX") );
|
||||
BOOST_CHECK( tokens[2]==string("xx") );
|
||||
#endif
|
||||
|
||||
// split tests
|
||||
split(
|
||||
tokens,
|
||||
@ -144,6 +168,21 @@ void iterator_test()
|
||||
BOOST_REQUIRE( tokens.size()==1 );
|
||||
BOOST_CHECK( tokens[0]==string("") );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// If using a compiler that supports forwarding references, we should be able to use rvalues, too
|
||||
split(
|
||||
tokens,
|
||||
string("Xx-abc--xX-abb-xx"),
|
||||
is_any_of("xX"),
|
||||
token_compress_on );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==4 );
|
||||
BOOST_CHECK( tokens[0]==string("") );
|
||||
BOOST_CHECK( tokens[1]==string("-abc--") );
|
||||
BOOST_CHECK( tokens[2]==string("-abb-") );
|
||||
BOOST_CHECK( tokens[3]==string("") );
|
||||
#endif
|
||||
|
||||
|
||||
find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
|
||||
find_iterator<string::iterator> fiter2;
|
||||
|
@ -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,22 +12,21 @@
|
||||
|
||||
#include <boost/algorithm/apply_permutation.hpp>
|
||||
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MAIN
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
|
||||
void test_apply_permutation()
|
||||
BOOST_AUTO_TEST_CASE(test_apply_permutation)
|
||||
{
|
||||
//Empty
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//1 element
|
||||
{
|
||||
@ -37,7 +36,7 @@ void test_apply_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, no changes
|
||||
{
|
||||
@ -47,7 +46,7 @@ void test_apply_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, changed
|
||||
{
|
||||
@ -57,7 +56,7 @@ void test_apply_permutation()
|
||||
result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, no changes
|
||||
{
|
||||
@ -67,7 +66,7 @@ void test_apply_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, changed
|
||||
{
|
||||
@ -77,7 +76,7 @@ void test_apply_permutation()
|
||||
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Just test range interface
|
||||
{
|
||||
@ -87,18 +86,18 @@ void test_apply_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec, order);
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
}
|
||||
|
||||
void test_apply_reverse_permutation()
|
||||
BOOST_AUTO_TEST_CASE(test_apply_reverse_permutation)
|
||||
{
|
||||
//Empty
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//1 element
|
||||
{
|
||||
@ -108,7 +107,7 @@ void test_apply_reverse_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, no changes
|
||||
{
|
||||
@ -118,7 +117,7 @@ void test_apply_reverse_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, changed
|
||||
{
|
||||
@ -128,7 +127,7 @@ void test_apply_reverse_permutation()
|
||||
result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, no changes
|
||||
{
|
||||
@ -138,7 +137,7 @@ void test_apply_reverse_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, changed
|
||||
{
|
||||
@ -148,7 +147,7 @@ void test_apply_reverse_permutation()
|
||||
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Just test range interface
|
||||
{
|
||||
@ -158,12 +157,6 @@ void test_apply_reverse_permutation()
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec, order);
|
||||
BOOST_CHECK(vec == result);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_main)
|
||||
{
|
||||
test_apply_permutation();
|
||||
test_apply_reverse_permutation();
|
||||
}
|
||||
|
Reference in New Issue
Block a user