1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <map>
11
12 // class map
13
14 // iterator find(const key_type& k);
15 // const_iterator find(const key_type& k) const;
16
17 #include <map>
18 #include <cassert>
19
main()20 int main()
21 {
22 typedef std::pair<const int, double> V;
23 typedef std::map<int, double> M;
24 {
25 typedef M::iterator R;
26 V ar[] =
27 {
28 V(5, 5),
29 V(6, 6),
30 V(7, 7),
31 V(8, 8),
32 V(9, 9),
33 V(10, 10),
34 V(11, 11),
35 V(12, 12)
36 };
37 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
38 R r = m.find(5);
39 assert(r == m.begin());
40 r = m.find(6);
41 assert(r == next(m.begin()));
42 r = m.find(7);
43 assert(r == next(m.begin(), 2));
44 r = m.find(8);
45 assert(r == next(m.begin(), 3));
46 r = m.find(9);
47 assert(r == next(m.begin(), 4));
48 r = m.find(10);
49 assert(r == next(m.begin(), 5));
50 r = m.find(11);
51 assert(r == next(m.begin(), 6));
52 r = m.find(12);
53 assert(r == next(m.begin(), 7));
54 r = m.find(4);
55 assert(r == next(m.begin(), 8));
56 }
57 {
58 typedef M::const_iterator R;
59 V ar[] =
60 {
61 V(5, 5),
62 V(6, 6),
63 V(7, 7),
64 V(8, 8),
65 V(9, 9),
66 V(10, 10),
67 V(11, 11),
68 V(12, 12)
69 };
70 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
71 R r = m.find(5);
72 assert(r == m.begin());
73 r = m.find(6);
74 assert(r == next(m.begin()));
75 r = m.find(7);
76 assert(r == next(m.begin(), 2));
77 r = m.find(8);
78 assert(r == next(m.begin(), 3));
79 r = m.find(9);
80 assert(r == next(m.begin(), 4));
81 r = m.find(10);
82 assert(r == next(m.begin(), 5));
83 r = m.find(11);
84 assert(r == next(m.begin(), 6));
85 r = m.find(12);
86 assert(r == next(m.begin(), 7));
87 r = m.find(4);
88 assert(r == next(m.begin(), 8));
89 }
90 }
91