llvm-project
114 строк · 3.2 Кб
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// template <class InputIterator>
14// multimap(InputIterator first, InputIterator last);
15
16#include <map>17#include <cassert>18
19#include "test_macros.h"20#include "min_allocator.h"21
22int main(int, char**)23{
24{25typedef std::pair<const int, double> V;26V ar[] =27{28V(1, 1),29V(1, 1.5),30V(1, 2),31V(2, 1),32V(2, 1.5),33V(2, 2),34V(3, 1),35V(3, 1.5),36V(3, 2),37};38std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));39assert(m.size() == 9);40assert(std::distance(m.begin(), m.end()) == 9);41assert(*m.begin() == V(1, 1));42assert(*std::next(m.begin()) == V(1, 1.5));43assert(*std::next(m.begin(), 2) == V(1, 2));44assert(*std::next(m.begin(), 3) == V(2, 1));45assert(*std::next(m.begin(), 4) == V(2, 1.5));46assert(*std::next(m.begin(), 5) == V(2, 2));47assert(*std::next(m.begin(), 6) == V(3, 1));48assert(*std::next(m.begin(), 7) == V(3, 1.5));49assert(*std::next(m.begin(), 8) == V(3, 2));50}51#if TEST_STD_VER >= 1152{53typedef std::pair<const int, double> V;54V ar[] =55{56V(1, 1),57V(1, 1.5),58V(1, 2),59V(2, 1),60V(2, 1.5),61V(2, 2),62V(3, 1),63V(3, 1.5),64V(3, 2),65};66std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));67assert(m.size() == 9);68assert(std::distance(m.begin(), m.end()) == 9);69assert(*m.begin() == V(1, 1));70assert(*std::next(m.begin()) == V(1, 1.5));71assert(*std::next(m.begin(), 2) == V(1, 2));72assert(*std::next(m.begin(), 3) == V(2, 1));73assert(*std::next(m.begin(), 4) == V(2, 1.5));74assert(*std::next(m.begin(), 5) == V(2, 2));75assert(*std::next(m.begin(), 6) == V(3, 1));76assert(*std::next(m.begin(), 7) == V(3, 1.5));77assert(*std::next(m.begin(), 8) == V(3, 2));78}79#if TEST_STD_VER > 1180{81typedef std::pair<const int, double> V;82V ar[] =83{84V(1, 1),85V(1, 1.5),86V(1, 2),87V(2, 1),88V(2, 1.5),89V(2, 2),90V(3, 1),91V(3, 1.5),92V(3, 2),93};94typedef min_allocator<std::pair<const int, double>> A;95A a;96std::multimap<int, double, std::less<int>, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a);97assert(m.size() == 9);98assert(std::distance(m.begin(), m.end()) == 9);99assert(*m.begin() == V(1, 1));100assert(*std::next(m.begin()) == V(1, 1.5));101assert(*std::next(m.begin(), 2) == V(1, 2));102assert(*std::next(m.begin(), 3) == V(2, 1));103assert(*std::next(m.begin(), 4) == V(2, 1.5));104assert(*std::next(m.begin(), 5) == V(2, 2));105assert(*std::next(m.begin(), 6) == V(3, 1));106assert(*std::next(m.begin(), 7) == V(3, 1.5));107assert(*std::next(m.begin(), 8) == V(3, 2));108assert(m.get_allocator() == a);109}110#endif111#endif112
113return 0;114}
115