mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 20:11:50 +02:00
Compare commits
1 Commits
boost-1.52
...
boost-1.51
Author | SHA1 | Date | |
---|---|---|---|
b613c29c1e |
@ -39,7 +39,7 @@ OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if (p(*first))
|
||||
*result++ = *first;
|
||||
*result++ = first;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@ -75,7 +75,7 @@ OutputIterator copy_while ( InputIterator first, InputIterator last,
|
||||
OutputIterator result, Predicate p )
|
||||
{
|
||||
for ( ; first != last && p(*first); ++first )
|
||||
*result++ = *first;
|
||||
*result++ = first;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ template<typename InputIterator, typename OutputIterator, typename Predicate>
|
||||
OutputIterator copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
|
||||
{
|
||||
for ( ; first != last && !p(*first); ++first )
|
||||
*result++ = *first;
|
||||
*result++ = first;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace detail {
|
||||
|
||||
|
||||
/// \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 a the sequence [first,last) is a permutation of the sequence starting at first2
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last One past the end of the input sequence
|
||||
@ -88,7 +88,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
}
|
||||
|
||||
/// \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 a the sequence [first,last) is a permutation of the sequence starting at first2
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last One past the end of the input sequence
|
||||
@ -108,7 +108,7 @@ bool is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIter
|
||||
#endif
|
||||
|
||||
/// \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 a the sequence [first,last) is a permutation of the sequence starting at first2
|
||||
///
|
||||
/// \param r The input range
|
||||
/// \param first2 The start of the second sequence
|
||||
@ -119,7 +119,7 @@ bool is_permutation ( const Range &r, ForwardIterator first2 )
|
||||
}
|
||||
|
||||
/// \fn is_permutation ( const Range &r, ForwardIterator first2, BinaryPredicate pred )
|
||||
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
|
||||
/// \brief Tests to see if a the sequence [first,last) is a permutation of the sequence starting at first2
|
||||
///
|
||||
/// \param r The input range
|
||||
/// \param first2 The start of the second sequence
|
||||
|
@ -69,18 +69,14 @@ namespace detail {
|
||||
return std::copy ( res, res + num_hex_digits, out );
|
||||
}
|
||||
|
||||
// this needs to be in an un-named namespace because it is not a template
|
||||
// and might get included in several compilation units. This could cause
|
||||
// multiple definition errors at link time.
|
||||
namespace {
|
||||
unsigned hex_char_to_int ( char c ) {
|
||||
if ( c >= '0' && c <= '9' ) return c - '0';
|
||||
if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10;
|
||||
if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
|
||||
BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c));
|
||||
return 0; // keep dumb compilers happy
|
||||
return 0; // keep dumb compilers happy
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// My own iterator_traits class.
|
||||
// It is here so that I can "reach inside" some kinds of output iterators
|
||||
@ -109,17 +105,17 @@ namespace detail {
|
||||
// The first one is the output type, the second one is the character type of
|
||||
// the underlying stream, the third is the character traits.
|
||||
// We only care about the first one.
|
||||
template<typename T, typename charType, typename traits>
|
||||
struct hex_iterator_traits< std::ostream_iterator<T, charType, traits> > {
|
||||
typedef T value_type;
|
||||
};
|
||||
template<typename T, typename charType, typename traits>
|
||||
struct hex_iterator_traits< std::ostream_iterator<T, charType, traits> > {
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
bool iter_end ( Iterator current, Iterator last ) { return current == last; }
|
||||
|
||||
template <typename T>
|
||||
bool ptr_end ( const T* ptr, const T* /*end*/ ) { return *ptr == '\0'; }
|
||||
|
||||
template <typename Iterator>
|
||||
bool iter_end ( Iterator current, Iterator last ) { return current == last; }
|
||||
|
||||
template <typename T>
|
||||
bool ptr_end ( const T* ptr, const T* /*end*/ ) { return *ptr == '\0'; }
|
||||
|
||||
// What can we assume here about the inputs?
|
||||
// is std::iterator_traits<InputIterator>::value_type always 'char' ?
|
||||
// Could it be wchar_t, say? Does it matter?
|
||||
|
@ -14,11 +14,6 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/algorithm/searching/detail/bm_traits.hpp>
|
||||
|
@ -15,11 +15,6 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/algorithm/searching/detail/debugging.hpp>
|
||||
|
@ -32,7 +32,6 @@ import testing ;
|
||||
|
||||
[ run ordered_test.cpp : : : : ordered_test ]
|
||||
[ run find_if_not_test1.cpp : : : : find_if_not_test1 ]
|
||||
[ run copy_if_test1.cpp : : : : copy_if_test1 ]
|
||||
[ run copy_n_test1.cpp : : : : copy_n_test1 ]
|
||||
[ run iota_test1.cpp : : : : iota_test1 ]
|
||||
|
||||
|
@ -1,87 +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/cxx11/copy_if.hpp>
|
||||
#include <boost/test/included/test_exec_monitor.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include <boost/algorithm/cxx11/all_of.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
// namespace ba = boost;
|
||||
|
||||
bool is_true ( int v ) { return true; }
|
||||
bool is_false ( int v ) { return false; }
|
||||
bool is_even ( int v ) { return v % 2 == 0; }
|
||||
bool is_odd ( int v ) { return v % 2 == 1; }
|
||||
|
||||
template <typename Container>
|
||||
void test_sequence ( Container const &c ) {
|
||||
|
||||
typedef typename Container::value_type value_type;
|
||||
std::vector<value_type> v;
|
||||
|
||||
// None of the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
|
||||
v.clear ();
|
||||
ba::copy_if ( c, back_inserter ( v ), is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
|
||||
// All the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_true);
|
||||
BOOST_CHECK ( v.size () == c.size ());
|
||||
BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ()));
|
||||
|
||||
v.clear ();
|
||||
ba::copy_if ( c, back_inserter ( v ), is_true);
|
||||
BOOST_CHECK ( v.size () == c.size ());
|
||||
BOOST_CHECK ( v.size () == c.size ());
|
||||
BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ()));
|
||||
|
||||
// Some of the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_even );
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
|
||||
v.clear ();
|
||||
ba::copy_if ( c, back_inserter ( v ), is_even );
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
|
||||
|
||||
void test_sequence1 () {
|
||||
std::vector<int> v;
|
||||
for ( int i = 5; i < 15; ++i )
|
||||
v.push_back ( i );
|
||||
test_sequence ( v );
|
||||
|
||||
std::list<int> l;
|
||||
for ( int i = 25; i > 15; --i )
|
||||
l.push_back ( i );
|
||||
test_sequence ( l );
|
||||
}
|
||||
|
||||
|
||||
int test_main( int , char* [] )
|
||||
{
|
||||
test_sequence1 ();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user