Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
find.cpp
Go to the documentation of this file.
1
30#include <vector> // for vector
31#include <algorithm> // for adjacent_find, find
32#include <functional> // for bind1st, equal_to
33#include <iostream> // for cout, endl
34
35#include <examples.h>
36
37
38int main ()
39{
40 // Typedef for convenience.
41 typedef std::vector<int, std::allocator<int> > Vector;
42
43 const Vector::value_type arr[] = { 0, 1, 2, 2, 3, 4, 2, 2, 6, 7 };
44
45 // Set up a vector.
46 const Vector v1 (arr, arr + sizeof arr / sizeof *arr);
47
48 // Try find.
49 Vector::const_iterator it = std::find (v1.begin (), v1.end (), 3);
50
51 std::cout << *it << ' ';
52
53 // Try find_if.
54 it = std::find_if (v1.begin (), v1.end (),
55 std::bind1st (std::equal_to<Vector::value_type>(), 3));
56
57 std::cout << *it << ' ';
58
59 // Try both adjacent_find variants.
60 it = std::adjacent_find (v1.begin (), v1.end ());
61
62 std::cout << *it << ' ';
63
64 it = std::adjacent_find (v1.begin (), v1.end (),
65 std::equal_to<Vector::value_type>());
66
67 std::cout << *it << std::endl;
68
69 return 0;
70}
#define v1
Definition 17.names.cpp:245
std::vector< UserClass, std::allocator< UserClass > > Vector
int main()
Definition find.cpp:38