mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-28 21:40:57 +02:00
Compare commits
74 Commits
develop
...
boost-1.54
Author | SHA1 | Date | |
---|---|---|---|
088d942db3 | |||
1a70166889 | |||
63da6f5713 | |||
2381d0bdac | |||
40b5941652 | |||
00dfda98b2 | |||
52eef989da | |||
8132864884 | |||
6e098b27aa | |||
60010b4165 | |||
1660dc9d48 | |||
5ae4f848b3 | |||
fe3e0bb9c4 | |||
311e169376 | |||
3dddfa1930 | |||
be6d8f9665 | |||
bced4ed8dd | |||
1b57e905ab | |||
29bd9f53d9 | |||
6341cfb1a6 | |||
7f4acd6170 | |||
314f6dcfe0 | |||
167aa6e31c | |||
d228e91494 | |||
9cc573fbd0 | |||
28a7d3eb4b | |||
883cce61a8 | |||
96d4708367 | |||
563fe27a59 | |||
76cd99ed53 | |||
0f2399fef0 | |||
044d667e79 | |||
be9da63894 | |||
787c94bc53 | |||
e87ce37b34 | |||
199a89a1e9 | |||
01492a93c6 | |||
50703b8c97 | |||
0f8d556130 | |||
bbd3220a1e | |||
9068069106 | |||
a37af3c81e | |||
f5885c6fb0 | |||
d45bb3545e | |||
d735b9fa1e | |||
62ec675581 | |||
e7cd4da67b | |||
6076f5a18e | |||
60cd5a0500 | |||
c33dad924d | |||
2f2935f07e | |||
3cbaafc27f | |||
c067b348bf | |||
c33935fa1f | |||
98a8b08afb | |||
fc0f3dcffc | |||
822636418b | |||
352e16aade | |||
89c76ea1bb | |||
50b5726a6f | |||
d4b95734dd | |||
05af96f84c | |||
5bdbb2b308 | |||
1a02969303 | |||
6309379618 | |||
37581bac55 | |||
a71a4ed5b1 | |||
c509c3fbad | |||
d8683f2498 | |||
7c0101aa51 | |||
6f3e85528f | |||
8af639b7cf | |||
d9bc7e800b | |||
b4ed9beb90 |
0
include/boost/algorithm/clamp.hpp
Executable file → Normal file
0
include/boost/algorithm/clamp.hpp
Executable file → Normal file
@ -21,13 +21,10 @@
|
|||||||
#include <boost/range/end.hpp>
|
#include <boost/range/end.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <boost/type_traits/is_same.hpp>
|
#include <boost/type_traits/is_same.hpp>
|
||||||
|
#include <boost/tr1/tr1/tuple> // for tie
|
||||||
|
|
||||||
namespace boost { namespace algorithm {
|
namespace boost { namespace algorithm {
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
|
||||||
// Use the C++11 versions of is_permutation if it is available
|
|
||||||
using std::is_permutation; // Section 25.2.12
|
|
||||||
#else
|
|
||||||
/// \cond DOXYGEN_HIDE
|
/// \cond DOXYGEN_HIDE
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename Predicate, typename Iterator>
|
template <typename Predicate, typename Iterator>
|
||||||
@ -37,18 +34,82 @@ namespace detail {
|
|||||||
template <typename T1>
|
template <typename T1>
|
||||||
bool operator () ( const T1 &t1 ) const { return p_ ( *it_, t1 ); }
|
bool operator () ( const T1 &t1 ) const { return p_ ( *it_, t1 ); }
|
||||||
private:
|
private:
|
||||||
Predicate &p_;
|
Predicate p_;
|
||||||
Iterator it_;
|
Iterator it_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Preconditions:
|
||||||
|
// 1. The sequences are the same length
|
||||||
|
// 2. Any common elements on the front have been removed (not necessary for correctness, just for performance)
|
||||||
|
template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate >
|
||||||
|
bool is_permutation_inner ( ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
|
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||||
|
BinaryPredicate p ) {
|
||||||
|
// for each unique value in the sequence [first1,last1), count how many times
|
||||||
|
// it occurs, and make sure it occurs the same number of times in [first2, last2)
|
||||||
|
for ( ForwardIterator1 iter = first1; iter != last1; ++iter ) {
|
||||||
|
value_predicate<BinaryPredicate, ForwardIterator1> pred ( p, iter );
|
||||||
|
|
||||||
|
/* For each value we haven't seen yet... */
|
||||||
|
if ( std::find_if ( first1, iter, pred ) == iter ) {
|
||||||
|
std::size_t dest_count = std::count_if ( first2, last2, pred );
|
||||||
|
if ( dest_count == 0 || dest_count != (std::size_t) std::count_if ( iter, last1, pred ))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
||||||
|
bool is_permutation_tag ( ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
|
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||||
|
BinaryPredicate p,
|
||||||
|
std::forward_iterator_tag, std::forward_iterator_tag ) {
|
||||||
|
|
||||||
|
// Skip the common prefix (if any)
|
||||||
|
while ( first1 != last1 && first2 != last2 && p ( *first1, *first2 )) {
|
||||||
|
++first1;
|
||||||
|
++first2;
|
||||||
|
}
|
||||||
|
if ( first1 != last1 && first2 != last2 )
|
||||||
|
return boost::algorithm::detail::is_permutation_inner ( first1, last1, first2, last2,
|
||||||
|
std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> ());
|
||||||
|
return first1 == last1 && first2 == last2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class RandomAccessIterator1, class RandomAccessIterator2, class BinaryPredicate>
|
||||||
|
bool is_permutation_tag ( RandomAccessIterator1 first1, RandomAccessIterator1 last1,
|
||||||
|
RandomAccessIterator2 first2, RandomAccessIterator2 last2,
|
||||||
|
BinaryPredicate p,
|
||||||
|
std::random_access_iterator_tag, std::random_access_iterator_tag ) {
|
||||||
|
// Cheap check
|
||||||
|
if ( std::distance ( first1, last1 ) != std::distance ( first2, last2 ))
|
||||||
|
return false;
|
||||||
|
// Skip the common prefix (if any)
|
||||||
|
while ( first1 != last1 && first2 != last2 && p ( *first1, *first2 )) {
|
||||||
|
++first1;
|
||||||
|
++first2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( first1 != last1 && first2 != last2 )
|
||||||
|
return is_permutation_inner (first1, last1, first2, last2, p);
|
||||||
|
return first1 == last1 && first2 == last2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
// Use the C++11 versions of is_permutation if it is available
|
||||||
|
using std::is_permutation; // Section 25.2.12
|
||||||
|
#else
|
||||||
|
|
||||||
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2, BinaryPredicate p )
|
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2, BinaryPredicate p )
|
||||||
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||||
///
|
///
|
||||||
/// \param first The start of the input sequence
|
/// \param first1 The start of the input sequence
|
||||||
/// \param last One past the end of the input sequence
|
/// \param last1 One past the end of the input sequence
|
||||||
/// \param first2 The start of the second sequence
|
/// \param first2 The start of the second sequence
|
||||||
/// \param p The predicate to compare elements with
|
/// \param p The predicate to compare elements with
|
||||||
///
|
///
|
||||||
@ -60,6 +121,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
|||||||
ForwardIterator2 first2, BinaryPredicate p )
|
ForwardIterator2 first2, BinaryPredicate p )
|
||||||
{
|
{
|
||||||
// Skip the common prefix (if any)
|
// Skip the common prefix (if any)
|
||||||
|
// std::tie (first1, first2) = std::mismatch (first1, last1, first2, p);
|
||||||
std::pair<ForwardIterator1, ForwardIterator2> eq = std::mismatch (first1, last1, first2, p);
|
std::pair<ForwardIterator1, ForwardIterator2> eq = std::mismatch (first1, last1, first2, p);
|
||||||
first1 = eq.first;
|
first1 = eq.first;
|
||||||
first2 = eq.second;
|
first2 = eq.second;
|
||||||
@ -67,19 +129,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
|||||||
// Create last2
|
// Create last2
|
||||||
ForwardIterator2 last2 = first2;
|
ForwardIterator2 last2 = first2;
|
||||||
std::advance ( last2, std::distance (first1, last1));
|
std::advance ( last2, std::distance (first1, last1));
|
||||||
|
return boost::algorithm::detail::is_permutation_inner ( first1, last1, first2, last2, p );
|
||||||
// for each unique value in the sequence [first1,last1), count how many times
|
|
||||||
// it occurs, and make sure it occurs the same number of times in [first2, last2)
|
|
||||||
for ( ForwardIterator1 iter = first1; iter != last1; ++iter ) {
|
|
||||||
detail::value_predicate<BinaryPredicate, ForwardIterator1> pred ( p, iter );
|
|
||||||
|
|
||||||
/* For each value we haven't seen yet... */
|
|
||||||
if ( std::find_if ( first1, iter, pred ) == iter ) {
|
|
||||||
std::size_t dest_count = std::count_if ( first2, last2, pred );
|
|
||||||
if ( dest_count == 0 || dest_count != (std::size_t) std::count_if ( iter, last1, pred ))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -88,23 +138,84 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
|||||||
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2 )
|
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2 )
|
||||||
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||||
///
|
///
|
||||||
/// \param first The start of the input sequence
|
/// \param first1 The start of the input sequence
|
||||||
/// \param last One past the end of the input sequence
|
/// \param last2 One past the end of the input sequence
|
||||||
/// \param first2 The start of the second sequence
|
/// \param first2 The start of the second sequence
|
||||||
/// \note This function is part of the C++2011 standard library.
|
/// \note This function is part of the C++2011 standard library.
|
||||||
/// We will use the standard one if it is available,
|
/// We will use the standard one if it is available,
|
||||||
/// otherwise we have our own implementation.
|
/// otherwise we have our own implementation.
|
||||||
template< class ForwardIterator1, class ForwardIterator2 >
|
template< class ForwardIterator1, class ForwardIterator2 >
|
||||||
bool is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2 )
|
bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2 )
|
||||||
{
|
{
|
||||||
// How should I deal with the idea that ForwardIterator1::value_type
|
// How should I deal with the idea that ForwardIterator1::value_type
|
||||||
// and ForwardIterator2::value_type could be different? Define my own comparison predicate?
|
// and ForwardIterator2::value_type could be different? Define my own comparison predicate?
|
||||||
return boost::algorithm::is_permutation ( first, last, first2,
|
// Skip the common prefix (if any)
|
||||||
std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> ());
|
std::pair<ForwardIterator1, ForwardIterator2> eq = std::mismatch (first1, last1, first2 );
|
||||||
|
first1 = eq.first;
|
||||||
|
first2 = eq.second;
|
||||||
|
if ( first1 != last1 ) {
|
||||||
|
// Create last2
|
||||||
|
ForwardIterator2 last2 = first2;
|
||||||
|
std::advance ( last2, std::distance (first1, last1));
|
||||||
|
return boost::algorithm::detail::is_permutation_inner ( first1, last1, first2, last2,
|
||||||
|
std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> ());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last,
|
||||||
|
/// ForwardIterator2 first2, ForwardIterator2 last2 )
|
||||||
|
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||||
|
///
|
||||||
|
/// \param first1 The start of the input sequence
|
||||||
|
/// \param last2 One past the end of the input sequence
|
||||||
|
/// \param first2 The start of the second sequence
|
||||||
|
/// \param last1 One past the end of the second sequence
|
||||||
|
/// \note This function is part of the C++2011 standard library.
|
||||||
|
/// We will use the standard one if it is available,
|
||||||
|
/// otherwise we have our own implementation.
|
||||||
|
template< class ForwardIterator1, class ForwardIterator2 >
|
||||||
|
bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
|
ForwardIterator2 first2, ForwardIterator2 last2 )
|
||||||
|
{
|
||||||
|
// How should I deal with the idea that ForwardIterator1::value_type
|
||||||
|
// and ForwardIterator2::value_type could be different? Define my own comparison predicate?
|
||||||
|
return boost::algorithm::detail::is_permutation_tag (
|
||||||
|
first1, last1, first2, last2,
|
||||||
|
std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> (),
|
||||||
|
typename std::iterator_traits<ForwardIterator1>::iterator_category (),
|
||||||
|
typename std::iterator_traits<ForwardIterator2>::iterator_category ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last,
|
||||||
|
/// ForwardIterator2 first2, ForwardIterator2 last2,
|
||||||
|
/// BinaryPredicate p )
|
||||||
|
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||||
|
///
|
||||||
|
/// \param first1 The start of the input sequence
|
||||||
|
/// \param last1 One past the end of the input sequence
|
||||||
|
/// \param first2 The start of the second sequence
|
||||||
|
/// \param last2 One past the end of the second sequence
|
||||||
|
/// \param pred The predicate to compare elements with
|
||||||
|
///
|
||||||
|
/// \note This function is part of the C++2011 standard library.
|
||||||
|
/// We will use the standard one if it is available,
|
||||||
|
/// otherwise we have our own implementation.
|
||||||
|
template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate >
|
||||||
|
bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
|
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||||
|
BinaryPredicate pred )
|
||||||
|
{
|
||||||
|
return boost::algorithm::detail::is_permutation_tag (
|
||||||
|
first1, last1, first2, last2, pred,
|
||||||
|
typename std::iterator_traits<ForwardIterator1>::iterator_category (),
|
||||||
|
typename std::iterator_traits<ForwardIterator2>::iterator_category ());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// \fn is_permutation ( const Range &r, ForwardIterator first2 )
|
/// \fn is_permutation ( const Range &r, ForwardIterator first2 )
|
||||||
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||||
///
|
///
|
||||||
|
0
include/boost/algorithm/searching/boyer_moore.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/boyer_moore.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/boyer_moore_horspool.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/boyer_moore_horspool.hpp
Executable file → Normal file
8
include/boost/algorithm/searching/detail/bm_traits.hpp
Executable file → Normal file
8
include/boost/algorithm/searching/detail/bm_traits.hpp
Executable file → Normal file
@ -20,11 +20,7 @@
|
|||||||
#include <boost/type_traits/remove_const.hpp>
|
#include <boost/type_traits/remove_const.hpp>
|
||||||
|
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
|
|
||||||
#include <boost/tr1/tr1/unordered_map>
|
#include <boost/tr1/tr1/unordered_map>
|
||||||
#else
|
|
||||||
#include <unordered_map>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/algorithm/searching/detail/debugging.hpp>
|
#include <boost/algorithm/searching/detail/debugging.hpp>
|
||||||
|
|
||||||
@ -39,11 +35,7 @@ namespace boost { namespace algorithm { namespace detail {
|
|||||||
template<typename key_type, typename value_type>
|
template<typename key_type, typename value_type>
|
||||||
class skip_table<key_type, value_type, false> {
|
class skip_table<key_type, value_type, false> {
|
||||||
private:
|
private:
|
||||||
#ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
|
|
||||||
typedef std::tr1::unordered_map<key_type, value_type> skip_map;
|
typedef std::tr1::unordered_map<key_type, value_type> skip_map;
|
||||||
#else
|
|
||||||
typedef std::unordered_map<key_type, value_type> skip_map;
|
|
||||||
#endif
|
|
||||||
const value_type k_default_value;
|
const value_type k_default_value;
|
||||||
skip_map skip_;
|
skip_map skip_;
|
||||||
|
|
||||||
|
0
include/boost/algorithm/searching/detail/debugging.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/detail/debugging.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/knuth_morris_pratt.hpp
Executable file → Normal file
0
include/boost/algorithm/searching/knuth_morris_pratt.hpp
Executable file → Normal file
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) Marshall Clow 2012.
|
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
Alternate interfaces (aka "wrappers") for algorithms.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BOOST_ALGORITHM_WRAPPERS_HPP
|
|
||||||
#define BOOST_ALGORITHM_WRAPPERS_HPP
|
|
||||||
|
|
||||||
namespace boost { namespace algorithm {
|
|
||||||
|
|
||||||
/// \fn find_ptr ( Container &c, Key k )
|
|
||||||
/// \return a pointer to the value matching the key in the container,
|
|
||||||
/// or NULL if the key does not exist in the container.
|
|
||||||
///
|
|
||||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
|
||||||
/// Suggested by Olaf van der Spek
|
|
||||||
///
|
|
||||||
/// \param c The container to be searched
|
|
||||||
/// \param k The key value to search with
|
|
||||||
template <class Container, class Key>
|
|
||||||
typename Container::value_type::second_type*
|
|
||||||
find_ptr ( Container &c, Key k )
|
|
||||||
{
|
|
||||||
typename Container::iterator iter = c.find ( k );
|
|
||||||
return iter == c.end() ? NULL : &iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \fn find_ptr ( const Container &c, Key k )
|
|
||||||
/// \return a pointer to the value matching the key in the container,
|
|
||||||
/// or NULL if the key does not exist in the container.
|
|
||||||
///
|
|
||||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
|
||||||
/// Suggested by Olaf van der Spek
|
|
||||||
///
|
|
||||||
/// \param c The container to be searched
|
|
||||||
/// \param k The key value to search with
|
|
||||||
template <class Container, class Key>
|
|
||||||
const typename Container::value_type::second_type*
|
|
||||||
find_ptr ( const Container &c, Key k )
|
|
||||||
{
|
|
||||||
typename Container::const_iterator iter = c.find ( k );
|
|
||||||
return iter == c.end() ? NULL : &iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif
|
|
3
test/Jamfile.v2
Executable file → Normal file
3
test/Jamfile.v2
Executable file → Normal file
@ -58,9 +58,6 @@ alias unit_test_framework
|
|||||||
[ run hex_test4.cpp unit_test_framework : : : : hex_test4 ]
|
[ run hex_test4.cpp unit_test_framework : : : : hex_test4 ]
|
||||||
[ compile-fail hex_fail1.cpp ]
|
[ compile-fail hex_fail1.cpp ]
|
||||||
|
|
||||||
# Wrapper tests
|
|
||||||
[ run wrapper_test1.cpp unit_test_framework : : : : wrapper_test1 ]
|
|
||||||
|
|
||||||
# Gather tests
|
# Gather tests
|
||||||
[ run gather_test1.cpp unit_test_framework : : : : gather_test1 ]
|
[ run gather_test1.cpp unit_test_framework : : : : gather_test1 ]
|
||||||
[ compile-fail gather_fail1.cpp ]
|
[ compile-fail gather_fail1.cpp ]
|
||||||
|
0
test/clamp_test.cpp
Executable file → Normal file
0
test/clamp_test.cpp
Executable file → Normal file
0
test/empty_search_test.cpp
Executable file → Normal file
0
test/empty_search_test.cpp
Executable file → Normal file
@ -24,9 +24,9 @@ bool never_eq ( const T&, const T& ) { return false; }
|
|||||||
int comparison_count = 0;
|
int comparison_count = 0;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool counting_equals ( const T &a, const T &b ) {
|
bool counting_equals ( const T &a, const T &b ) {
|
||||||
++comparison_count;
|
++comparison_count;
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ba = boost::algorithm;
|
namespace ba = boost::algorithm;
|
||||||
|
|
||||||
@ -37,85 +37,88 @@ void test_equal ()
|
|||||||
const int sz = sizeof (num)/sizeof(num[0]);
|
const int sz = sizeof (num)/sizeof(num[0]);
|
||||||
|
|
||||||
|
|
||||||
// Empty sequences are equal to each other, but not to non-empty sequences
|
// Empty sequences are equal to each other, but not to non-empty sequences
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num),
|
input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
never_eq<int> ));
|
never_eq<int> ));
|
||||||
BOOST_CHECK ( ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
BOOST_CHECK ( ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
never_eq<int> ));
|
never_eq<int> ));
|
||||||
|
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
// Single element sequences are equal if they contain the same value
|
// Single element sequences are equal if they contain the same value
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
BOOST_CHECK ( ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
BOOST_CHECK ( ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
never_eq<int> ));
|
never_eq<int> ));
|
||||||
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
never_eq<int> ));
|
never_eq<int> ));
|
||||||
|
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
|
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
|
|
||||||
// Identical long sequences are equal.
|
// Identical long sequences are equal.
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)));
|
input_iterator<int *>(num), input_iterator<int *>(num + sz)));
|
||||||
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
never_eq<int> ));
|
never_eq<int> ));
|
||||||
|
BOOST_CHECK ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
|
eq<int> ));
|
||||||
|
|
||||||
// different sequences are different
|
// different sequences are different
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)));
|
input_iterator<int *>(num), input_iterator<int *>(num + sz)));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1)));
|
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1)));
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1),
|
||||||
eq<int> ));
|
eq<int> ));
|
||||||
|
|
||||||
// When there's a cheap check, bail early
|
// When there's a cheap check, bail early
|
||||||
comparison_count = 0;
|
comparison_count = 0;
|
||||||
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz - 1),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz - 1),
|
||||||
counting_equals<int> ));
|
counting_equals<int> ));
|
||||||
BOOST_CHECK ( comparison_count == 0 );
|
BOOST_CHECK ( comparison_count == 0 );
|
||||||
// And when there's not, we can't
|
// And when there's not, we can't
|
||||||
comparison_count = 0;
|
comparison_count = 0;
|
||||||
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
BOOST_CHECK (!ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz - 1),
|
||||||
counting_equals<int> ));
|
counting_equals<int> ));
|
||||||
BOOST_CHECK ( comparison_count > 0 );
|
BOOST_CHECK ( comparison_count > 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,10 +19,95 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
#include "iterator_test.hpp"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool eq ( const T& a, const T& b ) { return a == b; }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool never_eq ( const T&, const T& ) { return false; }
|
||||||
|
|
||||||
namespace ba = boost::algorithm;
|
namespace ba = boost::algorithm;
|
||||||
// namespace ba = boost;
|
|
||||||
|
|
||||||
void test_sequence1 () {
|
void test_sequence1 () {
|
||||||
|
int num[] = { 1, 1, 2, 3, 5 };
|
||||||
|
const int sz = sizeof (num)/sizeof(num[0]);
|
||||||
|
|
||||||
|
// Empty sequences
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num),
|
||||||
|
forward_iterator<int *>(num)));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num)));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num),
|
||||||
|
forward_iterator<int *>(num),
|
||||||
|
never_eq<int> )); // Since the sequences are empty, the pred is never called
|
||||||
|
|
||||||
|
// Empty vs. non-empty
|
||||||
|
BOOST_CHECK ( !
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
|
BOOST_CHECK ( !
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num + 1), forward_iterator<int *>(num + 2),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num)));
|
||||||
|
|
||||||
|
BOOST_CHECK ( !
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
|
BOOST_CHECK ( !
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
|
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2)));
|
||||||
|
|
||||||
|
// Something should be a permutation of itself
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz),
|
||||||
|
forward_iterator<int *>(num)));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz),
|
||||||
|
forward_iterator<int *>(num), eq<int> ));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz )));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz ),
|
||||||
|
eq<int> ));
|
||||||
|
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz)));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
|
eq<int> ));
|
||||||
|
BOOST_CHECK (
|
||||||
|
ba::is_permutation (
|
||||||
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
|
forward_iterator<int *>(num), forward_iterator<int *>(num + sz),
|
||||||
|
eq<int> ));
|
||||||
|
|
||||||
|
|
||||||
std::vector<int> v, v1;
|
std::vector<int> v, v1;
|
||||||
|
|
||||||
v.clear ();
|
v.clear ();
|
||||||
|
@ -24,9 +24,9 @@ bool never_eq ( const T&, const T& ) { return false; }
|
|||||||
namespace ba = boost::algorithm;
|
namespace ba = boost::algorithm;
|
||||||
|
|
||||||
template <typename Iter1, typename Iter2>
|
template <typename Iter1, typename Iter2>
|
||||||
bool iter_eq ( std::pair<Iter1, Iter1> pr, Iter1 first, Iter2 second ) {
|
bool iter_eq ( std::pair<Iter1, Iter2> pr, Iter1 first, Iter2 second ) {
|
||||||
return pr.first == first && pr.second == second;
|
return pr.first == first && pr.second == second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_mismatch ()
|
void test_mismatch ()
|
||||||
{
|
{
|
||||||
@ -35,123 +35,129 @@ void test_mismatch ()
|
|||||||
const int sz = sizeof (num)/sizeof(num[0]);
|
const int sz = sizeof (num)/sizeof(num[0]);
|
||||||
|
|
||||||
|
|
||||||
// No mismatch for empty sequences
|
// No mismatch for empty sequences
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)),
|
input_iterator<int *>(num), input_iterator<int *>(num)),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num),
|
input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
never_eq<int> ),
|
never_eq<int> ),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||||
never_eq<int> ),
|
never_eq<int> ),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
// Empty vs. non-empty mismatch immediately
|
// Empty vs. non-empty mismatch immediately
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)),
|
input_iterator<int *>(num), input_iterator<int *>(num)),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
ba::mismatch ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)),
|
||||||
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num)));
|
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
// Single element sequences are equal if they contain the same value
|
// Single element sequences are equal if they contain the same value
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
eq<int> ),
|
eq<int> ),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
eq<int> ),
|
eq<int> ),
|
||||||
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 1)));
|
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
never_eq<int> ),
|
never_eq<int> ),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||||
never_eq<int> ),
|
never_eq<int> ),
|
||||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)),
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||||
eq<int> ),
|
eq<int> ),
|
||||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||||
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||||
eq<int> ),
|
eq<int> ),
|
||||||
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Identical long sequences are equal.
|
// Identical long sequences are equal.
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
||||||
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
eq<int> ),
|
eq<int> ),
|
||||||
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
BOOST_CHECK ( iter_eq (
|
||||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
never_eq<int> ),
|
never_eq<int> ),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||||
|
|
||||||
// different sequences are different
|
BOOST_CHECK ( iter_eq (
|
||||||
BOOST_CHECK ( iter_eq (
|
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
never_eq<int> ),
|
||||||
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||||
|
|
||||||
BOOST_CHECK ( iter_eq (
|
// different sequences are different
|
||||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
BOOST_CHECK ( iter_eq (
|
||||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||||
eq<int> ),
|
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
||||||
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
|
BOOST_CHECK ( iter_eq (
|
||||||
|
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||||
|
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||||
|
eq<int> ),
|
||||||
|
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
test/search_test1.cpp
Executable file → Normal file
0
test/search_test1.cpp
Executable file → Normal file
0
test/search_test2.cpp
Executable file → Normal file
0
test/search_test2.cpp
Executable file → Normal file
0
test/search_test3.cpp
Executable file → Normal file
0
test/search_test3.cpp
Executable file → Normal file
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) Marshall Clow 2012.
|
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
For more information, see http://www.boost.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
|
||||||
#include <boost/algorithm/wrappers.hpp>
|
|
||||||
|
|
||||||
#define BOOST_TEST_MAIN
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace ba = boost::algorithm;
|
|
||||||
|
|
||||||
void test_int ()
|
|
||||||
{
|
|
||||||
std::map<int, int> m;
|
|
||||||
std::multimap<int, int> mm;
|
|
||||||
|
|
||||||
int *ptr;
|
|
||||||
|
|
||||||
// try with an empty map
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
|
||||||
|
|
||||||
m.insert ( std::make_pair <int, int> ( 5, 5 ));
|
|
||||||
mm.insert ( std::make_pair <int, int> ( 9, 9 ));
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
|
||||||
|
|
||||||
ptr = ba::find_ptr ( m, 5 );
|
|
||||||
BOOST_CHECK ( ptr != NULL && *ptr == 5 );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 9 ) == NULL );
|
|
||||||
|
|
||||||
ptr = ba::find_ptr ( mm, 9 );
|
|
||||||
BOOST_CHECK ( ptr != NULL && *ptr == 9 );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 5 ) == NULL );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_str ()
|
|
||||||
{
|
|
||||||
std::map<int, std::string> m;
|
|
||||||
std::multimap<int, std::string> mm;
|
|
||||||
std::string *ptr;
|
|
||||||
|
|
||||||
// try with an empty map
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 31 ) == NULL );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 31 ) == NULL );
|
|
||||||
|
|
||||||
m.insert ( std::make_pair <int, std::string> ( 55, "fifty-five" ));
|
|
||||||
mm.insert ( std::make_pair <int, std::string> ( 66, "sixty-six" ));
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
|
||||||
|
|
||||||
ptr = ba::find_ptr ( m, 55 );
|
|
||||||
BOOST_CHECK ( ptr != NULL && *ptr == "fifty-five" );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( m , 66 ) == NULL );
|
|
||||||
|
|
||||||
ptr = ba::find_ptr ( mm, 66 );
|
|
||||||
BOOST_CHECK ( ptr != NULL && *ptr == "sixty-six" );
|
|
||||||
BOOST_CHECK ( ba::find_ptr ( mm, 55 ) == NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( test_main )
|
|
||||||
{
|
|
||||||
test_int ();
|
|
||||||
test_str ();
|
|
||||||
}
|
|
Reference in New Issue
Block a user