Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
equal.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for equal
30#include <functional> // for equal_to
31#include <ios> // for boolalpha
32#include <iostream> // for cout, endl
33#include <iterator> // for ostream_iterator
34#include <vector> // for vector
35
36#include <examples.h>
37
38
39int main ()
40{
41 // Typedef for convenience.
42 typedef std::vector<int, std::allocator<int> > Vector;
43
44 typedef std::ostream_iterator <Vector::value_type,
45 char,
46 std::char_traits<char> > os_iter;
47
48 const Vector::value_type a1[] = { 1, 2, 3, 4 };
49 const Vector::value_type a2[] = { 1, 2, 4, 3 };
50
51 // Set up two vectors.
52 const Vector v1 (a1, a1 + sizeof a1 / sizeof *a1);
53 const Vector v2 (a2, a2 + sizeof a2 / sizeof *a2);
54
55 // Check for equality.
56 bool same = std::equal (v1.begin (), v1.end (), v2.begin ());
57
58 same = same && std::equal (v1.begin (), v1.end (), v2.begin (),
59 std::equal_to<Vector::value_type>());
60
61 // Output the sequences.
62 std::cout << "{ ";
63 std::copy (v1.begin (), v1.end (), os_iter (std::cout, " "));
64
65 std::cout << "} == { ";
66 std::copy (v2.begin (), v2.end (), os_iter (std::cout, " "));
67
68 // Output the result.
69 std::cout << "} --> " << std::boolalpha << same << std::endl;
70
71 return 0;
72}
#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
int main()
Definition equal.cpp:39