Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
mismatch.cpp
Go to the documentation of this file.
1
31#include <algorithm> // mismatch
32#include <functional> // less_equal
33#include <iostream> // cout, endl
34#include <utility> // pair
35#include <vector> // vector
36
37#include <examples.h>
38
39
40int main ()
41{
42 typedef std::vector<int, std::allocator<int> > Vector;
43 typedef Vector::const_iterator Iter;
44
45 const Vector::value_type d1[] = { 1, 2, 3, 4 };
46 const Vector::value_type d2[] = { 1, 3, 2, 4 };
47
48 // Set up two vectors.
49 const Vector vi1 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
50 const Vector vi2 (d2 + 0, d2 + sizeof d2 / sizeof *d2);
51
52 // p1 will contain two iterators that point to the first pair of
53 // elements that are different between the two vectors.
54 std::pair<Iter, Iter> p1 =
55 std::mismatch (vi1.begin (), vi1.end (), vi2.begin ());
56
57 // Find the first two elements such that an element in the
58 // first vector is greater than the element in the second vector.
59 std::pair<Iter, Iter> p2 =
60 std::mismatch (vi1.begin (), vi1.end (),
61 vi2.begin (), std::less_equal<int>());
62
63 // Output results.
64 std::cout << *p1.first << ", " << *p1.second << std::endl;
65 std::cout << *p2.first << ", " << *p2.second << std::endl;
66
67 return 0;
68}
#define d1
Definition 17.names.cpp:228
#define p2
Definition 17.names.cpp:265
#define p1
Definition 17.names.cpp:239
#define d2
Definition 17.names.cpp:254
std::vector< UserClass, std::allocator< UserClass > > Vector
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition mismatch.cpp:40