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