1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <set>
10
11// class multiset
12
13// iterator lower_bound(const key_type& k);
14// const_iterator lower_bound(const key_type& k) const;
15
16#include <set>
17#include <cassert>
18
19#include "test_macros.h"
20#include "min_allocator.h"
21#include "private_constructor.h"
22
23int main(int, char**) {
24 {
25 typedef int V;
26 typedef std::multiset<int> M;
27 {
28 typedef M::iterator R;
29 V ar[] = {5, 5, 5, 7, 7, 7, 9, 9, 9};
30 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
31 R r = m.lower_bound(x: 4);
32 assert(r == std::next(m.begin(), 0));
33 r = m.lower_bound(x: 5);
34 assert(r == std::next(m.begin(), 0));
35 r = m.lower_bound(x: 6);
36 assert(r == std::next(m.begin(), 3));
37 r = m.lower_bound(x: 7);
38 assert(r == std::next(m.begin(), 3));
39 r = m.lower_bound(x: 8);
40 assert(r == std::next(m.begin(), 6));
41 r = m.lower_bound(x: 9);
42 assert(r == std::next(m.begin(), 6));
43 r = m.lower_bound(x: 11);
44 assert(r == std::next(m.begin(), 9));
45 }
46 {
47 typedef M::const_iterator R;
48 V ar[] = {5, 5, 5, 7, 7, 7, 9, 9, 9};
49 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
50 R r = m.lower_bound(x: 4);
51 assert(r == std::next(m.begin(), 0));
52 r = m.lower_bound(x: 5);
53 assert(r == std::next(m.begin(), 0));
54 r = m.lower_bound(x: 6);
55 assert(r == std::next(m.begin(), 3));
56 r = m.lower_bound(x: 7);
57 assert(r == std::next(m.begin(), 3));
58 r = m.lower_bound(x: 8);
59 assert(r == std::next(m.begin(), 6));
60 r = m.lower_bound(x: 9);
61 assert(r == std::next(m.begin(), 6));
62 r = m.lower_bound(x: 11);
63 assert(r == std::next(m.begin(), 9));
64 }
65 }
66#if TEST_STD_VER >= 11
67 {
68 typedef int V;
69 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
70 {
71 typedef M::iterator R;
72 V ar[] = {5, 5, 5, 7, 7, 7, 9, 9, 9};
73 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
74 R r = m.lower_bound(4);
75 assert(r == std::next(m.begin(), 0));
76 r = m.lower_bound(5);
77 assert(r == std::next(m.begin(), 0));
78 r = m.lower_bound(6);
79 assert(r == std::next(m.begin(), 3));
80 r = m.lower_bound(7);
81 assert(r == std::next(m.begin(), 3));
82 r = m.lower_bound(8);
83 assert(r == std::next(m.begin(), 6));
84 r = m.lower_bound(9);
85 assert(r == std::next(m.begin(), 6));
86 r = m.lower_bound(11);
87 assert(r == std::next(m.begin(), 9));
88 }
89 {
90 typedef M::const_iterator R;
91 V ar[] = {5, 5, 5, 7, 7, 7, 9, 9, 9};
92 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
93 R r = m.lower_bound(4);
94 assert(r == std::next(m.begin(), 0));
95 r = m.lower_bound(5);
96 assert(r == std::next(m.begin(), 0));
97 r = m.lower_bound(6);
98 assert(r == std::next(m.begin(), 3));
99 r = m.lower_bound(7);
100 assert(r == std::next(m.begin(), 3));
101 r = m.lower_bound(8);
102 assert(r == std::next(m.begin(), 6));
103 r = m.lower_bound(9);
104 assert(r == std::next(m.begin(), 6));
105 r = m.lower_bound(11);
106 assert(r == std::next(m.begin(), 9));
107 }
108 }
109#endif
110#if TEST_STD_VER > 11
111 {
112 typedef int V;
113 typedef std::multiset<V, std::less<>> M;
114
115 typedef M::iterator R;
116 V ar[] = {5, 5, 5, 7, 7, 7, 9, 9, 9};
117 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
118
119 R r = m.lower_bound(4);
120 assert(r == std::next(m.begin(), 0));
121 r = m.lower_bound(5);
122 assert(r == std::next(m.begin(), 0));
123 r = m.lower_bound(6);
124 assert(r == std::next(m.begin(), 3));
125 r = m.lower_bound(7);
126 assert(r == std::next(m.begin(), 3));
127 r = m.lower_bound(8);
128 assert(r == std::next(m.begin(), 6));
129 r = m.lower_bound(9);
130 assert(r == std::next(m.begin(), 6));
131 r = m.lower_bound(11);
132 assert(r == std::next(m.begin(), 9));
133 }
134
135 {
136 typedef PrivateConstructor V;
137 typedef std::multiset<V, std::less<>> M;
138 typedef M::iterator R;
139
140 M m;
141 m.insert(V::make(5));
142 m.insert(V::make(5));
143 m.insert(V::make(5));
144 m.insert(V::make(7));
145 m.insert(V::make(7));
146 m.insert(V::make(7));
147 m.insert(V::make(9));
148 m.insert(V::make(9));
149 m.insert(V::make(9));
150
151 R r = m.lower_bound(4);
152 assert(r == std::next(m.begin(), 0));
153 r = m.lower_bound(5);
154 assert(r == std::next(m.begin(), 0));
155 r = m.lower_bound(6);
156 assert(r == std::next(m.begin(), 3));
157 r = m.lower_bound(7);
158 assert(r == std::next(m.begin(), 3));
159 r = m.lower_bound(8);
160 assert(r == std::next(m.begin(), 6));
161 r = m.lower_bound(9);
162 assert(r == std::next(m.begin(), 6));
163 r = m.lower_bound(11);
164 assert(r == std::next(m.begin(), 9));
165 }
166#endif
167
168 return 0;
169}
170

source code of libcxx/test/std/containers/associative/multiset/lower_bound.pass.cpp