Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
find_end.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for find_first_of(), find_end()
30#include <functional> // for equal_to
31#include <iostream> // for cout, endl
32#include <iterator> // for ostream_iterator
33#include <list> // for list
34
35#include <examples.h>
36
37
38int main ()
39{
40 typedef std::list<int, std::allocator<int> > List;
41
42 const List::value_type a1[] = { 0, 1, 6, 5, 3, 2, 2, 6, 5, 7 };
43 const List::value_type a2[] = { 6, 5, 0, 0 };
44
45 // Set up two sequences.
46 const List l1 (a1, a1 + sizeof a1 / sizeof *a1);
47 const List l2 (a2, a2 + 2);
48
49 // Try both find_first_of variants.
50 List::const_iterator it1 =
51 std::find_first_of (l1.begin (), l1.end (), l2.begin (), l2.end ());
52
53 List::const_iterator it2 =
54 std::find_first_of (l1.begin (), l1.end (), l2.begin (), l2.end (),
55 std::equal_to<List::value_type>());
56
57 // Try both find_end variants.
58 List::const_iterator it3 =
59 std::find_end (l1.begin (), l1.end (), l2.begin (), l2.end ());
60
61 List::const_iterator it4 =
62 std::find_end (l1.begin (), l1.end (), l2.begin (), l2.end (),
63 std::equal_to<List::value_type>());
64
65 // Output results of find_first_of.
66 // Iterator now points to the first element that matches
67 // one of a set of values.
68
69 std::ostream_iterator<List::value_type,
70 char,
71 std::char_traits<char> > out (std::cout, " " );
72
73 if (it3 == it4 && it1 == it2) {
74
75 std::cout << "For the sequences { ";
76 std::copy (l1.begin (), l1.end (), out);
77
78 std::cout << "} and { ";
79 std::copy (l2.begin (), l2.end (), out);
80
81 std::cout << "} \nboth versions of find_first_of point to: "
82 << *it1 << std::endl;
83
84 // Output results of find_end.
85 // Iterator now points to the first element of the last
86 // find subsequence.
87
88 std::cout << "both versions of find_end point to: "
89 << *it3 << std::endl;
90 }
91
92 return 0;
93}
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
const int out
int main()
Definition find_end.cpp:38