Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
lex_compare.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for lexicographical_compare
30#include <functional> // for less
31#include <ios> // for boolalpha
32#include <iostream> // for cout, endl
33#include <vector> // for vector
34
35#include <examples.h>
36
37
38int main()
39{
40 typedef std::vector<int, std::allocator<int> > Vector;
41
42 const Vector::value_type d1[] = { 1, 3, 5, 32, 64 };
43 const Vector::value_type d2[] = { 1, 3, 2, 43, 56 };
44
45 // Create vectors.
46 const Vector v1 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
47 const Vector v2 (d2 + 0, d2 + sizeof d1 / sizeof *d2);
48
49 // Is v1 less than v2 (I think not).
50 bool b1 = std::lexicographical_compare (v1.begin (), v1.end (),
51 v2.begin (), v2.end ());
52 // Is v2 less than v1 (yup, sure is).
53 bool b2 = std::lexicographical_compare (v2.begin (), v2.end (),
54 v1.begin (), v1.end (),
55 std::less<int>());
56 std::cout << std::boolalpha << b1
57 << " " << b2 << std::endl;
58
59 return 0;
60}
#define d1
Definition 17.names.cpp:228
#define b1
Definition 17.names.cpp:226
#define v2
Definition 17.names.cpp:271
#define b2
Definition 17.names.cpp:252
#define d2
Definition 17.names.cpp:254
#define v1
Definition 17.names.cpp:245
std::vector< UserClass, std::allocator< UserClass > > Vector
int main()