111 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// 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 typedef std::pair<const int, double> V;25 V ar[] = {26 V(1, 1),27 V(1, 1.5),28 V(1, 2),29 V(2, 1),30 V(2, 1.5),31 V(2, 2),32 V(3, 1),33 V(3, 1.5),34 V(3, 2),35 };36 std::multimap<int, double> m(ar, ar + sizeof(ar) / sizeof(ar[0]));37 assert(m.size() == 9);38 assert(std::distance(m.begin(), m.end()) == 9);39 assert(*m.begin() == V(1, 1));40 assert(*std::next(m.begin()) == V(1, 1.5));41 assert(*std::next(m.begin(), 2) == V(1, 2));42 assert(*std::next(m.begin(), 3) == V(2, 1));43 assert(*std::next(m.begin(), 4) == V(2, 1.5));44 assert(*std::next(m.begin(), 5) == V(2, 2));45 assert(*std::next(m.begin(), 6) == V(3, 1));46 assert(*std::next(m.begin(), 7) == V(3, 1.5));47 assert(*std::next(m.begin(), 8) == V(3, 2));48 }49#if TEST_STD_VER >= 1150 {51 typedef std::pair<const int, double> V;52 V ar[] = {53 V(1, 1),54 V(1, 1.5),55 V(1, 2),56 V(2, 1),57 V(2, 1.5),58 V(2, 2),59 V(3, 1),60 V(3, 1.5),61 V(3, 2),62 };63 std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar + sizeof(ar) / sizeof(ar[0]));64 assert(m.size() == 9);65 assert(std::distance(m.begin(), m.end()) == 9);66 assert(*m.begin() == V(1, 1));67 assert(*std::next(m.begin()) == V(1, 1.5));68 assert(*std::next(m.begin(), 2) == V(1, 2));69 assert(*std::next(m.begin(), 3) == V(2, 1));70 assert(*std::next(m.begin(), 4) == V(2, 1.5));71 assert(*std::next(m.begin(), 5) == V(2, 2));72 assert(*std::next(m.begin(), 6) == V(3, 1));73 assert(*std::next(m.begin(), 7) == V(3, 1.5));74 assert(*std::next(m.begin(), 8) == V(3, 2));75 }76# if TEST_STD_VER > 1177 {78 typedef std::pair<const int, double> V;79 V ar[] = {80 V(1, 1),81 V(1, 1.5),82 V(1, 2),83 V(2, 1),84 V(2, 1.5),85 V(2, 2),86 V(3, 1),87 V(3, 1.5),88 V(3, 2),89 };90 typedef min_allocator<std::pair<const int, double>> A;91 A a;92 std::multimap<int, double, std::less<int>, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), a);93 assert(m.size() == 9);94 assert(std::distance(m.begin(), m.end()) == 9);95 assert(*m.begin() == V(1, 1));96 assert(*std::next(m.begin()) == V(1, 1.5));97 assert(*std::next(m.begin(), 2) == V(1, 2));98 assert(*std::next(m.begin(), 3) == V(2, 1));99 assert(*std::next(m.begin(), 4) == V(2, 1.5));100 assert(*std::next(m.begin(), 5) == V(2, 2));101 assert(*std::next(m.begin(), 6) == V(3, 1));102 assert(*std::next(m.begin(), 7) == V(3, 1.5));103 assert(*std::next(m.begin(), 8) == V(3, 2));104 assert(m.get_allocator() == a);105 }106# endif107#endif108 109 return 0;110}111