Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
ul_bound.cpp
Go to the documentation of this file.
1
29#include <vector>
30#include <algorithm>
31#include <functional>
32#include <iostream>
33
34int main ()
35{
36 typedef std::vector<int, std::allocator<int> > Vector;
37 typedef Vector::const_iterator Iterator;
38
39 const int a[] = { 0, 1, 2, 2, 3, 4, 5, 5, 5, 6, 7 };
40
41 // Set up a vector.
42 const Vector v (a, a + sizeof a / sizeof *a);
43
44 // Try lower_bound variants.
45 Iterator it1 = std::lower_bound (v.begin (),v.end (), 3);
46 Iterator it2 = std::lower_bound (v.begin (),v.end (), 2,
47 std::less<int>());
48
49 // Try upper_bound variants.
50 Iterator it3 = std::upper_bound (v.begin (), v.end (), 3);
51 Iterator it4 = std::upper_bound (v.begin (), v.end (), 2,
52 std::less<int>());
53
54 std::cout << "\n\nThe upper and lower bounds of 3: ( "
55 << *it1 << " , " << *it3
56 << " ]\n\n\nThe upper and lower bounds of 2: ( "
57 << *it2 << " , " << *it4 << " ]\n";
58
59 return 0;
60}
InputIter< UserClass > Iterator
#define v
Definition 17.names.cpp:138
#define a
Definition 17.names.cpp:109
std::vector< UserClass, std::allocator< UserClass > > Vector
int main()
Definition ul_bound.cpp:34