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// <set>
11
12// class multiset
13
14//       iterator lower_bound(const key_type& k);
15// const_iterator lower_bound(const key_type& k) const;
16
17#include <set>
18#include <cassert>
19
20#include "test_macros.h"
21#include "min_allocator.h"
22#include "private_constructor.hpp"
23
24int main()
25{
26    {
27        typedef int V;
28        typedef std::multiset<int> M;
29        {
30            typedef M::iterator R;
31            V ar[] =
32            {
33                5,
34                5,
35                5,
36                7,
37                7,
38                7,
39                9,
40                9,
41                9
42            };
43            M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
44            R r = m.lower_bound(4);
45            assert(r == next(m.begin(), 0));
46            r = m.lower_bound(5);
47            assert(r == next(m.begin(), 0));
48            r = m.lower_bound(6);
49            assert(r == next(m.begin(), 3));
50            r = m.lower_bound(7);
51            assert(r == next(m.begin(), 3));
52            r = m.lower_bound(8);
53            assert(r == next(m.begin(), 6));
54            r = m.lower_bound(9);
55            assert(r == next(m.begin(), 6));
56            r = m.lower_bound(11);
57            assert(r == next(m.begin(), 9));
58        }
59        {
60            typedef M::const_iterator R;
61            V ar[] =
62            {
63                5,
64                5,
65                5,
66                7,
67                7,
68                7,
69                9,
70                9,
71                9
72            };
73            const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
74            R r = m.lower_bound(4);
75            assert(r == next(m.begin(), 0));
76            r = m.lower_bound(5);
77            assert(r == next(m.begin(), 0));
78            r = m.lower_bound(6);
79            assert(r == next(m.begin(), 3));
80            r = m.lower_bound(7);
81            assert(r == next(m.begin(), 3));
82            r = m.lower_bound(8);
83            assert(r == next(m.begin(), 6));
84            r = m.lower_bound(9);
85            assert(r == next(m.begin(), 6));
86            r = m.lower_bound(11);
87            assert(r == next(m.begin(), 9));
88        }
89    }
90#if TEST_STD_VER >= 11
91    {
92        typedef int V;
93        typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
94        {
95            typedef M::iterator R;
96            V ar[] =
97            {
98                5,
99                5,
100                5,
101                7,
102                7,
103                7,
104                9,
105                9,
106                9
107            };
108            M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
109            R r = m.lower_bound(4);
110            assert(r == next(m.begin(), 0));
111            r = m.lower_bound(5);
112            assert(r == next(m.begin(), 0));
113            r = m.lower_bound(6);
114            assert(r == next(m.begin(), 3));
115            r = m.lower_bound(7);
116            assert(r == next(m.begin(), 3));
117            r = m.lower_bound(8);
118            assert(r == next(m.begin(), 6));
119            r = m.lower_bound(9);
120            assert(r == next(m.begin(), 6));
121            r = m.lower_bound(11);
122            assert(r == next(m.begin(), 9));
123        }
124        {
125            typedef M::const_iterator R;
126            V ar[] =
127            {
128                5,
129                5,
130                5,
131                7,
132                7,
133                7,
134                9,
135                9,
136                9
137            };
138            const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
139            R r = m.lower_bound(4);
140            assert(r == next(m.begin(), 0));
141            r = m.lower_bound(5);
142            assert(r == next(m.begin(), 0));
143            r = m.lower_bound(6);
144            assert(r == next(m.begin(), 3));
145            r = m.lower_bound(7);
146            assert(r == next(m.begin(), 3));
147            r = m.lower_bound(8);
148            assert(r == next(m.begin(), 6));
149            r = m.lower_bound(9);
150            assert(r == next(m.begin(), 6));
151            r = m.lower_bound(11);
152            assert(r == next(m.begin(), 9));
153        }
154    }
155#endif
156#if TEST_STD_VER > 11
157    {
158    typedef int V;
159    typedef std::multiset<V, std::less<>> M;
160
161    typedef M::iterator R;
162    V ar[] =
163    {
164        5,
165        5,
166        5,
167        7,
168        7,
169        7,
170        9,
171        9,
172        9
173    };
174    M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
175
176    R r = m.lower_bound(4);
177    assert(r == next(m.begin(), 0));
178    r = m.lower_bound(5);
179    assert(r == next(m.begin(), 0));
180    r = m.lower_bound(6);
181    assert(r == next(m.begin(), 3));
182    r = m.lower_bound(7);
183    assert(r == next(m.begin(), 3));
184    r = m.lower_bound(8);
185    assert(r == next(m.begin(), 6));
186    r = m.lower_bound(9);
187    assert(r == next(m.begin(), 6));
188    r = m.lower_bound(11);
189    assert(r == next(m.begin(), 9));
190    }
191
192    {
193    typedef PrivateConstructor V;
194    typedef std::multiset<V, std::less<>> M;
195    typedef M::iterator R;
196
197    M m;
198    m.insert ( V::make ( 5 ));
199    m.insert ( V::make ( 5 ));
200    m.insert ( V::make ( 5 ));
201    m.insert ( V::make ( 7 ));
202    m.insert ( V::make ( 7 ));
203    m.insert ( V::make ( 7 ));
204    m.insert ( V::make ( 9 ));
205    m.insert ( V::make ( 9 ));
206    m.insert ( V::make ( 9 ));
207
208    R r = m.lower_bound(4);
209    assert(r == next(m.begin(), 0));
210    r = m.lower_bound(5);
211    assert(r == next(m.begin(), 0));
212    r = m.lower_bound(6);
213    assert(r == next(m.begin(), 3));
214    r = m.lower_bound(7);
215    assert(r == next(m.begin(), 3));
216    r = m.lower_bound(8);
217    assert(r == next(m.begin(), 6));
218    r = m.lower_bound(9);
219    assert(r == next(m.begin(), 6));
220    r = m.lower_bound(11);
221    assert(r == next(m.begin(), 9));
222    }
223#endif
224}
225