Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
find_first_of.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for find_first_of()
30#include <functional> // for equal_to
31#include <iostream> // for cout, endl
32#include <iterator> // for ostream_iterator
33#include <vector> // for vector
34
35#include <examples.h>
36
37int main ()
38{
39 // Typedef for convenience.
40 typedef std::vector<int, std::allocator<int> > Vector;
41
42 const Vector::value_type a1[] = { 0, 1, 2, 2, 3, 4, 2, 2, 6, 7 };
43 const Vector::value_type a2[] = { 6, 4 };
44
45 // Set up two vectors.
46 const Vector v1 (a1, a1 + sizeof a1 / sizeof *a1);
47 const Vector v2 (a2, a2 + sizeof a2 / sizeof *a2);
48
49 // Try both find_first_of variants.
50 Vector::const_iterator it1 =
51 std::find_first_of (v1.begin (), v1.end (), v2.begin (), v2.end ());
52
53 Vector::const_iterator it2 =
54 std::find_first_of (v1.begin (), v1.end (), v2.begin (), v2.end (),
55 std::equal_to<Vector::value_type>());
56
57 // Create an output stream iterator.
58 std::ostream_iterator<Vector::value_type,
59 char,
60 std::char_traits<char> > out (std::cout, " " );
61
62 // Output results.
63 std::cout << "For the vectors { ";
64 std::copy (v1.begin (), v1.end (), out);
65
66 std:: cout << "} and { ";
67 std::copy (v2.begin (), v2.end (), out);
68
69 std::cout << "}\nboth versions of find_first_of point to: "
70 << *it1 << std::endl;
71
72 // Return 0 on success, non-0 on failure.
73 return !(*it1 == *it2);
74}
#define v2
Definition 17.names.cpp:271
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
#define v1
Definition 17.names.cpp:245
std::vector< UserClass, std::allocator< UserClass > > Vector
const int out
int main()