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 upper_bound(const key_type& k);
14// const_iterator upper_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.upper_bound(x: 4);
32 assert(r == std::next(m.begin(), 0));
33 r = m.upper_bound(x: 5);
34 assert(r == std::next(m.begin(), 3));
35 r = m.upper_bound(x: 6);
36 assert(r == std::next(m.begin(), 3));
37 r = m.upper_bound(x: 7);
38 assert(r == std::next(m.begin(), 6));
39 r = m.upper_bound(x: 8);
40 assert(r == std::next(m.begin(), 6));
41 r = m.upper_bound(x: 9);
42 assert(r == std::next(m.begin(), 9));
43 r = m.upper_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.upper_bound(x: 4);
51 assert(r == std::next(m.begin(), 0));
52 r = m.upper_bound(x: 5);
53 assert(r == std::next(m.begin(), 3));
54 r = m.upper_bound(x: 6);
55 assert(r == std::next(m.begin(), 3));
56 r = m.upper_bound(x: 7);
57 assert(r == std::next(m.begin(), 6));
58 r = m.upper_bound(x: 8);
59 assert(r == std::next(m.begin(), 6));
60 r = m.upper_bound(x: 9);
61 assert(r == std::next(m.begin(), 9));
62 r = m.upper_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.upper_bound(4);
75 assert(r == std::next(m.begin(), 0));
76 r = m.upper_bound(5);
77 assert(r == std::next(m.begin(), 3));
78 r = m.upper_bound(6);
79 assert(r == std::next(m.begin(), 3));
80 r = m.upper_bound(7);
81 assert(r == std::next(m.begin(), 6));
82 r = m.upper_bound(8);
83 assert(r == std::next(m.begin(), 6));
84 r = m.upper_bound(9);
85 assert(r == std::next(m.begin(), 9));
86 r = m.upper_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.upper_bound(4);
94 assert(r == std::next(m.begin(), 0));
95 r = m.upper_bound(5);
96 assert(r == std::next(m.begin(), 3));
97 r = m.upper_bound(6);
98 assert(r == std::next(m.begin(), 3));
99 r = m.upper_bound(7);
100 assert(r == std::next(m.begin(), 6));
101 r = m.upper_bound(8);
102 assert(r == std::next(m.begin(), 6));
103 r = m.upper_bound(9);
104 assert(r == std::next(m.begin(), 9));
105 r = m.upper_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 R r = m.upper_bound(4);
119 assert(r == std::next(m.begin(), 0));
120 r = m.upper_bound(5);
121 assert(r == std::next(m.begin(), 3));
122 r = m.upper_bound(6);
123 assert(r == std::next(m.begin(), 3));
124 r = m.upper_bound(7);
125 assert(r == std::next(m.begin(), 6));
126 r = m.upper_bound(8);
127 assert(r == std::next(m.begin(), 6));
128 r = m.upper_bound(9);
129 assert(r == std::next(m.begin(), 9));
130 r = m.upper_bound(11);
131 assert(r == std::next(m.begin(), 9));
132 }
133
134 {
135 typedef PrivateConstructor V;
136 typedef std::multiset<V, std::less<>> M;
137
138 typedef M::iterator R;
139 M m;
140 m.insert(V::make(5));
141 m.insert(V::make(5));
142 m.insert(V::make(5));
143 m.insert(V::make(7));
144 m.insert(V::make(7));
145 m.insert(V::make(7));
146 m.insert(V::make(9));
147 m.insert(V::make(9));
148 m.insert(V::make(9));
149
150 R r = m.upper_bound(4);
151 assert(r == std::next(m.begin(), 0));
152 r = m.upper_bound(5);
153 assert(r == std::next(m.begin(), 3));
154 r = m.upper_bound(6);
155 assert(r == std::next(m.begin(), 3));
156 r = m.upper_bound(7);
157 assert(r == std::next(m.begin(), 6));
158 r = m.upper_bound(8);
159 assert(r == std::next(m.begin(), 6));
160 r = m.upper_bound(9);
161 assert(r == std::next(m.begin(), 9));
162 r = m.upper_bound(11);
163 assert(r == std::next(m.begin(), 9));
164 }
165#endif
166
167 return 0;
168}
169

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