15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <map>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // class multimap
125a83710eSEric Fiselier 
135a83710eSEric Fiselier //       iterator upper_bound(const key_type& k);
145a83710eSEric Fiselier // const_iterator upper_bound(const key_type& k) const;
155a83710eSEric Fiselier 
165a83710eSEric Fiselier #include <map>
175a83710eSEric Fiselier #include <cassert>
185a83710eSEric Fiselier 
190f901c7eSStephan T. Lavavej #include "test_macros.h"
205a83710eSEric Fiselier #include "min_allocator.h"
21cc89063bSNico Weber #include "private_constructor.h"
22f8457a07SMarshall Clow #include "is_transparent.h"
235a83710eSEric Fiselier 
main(int,char **)242df59c50SJF Bastien int main(int, char**)
255a83710eSEric Fiselier {
265a83710eSEric Fiselier     typedef std::pair<const int, double> V;
275a83710eSEric Fiselier     {
285a83710eSEric Fiselier     typedef std::multimap<int, double> M;
295a83710eSEric Fiselier     {
305a83710eSEric Fiselier         typedef M::iterator R;
315a83710eSEric Fiselier         V ar[] =
325a83710eSEric Fiselier         {
335a83710eSEric Fiselier             V(5, 1),
345a83710eSEric Fiselier             V(5, 2),
355a83710eSEric Fiselier             V(5, 3),
365a83710eSEric Fiselier             V(7, 1),
375a83710eSEric Fiselier             V(7, 2),
385a83710eSEric Fiselier             V(7, 3),
395a83710eSEric Fiselier             V(9, 1),
405a83710eSEric Fiselier             V(9, 2),
415a83710eSEric Fiselier             V(9, 3)
425a83710eSEric Fiselier         };
435a83710eSEric Fiselier         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
445a83710eSEric Fiselier         R r = m.upper_bound(4);
455a83710eSEric Fiselier         assert(r == m.begin());
465a83710eSEric Fiselier         r = m.upper_bound(5);
47*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
485a83710eSEric Fiselier         r = m.upper_bound(6);
49*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
505a83710eSEric Fiselier         r = m.upper_bound(7);
51*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
525a83710eSEric Fiselier         r = m.upper_bound(8);
53*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
545a83710eSEric Fiselier         r = m.upper_bound(9);
55*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 9));
565a83710eSEric Fiselier         r = m.upper_bound(10);
575a83710eSEric Fiselier         assert(r == m.end());
585a83710eSEric Fiselier     }
595a83710eSEric Fiselier     {
605a83710eSEric Fiselier         typedef M::const_iterator R;
615a83710eSEric Fiselier         V ar[] =
625a83710eSEric Fiselier         {
635a83710eSEric Fiselier             V(5, 1),
645a83710eSEric Fiselier             V(5, 2),
655a83710eSEric Fiselier             V(5, 3),
665a83710eSEric Fiselier             V(7, 1),
675a83710eSEric Fiselier             V(7, 2),
685a83710eSEric Fiselier             V(7, 3),
695a83710eSEric Fiselier             V(9, 1),
705a83710eSEric Fiselier             V(9, 2),
715a83710eSEric Fiselier             V(9, 3)
725a83710eSEric Fiselier         };
735a83710eSEric Fiselier         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
745a83710eSEric Fiselier         R r = m.upper_bound(4);
755a83710eSEric Fiselier         assert(r == m.begin());
765a83710eSEric Fiselier         r = m.upper_bound(5);
77*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
785a83710eSEric Fiselier         r = m.upper_bound(6);
79*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
805a83710eSEric Fiselier         r = m.upper_bound(7);
81*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
825a83710eSEric Fiselier         r = m.upper_bound(8);
83*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
845a83710eSEric Fiselier         r = m.upper_bound(9);
85*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 9));
865a83710eSEric Fiselier         r = m.upper_bound(10);
875a83710eSEric Fiselier         assert(r == m.end());
885a83710eSEric Fiselier     }
895a83710eSEric Fiselier     }
90f2f2a639SEric Fiselier #if TEST_STD_VER >= 11
915a83710eSEric Fiselier     {
925a83710eSEric Fiselier     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
935a83710eSEric Fiselier     {
945a83710eSEric Fiselier         typedef M::iterator R;
955a83710eSEric Fiselier         V ar[] =
965a83710eSEric Fiselier         {
975a83710eSEric Fiselier             V(5, 1),
985a83710eSEric Fiselier             V(5, 2),
995a83710eSEric Fiselier             V(5, 3),
1005a83710eSEric Fiselier             V(7, 1),
1015a83710eSEric Fiselier             V(7, 2),
1025a83710eSEric Fiselier             V(7, 3),
1035a83710eSEric Fiselier             V(9, 1),
1045a83710eSEric Fiselier             V(9, 2),
1055a83710eSEric Fiselier             V(9, 3)
1065a83710eSEric Fiselier         };
1075a83710eSEric Fiselier         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
1085a83710eSEric Fiselier         R r = m.upper_bound(4);
1095a83710eSEric Fiselier         assert(r == m.begin());
1105a83710eSEric Fiselier         r = m.upper_bound(5);
111*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
1125a83710eSEric Fiselier         r = m.upper_bound(6);
113*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
1145a83710eSEric Fiselier         r = m.upper_bound(7);
115*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
1165a83710eSEric Fiselier         r = m.upper_bound(8);
117*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
1185a83710eSEric Fiselier         r = m.upper_bound(9);
119*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 9));
1205a83710eSEric Fiselier         r = m.upper_bound(10);
1215a83710eSEric Fiselier         assert(r == m.end());
1225a83710eSEric Fiselier     }
1235a83710eSEric Fiselier     {
1245a83710eSEric Fiselier         typedef M::const_iterator R;
1255a83710eSEric Fiselier         V ar[] =
1265a83710eSEric Fiselier         {
1275a83710eSEric Fiselier             V(5, 1),
1285a83710eSEric Fiselier             V(5, 2),
1295a83710eSEric Fiselier             V(5, 3),
1305a83710eSEric Fiselier             V(7, 1),
1315a83710eSEric Fiselier             V(7, 2),
1325a83710eSEric Fiselier             V(7, 3),
1335a83710eSEric Fiselier             V(9, 1),
1345a83710eSEric Fiselier             V(9, 2),
1355a83710eSEric Fiselier             V(9, 3)
1365a83710eSEric Fiselier         };
1375a83710eSEric Fiselier         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
1385a83710eSEric Fiselier         R r = m.upper_bound(4);
1395a83710eSEric Fiselier         assert(r == m.begin());
1405a83710eSEric Fiselier         r = m.upper_bound(5);
141*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
1425a83710eSEric Fiselier         r = m.upper_bound(6);
143*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 3));
1445a83710eSEric Fiselier         r = m.upper_bound(7);
145*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
1465a83710eSEric Fiselier         r = m.upper_bound(8);
147*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 6));
1485a83710eSEric Fiselier         r = m.upper_bound(9);
149*5ffe11a9SArthur O'Dwyer         assert(r == std::next(m.begin(), 9));
1505a83710eSEric Fiselier         r = m.upper_bound(10);
1515a83710eSEric Fiselier         assert(r == m.end());
1525a83710eSEric Fiselier     }
1535a83710eSEric Fiselier     }
1545a83710eSEric Fiselier #endif
1550f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
1565a83710eSEric Fiselier     {
1575a83710eSEric Fiselier     typedef std::multimap<int, double, std::less<>> M;
1585a83710eSEric Fiselier     typedef M::iterator R;
1595a83710eSEric Fiselier     V ar[] =
1605a83710eSEric Fiselier     {
1615a83710eSEric Fiselier         V(5, 1),
1625a83710eSEric Fiselier         V(5, 2),
1635a83710eSEric Fiselier         V(5, 3),
1645a83710eSEric Fiselier         V(7, 1),
1655a83710eSEric Fiselier         V(7, 2),
1665a83710eSEric Fiselier         V(7, 3),
1675a83710eSEric Fiselier         V(9, 1),
1685a83710eSEric Fiselier         V(9, 2),
1695a83710eSEric Fiselier         V(9, 3)
1705a83710eSEric Fiselier     };
1715a83710eSEric Fiselier     M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
1725a83710eSEric Fiselier     R r = m.upper_bound(4);
1735a83710eSEric Fiselier     assert(r == m.begin());
1745a83710eSEric Fiselier     r = m.upper_bound(5);
175*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
1765a83710eSEric Fiselier     r = m.upper_bound(6);
177*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
1785a83710eSEric Fiselier     r = m.upper_bound(7);
179*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
1805a83710eSEric Fiselier     r = m.upper_bound(8);
181*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
1825a83710eSEric Fiselier     r = m.upper_bound(9);
183*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 9));
1845a83710eSEric Fiselier     r = m.upper_bound(10);
1855a83710eSEric Fiselier     assert(r == m.end());
186f8457a07SMarshall Clow 
187f8457a07SMarshall Clow     r = m.upper_bound(C2Int(4));
188f8457a07SMarshall Clow     assert(r == m.begin());
189f8457a07SMarshall Clow     r = m.upper_bound(C2Int(5));
190*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
191f8457a07SMarshall Clow     r = m.upper_bound(C2Int(6));
192*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
193f8457a07SMarshall Clow     r = m.upper_bound(C2Int(7));
194*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
195f8457a07SMarshall Clow     r = m.upper_bound(C2Int(8));
196*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
197f8457a07SMarshall Clow     r = m.upper_bound(C2Int(9));
198*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 9));
199f8457a07SMarshall Clow     r = m.upper_bound(C2Int(10));
2005a83710eSEric Fiselier     }
2015a83710eSEric Fiselier 
2025a83710eSEric Fiselier     {
2035a83710eSEric Fiselier     typedef PrivateConstructor PC;
2045a83710eSEric Fiselier     typedef std::multimap<PC, double, std::less<>> M;
2055a83710eSEric Fiselier     typedef M::iterator R;
2065a83710eSEric Fiselier 
2075a83710eSEric Fiselier     M m;
2085a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
2095a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
2105a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
2115a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
2125a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
2135a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
2145a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
2155a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
2165a83710eSEric Fiselier     m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
2175a83710eSEric Fiselier 
2185a83710eSEric Fiselier     R r = m.upper_bound(4);
2195a83710eSEric Fiselier     assert(r == m.begin());
2205a83710eSEric Fiselier     r = m.upper_bound(5);
221*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
2225a83710eSEric Fiselier     r = m.upper_bound(6);
223*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 3));
2245a83710eSEric Fiselier     r = m.upper_bound(7);
225*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
2265a83710eSEric Fiselier     r = m.upper_bound(8);
227*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 6));
2285a83710eSEric Fiselier     r = m.upper_bound(9);
229*5ffe11a9SArthur O'Dwyer     assert(r == std::next(m.begin(), 9));
2305a83710eSEric Fiselier     r = m.upper_bound(10);
2315a83710eSEric Fiselier     assert(r == m.end());
2325a83710eSEric Fiselier     }
2335a83710eSEric Fiselier 
2345a83710eSEric Fiselier #endif
2352df59c50SJF Bastien 
2362df59c50SJF Bastien   return 0;
2375a83710eSEric Fiselier }
238