Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
partition.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for copy
30#include <deque> // for deque
31#include <functional> // for unary_function
32#include <iostream> // for cout, endl
33#include <iterator> // for ostream_iterator
34
35#include <examples.h>
36
37typedef std::modulus<int> int_modulus;
38typedef std::binder2nd<int_modulus> bnd_modulus;
39typedef std::unary_negate<bnd_modulus> is_even;
40
41int main ()
42{
43 typedef std::deque<int, std::allocator<int> > Deque;
44 typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter;
45
46 // Initialize a deque with an array of integers.
47 const Deque::value_type a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
48
49 Deque d1 (a + 0, a + sizeof a / sizeof *a);
50 Deque d2 (d1);
51
52 // Print out the original values.
53 std::cout << "Unpartitioned values: \t\t";
54 std::copy (d1.begin (), d1.end (), Iter (std::cout, " "));
55
56 // A partition of the deque according to even/oddness.
57 std::partition (d2.begin (), d2.end (), is_even ( bnd_modulus(int_modulus (), 2)) );
58
59 // Output result of partition.
60 std::cout << "\nPartitioned values: \t\t";
61 std::copy (d2.begin (), d2.end (), Iter (std::cout, " "));
62
63 // A stable partition of the deque according to even/oddness.
64 std::stable_partition (d1.begin (), d1.end (), is_even ( bnd_modulus(int_modulus (), 2)) );
65
66 // Output result of partition.
67 std::cout << "\nStable partitioned values: \t";
68 std::copy (d1.begin (), d1.end (), Iter (std::cout, " "));
69 std::cout << std::endl;
70
71 return 0;
72}
73
74
75
76
77
78
79
80
81
#define d1
Definition 17.names.cpp:228
#define a
Definition 17.names.cpp:109
#define d2
Definition 17.names.cpp:254
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
std::deque< std::string, std::allocator< std::string > > Deque
Definition deque.cpp:35
std::unary_negate< bnd_modulus > is_even
Definition partition.cpp:39
std::modulus< int > int_modulus
Definition partition.cpp:37
std::binder2nd< int_modulus > bnd_modulus
Definition partition.cpp:38
int main()
Definition partition.cpp:41