Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
set_union.cpp
Go to the documentation of this file.
1
29#include <algorithm>
30#include <set>
31#include <iostream>
32#include <iterator>
33
34int main ()
35{
36 typedef std::set<int, std::less<int>, std::allocator<int> > Set;
37
38 // Initialize sets.
39 const int a1[] = { 2, 4, 6, 8, 10, 12 };
40 const int a2[] = { 3, 5, 7, 8 };
41
42 const Set s1 (a1, a1 + sizeof a1 / sizeof *a1);
43 const Set s2 (a2, a2 + sizeof a2 / sizeof *a2);
44
45 Set result;
46
47 // Create an insert_iterator for result.
48 std::insert_iterator<Set> res_ins (result, result.begin ());
49
50 // Compute union of two sets.
51 std::set_union (s2.begin (), s2.end (), s1.begin (), s1.end (), res_ins);
52
53 // Display result on standard output.
54 typedef std::ostream_iterator<int, char, std::char_traits<char> > OSIter;
55
56 std::cout << "The result of:\n{ ";
57
58 std::copy (s2.begin (),s2.end (), OSIter (std::cout," "));
59
60 std::cout << "} union { ";
61
62 std::copy (s1.begin (),s1.end (), OSIter (std::cout," "));
63
64 std::cout << "} =\n{ ";
65
66 std::copy (result.begin (),result.end (), OSIter (std::cout," "));
67
68 std::cout << "}\n\n";
69
70 return 0;
71}
#define s1
Definition 17.names.cpp:242
#define s2
Definition 17.names.cpp:268
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
volatile int result
int main()
Definition set_union.cpp:34
std::set< double, std::less< double >, std::allocator< double > > Set
Definition setex.cpp:39