From 3aea2b6a78bdc8761e6abe6c9e4a36d6cd630f82 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 22 Jun 2008 02:11:09 +0000 Subject: [PATCH] Fixed tests [SVN r46599] --- copy/test/copy_test.cpp | 62 ++++++++++++++++---------------- include/boost/algorithm/copy.hpp | 3 +- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/copy/test/copy_test.cpp b/copy/test/copy_test.cpp index 48e0c84..4d781d0 100644 --- a/copy/test/copy_test.cpp +++ b/copy/test/copy_test.cpp @@ -3,13 +3,13 @@ // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include -#include - #include #include #include +#include +#include + // #include // #include @@ -20,6 +20,8 @@ template bool IsLess ( int v2 ) { return v2 < v; } bool IsEven ( int v2 ) { return ( v2 & 1 ) == 0; } bool IsOdd ( int v2 ) { return ( v2 & 1 ) != 0; } +namespace bas = boost::algorithm::sequence; + void test_copy_if () { const int vals [] = { 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1 }; @@ -33,36 +35,36 @@ void test_copy_if () // Copy_if from constant iterators res.clear (); - boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> ); + bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> ); BOOST_CHECK_EQUAL ( res.size (), 5U ); BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsNotEqual<0> ) == res.end ()); // Copy them all res.clear (); - boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> ); + bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( valsSize, res.size ()); BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // Copy_if using ranges res.clear (); - boost::algorithm::copy_if ( cont, std::back_inserter(res), IsNotEqual<0> ); + bas::copy_if ( cont, std::back_inserter(res), IsNotEqual<0> ); BOOST_CHECK_EQUAL ( res.size (), 5U ); BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsEqual<0> ) == res.end ()); // Copy them all res.clear (); - boost::algorithm::copy_if ( cont, std::back_inserter(res), IsNotEqual<2> ); + bas::copy_if ( cont, std::back_inserter(res), IsNotEqual<2> ); BOOST_CHECK_EQUAL ( cont.size (), res.size ()); BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_if ( cont, std::back_inserter(res), IsEqual<2> ); + bas::copy_if ( cont, std::back_inserter(res), IsEqual<2> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // ---- Backwards tests ---- @@ -75,7 +77,7 @@ void test_copy_if () // Copy_if_backward from constant iterators res.clear (); - boost::algorithm::copy_if_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsEven ); + bas::copy_backward_if ( vals2, vals2 + vals2Size, std::back_inserter(res), IsEven ); BOOST_CHECK_EQUAL ( res.size (), 5U ); BOOST_CHECK_EQUAL ( res[0], 8 ); BOOST_CHECK_EQUAL ( res[1], 6 ); @@ -85,19 +87,19 @@ void test_copy_if () // Copy them all res.clear (); - boost::algorithm::copy_if_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> ); + bas::copy_backward_if ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( vals2Size, res.size ()); BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ())); // Copy none res.clear (); - boost::algorithm::copy_if_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_backward_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // Copy_if_backward using ranges res.clear (); - boost::algorithm::copy_if_backward ( cont, std::back_inserter(res), IsEven ); + bas::copy_backward_if ( cont, std::back_inserter(res), IsEven ); BOOST_CHECK_EQUAL ( res.size (), 5U ); BOOST_CHECK_EQUAL ( res[0], 8 ); BOOST_CHECK_EQUAL ( res[1], 6 ); @@ -107,13 +109,13 @@ void test_copy_if () // Copy them all res.clear (); - boost::algorithm::copy_if_backward ( cont, std::back_inserter(res), IsLess<100> ); + bas::copy_backward_if ( cont, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( cont.size (), res.size ()); BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_if_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_backward_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); } @@ -130,36 +132,36 @@ void test_copy_while () // Copy_while from constant iterators res.clear (); - boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> ); + bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> ); BOOST_CHECK_EQUAL ( res.size (), 1U ); BOOST_CHECK_EQUAL ( res[0], 0 ); // Copy them all res.clear (); - boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> ); + bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( valsSize, res.size ()); BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // Copy_while using ranges res.clear (); - boost::algorithm::copy_while ( cont, std::back_inserter(res), IsNotEqual<1> ); + bas::copy_while ( cont, std::back_inserter(res), IsNotEqual<1> ); BOOST_CHECK_EQUAL ( res.size (), 1U ); BOOST_CHECK_EQUAL ( res[0], 0 ); // Copy them all res.clear (); - boost::algorithm::copy_while ( cont, std::back_inserter(res), IsNotEqual<2> ); + bas::copy_while ( cont, std::back_inserter(res), IsNotEqual<2> ); BOOST_CHECK_EQUAL ( cont.size (), res.size ()); BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_while ( cont, std::back_inserter(res), IsEqual<2> ); + bas::copy_while ( cont, std::back_inserter(res), IsEqual<2> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // ---- Backwards tests ---- @@ -172,7 +174,7 @@ void test_copy_while () // Copy_if_backward from constant iterators res.clear (); - boost::algorithm::copy_while_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsGreater<5> ); + bas::copy_backward_while ( vals2, vals2 + vals2Size, std::back_inserter(res), IsGreater<5> ); BOOST_CHECK_EQUAL ( res.size (), 4U ); BOOST_CHECK_EQUAL ( res[0], 9 ); BOOST_CHECK_EQUAL ( res[1], 8 ); @@ -181,19 +183,19 @@ void test_copy_while () // Copy them all res.clear (); - boost::algorithm::copy_while_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> ); + bas::copy_backward_while ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( vals2Size, res.size ()); BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ())); // Copy none res.clear (); - boost::algorithm::copy_while_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_backward_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); // Copy_while_backward using ranges res.clear (); - boost::algorithm::copy_while_backward ( cont, std::back_inserter(res), IsGreater<5> ); + bas::copy_backward_while ( cont, std::back_inserter(res), IsGreater<5> ); BOOST_CHECK_EQUAL ( res.size (), 3U ); BOOST_CHECK_EQUAL ( res[0], 8 ); BOOST_CHECK_EQUAL ( res[1], 7 ); @@ -201,13 +203,13 @@ void test_copy_while () // Copy them all res.clear (); - boost::algorithm::copy_while_backward ( cont, std::back_inserter(res), IsLess<100> ); + bas::copy_backward_while ( cont, std::back_inserter(res), IsLess<100> ); BOOST_CHECK_EQUAL ( cont.size (), res.size ()); BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_while_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); + bas::copy_backward_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> ); BOOST_CHECK_EQUAL ( 0U, res.size ()); } @@ -224,18 +226,18 @@ void test_copy_n () // copy_n from constant iterators res.clear (); - boost::algorithm::copy_n ( vals, valsSize, std::back_inserter(res)); + bas::copy_n ( vals, valsSize, std::back_inserter(res)); BOOST_CHECK_EQUAL ( res.size (), valsSize ); BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ())); // Copy none res.clear (); - boost::algorithm::copy_n ( vals, 0, std::back_inserter(res)); + bas::copy_n ( vals, 0, std::back_inserter(res)); BOOST_CHECK_EQUAL ( 0U, res.size ()); // Copy_while from container res.clear (); - boost::algorithm::copy_n ( cont.begin (), cont.size (), std::back_inserter(res) ); + bas::copy_n ( cont.begin (), cont.size (), std::back_inserter(res) ); BOOST_CHECK_EQUAL ( res.size (), cont.size ()); BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ())); } diff --git a/include/boost/algorithm/copy.hpp b/include/boost/algorithm/copy.hpp index 7619ba7..c18e9f2 100644 --- a/include/boost/algorithm/copy.hpp +++ b/include/boost/algorithm/copy.hpp @@ -12,6 +12,7 @@ #define BOOST_ALGORITHM_SEQUENCE_COPY_HPP #include // For boost::begin and boost::end +#include // for std::iterator_traits<> /// \file copy.hpp /// \brief Boost implementation of various STL-type copying algorithms @@ -199,7 +200,7 @@ template // template // O copy_n ( I first, Size count, O res ) template - O copy_n ( I first, typename iterator_traits::difference_type count, O res ) + O copy_n ( I first, typename std::iterator_traits::difference_type count, O res ) { while ( count-- > 0 ) *res++ = *first++;