blob: c94590c89ce972a984bbd2bd68020fafae92dbca [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
3// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <set>
11
12// class set
13
14// iterator begin();
15// const_iterator begin() const;
16// iterator end();
17// const_iterator end() const;
18//
19// reverse_iterator rbegin();
20// const_reverse_iterator rbegin() const;
21// reverse_iterator rend();
22// const_reverse_iterator rend() const;
23//
24// const_iterator cbegin() const;
25// const_iterator cend() const;
26// const_reverse_iterator crbegin() const;
27// const_reverse_iterator crend() const;
28
29#include <set>
30#include <cassert>
31
32int main()
33{
34 {
35 typedef int V;
36 V ar[] =
37 {
38 1,
39 1,
40 1,
41 2,
42 2,
43 2,
44 3,
45 3,
46 3,
47 4,
48 4,
49 4,
50 5,
51 5,
52 5,
53 6,
54 6,
55 6,
56 7,
57 7,
58 7,
59 8,
60 8,
61 8
62 };
63 std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
64 assert(std::distance(m.begin(), m.end()) == m.size());
65 assert(std::distance(m.rbegin(), m.rend()) == m.size());
66 std::set<int>::iterator i = m.begin();
67 std::set<int>::const_iterator k = i;
68 assert(i == k);
69 for (int j = 1; j <= m.size(); ++j, ++i)
70 assert(*i == j);
71 }
72 {
73 typedef int V;
74 V ar[] =
75 {
76 1,
77 1,
78 1,
79 2,
80 2,
81 2,
82 3,
83 3,
84 3,
85 4,
86 4,
87 4,
88 5,
89 5,
90 5,
91 6,
92 6,
93 6,
94 7,
95 7,
96 7,
97 8,
98 8,
99 8
100 };
101 const std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
102 assert(std::distance(m.begin(), m.end()) == m.size());
103 assert(std::distance(m.cbegin(), m.cend()) == m.size());
104 assert(std::distance(m.rbegin(), m.rend()) == m.size());
105 assert(std::distance(m.crbegin(), m.crend()) == m.size());
106 std::set<int, double>::const_iterator i = m.begin();
107 for (int j = 1; j <= m.size(); ++j, ++i)
108 assert(*i == j);
109 }
110}