Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
set_diff.cpp
Go to the documentation of this file.
1
29#include <algorithm>
30#include <set>
31#include <iostream>
32#include <iterator>
33
34
35int main ()
36{
37 // Initialize some sets.
38 const int a1 [] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
39 const int a2 [] = { 2, 4, 6, 8, 10, 12 };
40
41 std::set<int, std::less<int>, std::allocator<int> >
42 all (a1+0, a1+10),
43 even (a2+0, a2+6),
44 odd;
45
46 // Create an insert_iterator for odd.
47 std::insert_iterator<std::set <int, std::less<int>, std::allocator<int> > >
48 odd_ins (odd, odd.begin ());
49
50 // Demonstrate set_difference.
51 typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter;
52
53 std::cout << "The result of:\n{";
54
55 std::copy (all.begin (), all.end (), Iter (std::cout, " "));
56 std::cout << "} - {";
57
58 std::copy (even.begin (), even.end (), Iter (std::cout, " "));
59 std::cout << "} =\n{";
60
61 std::set_difference (all.begin (), all.end (),
62 even.begin (), even.end (),
63 odd_ins);
64
65 std::copy (odd.begin (),odd.end (), Iter (std::cout," "));
66 std::cout << "}\n\n";
67
68 return 0;
69}
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition set_diff.cpp:35