182 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <map>10 11// class multimap12 13// iterator upper_bound(const key_type& k);14// const_iterator upper_bound(const key_type& k) const;15 16#include <map>17#include <cassert>18 19#include "test_macros.h"20#include "min_allocator.h"21#include "private_constructor.h"22#include "is_transparent.h"23 24int main(int, char**) {25 typedef std::pair<const int, double> V;26 {27 typedef std::multimap<int, double> M;28 {29 typedef M::iterator R;30 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};31 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));32 R r = m.upper_bound(4);33 assert(r == m.begin());34 r = m.upper_bound(5);35 assert(r == std::next(m.begin(), 3));36 r = m.upper_bound(6);37 assert(r == std::next(m.begin(), 3));38 r = m.upper_bound(7);39 assert(r == std::next(m.begin(), 6));40 r = m.upper_bound(8);41 assert(r == std::next(m.begin(), 6));42 r = m.upper_bound(9);43 assert(r == std::next(m.begin(), 9));44 r = m.upper_bound(10);45 assert(r == m.end());46 }47 {48 typedef M::const_iterator R;49 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};50 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));51 R r = m.upper_bound(4);52 assert(r == m.begin());53 r = m.upper_bound(5);54 assert(r == std::next(m.begin(), 3));55 r = m.upper_bound(6);56 assert(r == std::next(m.begin(), 3));57 r = m.upper_bound(7);58 assert(r == std::next(m.begin(), 6));59 r = m.upper_bound(8);60 assert(r == std::next(m.begin(), 6));61 r = m.upper_bound(9);62 assert(r == std::next(m.begin(), 9));63 r = m.upper_bound(10);64 assert(r == m.end());65 }66 }67#if TEST_STD_VER >= 1168 {69 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;70 {71 typedef M::iterator R;72 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};73 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));74 R r = m.upper_bound(4);75 assert(r == m.begin());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(10);87 assert(r == m.end());88 }89 {90 typedef M::const_iterator R;91 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};92 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));93 R r = m.upper_bound(4);94 assert(r == m.begin());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(10);106 assert(r == m.end());107 }108 }109#endif110#if TEST_STD_VER > 11111 {112 typedef std::multimap<int, double, std::less<>> M;113 typedef M::iterator R;114 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};115 M m(ar, ar + sizeof(ar) / sizeof(ar[0]));116 R r = m.upper_bound(4);117 assert(r == m.begin());118 r = m.upper_bound(5);119 assert(r == std::next(m.begin(), 3));120 r = m.upper_bound(6);121 assert(r == std::next(m.begin(), 3));122 r = m.upper_bound(7);123 assert(r == std::next(m.begin(), 6));124 r = m.upper_bound(8);125 assert(r == std::next(m.begin(), 6));126 r = m.upper_bound(9);127 assert(r == std::next(m.begin(), 9));128 r = m.upper_bound(10);129 assert(r == m.end());130 131 r = m.upper_bound(C2Int(4));132 assert(r == m.begin());133 r = m.upper_bound(C2Int(5));134 assert(r == std::next(m.begin(), 3));135 r = m.upper_bound(C2Int(6));136 assert(r == std::next(m.begin(), 3));137 r = m.upper_bound(C2Int(7));138 assert(r == std::next(m.begin(), 6));139 r = m.upper_bound(C2Int(8));140 assert(r == std::next(m.begin(), 6));141 r = m.upper_bound(C2Int(9));142 assert(r == std::next(m.begin(), 9));143 r = m.upper_bound(C2Int(10));144 }145 146 {147 typedef PrivateConstructor PC;148 typedef std::multimap<PC, double, std::less<>> M;149 typedef M::iterator R;150 151 M m;152 m.insert(std::make_pair<PC, double>(PC::make(5), 1));153 m.insert(std::make_pair<PC, double>(PC::make(5), 2));154 m.insert(std::make_pair<PC, double>(PC::make(5), 3));155 m.insert(std::make_pair<PC, double>(PC::make(7), 1));156 m.insert(std::make_pair<PC, double>(PC::make(7), 2));157 m.insert(std::make_pair<PC, double>(PC::make(7), 3));158 m.insert(std::make_pair<PC, double>(PC::make(9), 1));159 m.insert(std::make_pair<PC, double>(PC::make(9), 2));160 m.insert(std::make_pair<PC, double>(PC::make(9), 3));161 162 R r = m.upper_bound(4);163 assert(r == m.begin());164 r = m.upper_bound(5);165 assert(r == std::next(m.begin(), 3));166 r = m.upper_bound(6);167 assert(r == std::next(m.begin(), 3));168 r = m.upper_bound(7);169 assert(r == std::next(m.begin(), 6));170 r = m.upper_bound(8);171 assert(r == std::next(m.begin(), 6));172 r = m.upper_bound(9);173 assert(r == std::next(m.begin(), 9));174 r = m.upper_bound(10);175 assert(r == m.end());176 }177 178#endif179 180 return 0;181}182