2 Copyright (c) Marshall Clow 2011-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
12 #include <boost/config.hpp>
13 #include <boost/algorithm/cxx11/partition_copy.hpp>
14 #include <boost/test/included/test_exec_monitor.hpp>
16 #include <boost/algorithm/cxx11/all_of.hpp>
17 #include <boost/algorithm/cxx11/none_of.hpp>
22 namespace ba = boost::algorithm;
23 // namespace ba = boost;
25 template <typename Container, typename Predicate>
26 void test_sequence ( const Container &c, Predicate comp ) {
27 std::vector<typename Container::value_type> v1, v2;
29 v1.clear (); v2.clear ();
30 ba::partition_copy ( c.begin (), c.end (),
31 std::back_inserter (v1), std::back_inserter (v2), comp );
32 // std::cout << "Sizes(1): " << c.size () << " -> { " << v1.size () << ", " << v2.size () << " }" << std::endl;
33 BOOST_CHECK ( v1.size () + v2.size () == c.size ());
34 BOOST_CHECK ( ba::all_of ( v1.begin (), v1.end (), comp ));
35 BOOST_CHECK ( ba::none_of ( v2.begin (), v2.end (), comp ));
37 v1.clear (); v2.clear ();
38 ba::partition_copy ( c, std::back_inserter (v1), std::back_inserter ( v2 ), comp );
39 // std::cout << "Sizes(2): " << c.size () << " -> { " << v1.size () << ", " << v2.size () << " }" << std::endl;
40 BOOST_CHECK ( v1.size () + v2.size () == c.size ());
41 BOOST_CHECK ( ba::all_of ( v1, comp ));
42 BOOST_CHECK ( ba::none_of ( v2, comp ));
48 less_than ( T foo ) : val ( foo ) {}
49 less_than ( const less_than &rhs ) : val ( rhs.val ) {}
51 bool operator () ( const T &v ) const { return v < val; }
54 less_than operator = ( const less_than &rhs );
58 bool is_even ( int v ) { return v % 2 == 0; }
60 void test_sequence1 () {
64 for ( int i = 5; i < 15; ++i )
66 test_sequence ( v, less_than<int>(3)); // no elements
67 test_sequence ( v, less_than<int>(6)); // only the first element
68 test_sequence ( v, less_than<int>(10));
69 test_sequence ( v, less_than<int>(99)); // all elements satisfy
71 // With bidirectional iterators.
73 for ( int i = 5; i < 16; ++i )
75 test_sequence ( l, less_than<int>(3)); // no elements
76 test_sequence ( l, less_than<int>(6)); // only the first element
77 test_sequence ( l, less_than<int>(10));
78 test_sequence ( l, less_than<int>(99)); // all elements satisfy
83 int test_main( int , char* [] )