1/*
2 Copyright (c) Marshall Clow 2011-2012.
3
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)
6
7 For more information, see http://www.boost.org
8*/
9
10#include <iostream>
11
12#include <boost/config.hpp>
13#include <boost/algorithm/cxx11/is_partitioned.hpp>
14
15#define BOOST_TEST_MAIN
16#include <boost/test/unit_test.hpp>
17
18#include <string>
19#include <vector>
20#include <list>
21
22namespace ba = boost::algorithm;
23// namespace ba = boost;
24
25template <typename T>
26struct less_than {
27public:
28 less_than ( T foo ) : val ( foo ) {}
29 less_than ( const less_than &rhs ) : val ( rhs.val ) {}
30
31 bool operator () ( const T &v ) const { return v < val; }
32private:
33 less_than ();
34 less_than operator = ( const less_than &rhs );
35 T val;
36 };
37
38
39void test_sequence1 () {
40 std::vector<int> v;
41
42 v.clear ();
43 for ( int i = 5; i < 15; ++i )
44 v.push_back ( x: i );
45 BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(3))); // no elements
46 BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(6))); // only the first element
47 BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(10))); // in the middle somewhere
48 BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(99))); // all elements satisfy
49
50// With bidirectional iterators.
51 std::list<int> l;
52 for ( int i = 5; i < 15; ++i )
53 l.push_back ( x: i );
54 BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(3))); // no elements
55 BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(6))); // only the first element
56 BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(10))); // in the middle somewhere
57 BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(99))); // all elements satisfy
58 }
59
60
61BOOST_AUTO_TEST_CASE( test_main )
62{
63 test_sequence1 ();
64}
65

source code of boost/libs/algorithm/test/is_partitioned_test1.cpp