Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
includes.cpp
Go to the documentation of this file.
1
30#include <algorithm> // for includes
31#include <iostream> // for cout, endl
32#include <iterator> // for ostream_iterator
33#include <set> // for set
34
35#include <examples.h>
36
37
38int main ()
39{
40 // Typedefs for convenience.
41 typedef std::set<int, std::less<int>, std::allocator<int> > Set;
42 typedef std::ostream_iterator<int, char, std::char_traits<char> > os_iter;
43
44 int a1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
45 int a2[] = { 2, 4, 6, 8, 10, 12 };
46 int a3[] = { 3, 5, 7, 8 };
47
48 // Initialize three sets.
49 Set all (a1, a1 + sizeof a1 / sizeof *a1);
50 Set even (a2, a2 + sizeof a2 / sizeof *a2);
51 Set other (a3, a3 + sizeof a3 / sizeof *a3);
52
53 // Demonstrate includes.
54 std::cout << "The set: ";
55 std::copy (all.begin (), all.end (), os_iter (std::cout, " "));
56
57 bool answer = std::includes (all.begin (), all.end (),
58 other.begin (), other.end ());
59
60 std::cout << std::endl << (answer ? "INCLUDES " : "DOES NOT INCLUDE ");
61 std::copy (other.begin (), other.end (), os_iter (std::cout, " "));
62
63 answer = std::includes (all.begin (), all.end (),
64 even.begin (), even.end ());
65
66 std::cout << ", and" << std::endl
67 << (answer ? "INCLUDES" : "DOES NOT INCLUDE ");
68
69 std::copy (even.begin (), even.end (), os_iter (std::cout, " "));
70
71 std::cout << std::endl << std::endl;
72
73 return 0;
74}
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
int main()
Definition includes.cpp:38
std::set< double, std::less< double >, std::allocator< double > > Set
Definition setex.cpp:39