| 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 | // UNSUPPORTED: c++03, c++11, c++14 |
| 11 | |
| 12 | // template<class InputIterator, |
| 13 | // class Compare = less<iter-value-type<InputIterator>>, |
| 14 | // class Allocator = allocator<iter-value-type<InputIterator>>> |
| 15 | // multimap(InputIterator, InputIterator, |
| 16 | // Compare = Compare(), Allocator = Allocator()) |
| 17 | // -> multimap<iter-value-type<InputIterator>, Compare, Allocator>; |
| 18 | // template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>> |
| 19 | // multimap(initializer_list<Key>, Compare = Compare(), Allocator = Allocator()) |
| 20 | // -> multimap<Key, Compare, Allocator>; |
| 21 | // template<class InputIterator, class Allocator> |
| 22 | // multimap(InputIterator, InputIterator, Allocator) |
| 23 | // -> multimap<iter-value-type<InputIterator>, less<iter-value-type<InputIterator>>, Allocator>; |
| 24 | // template<class Key, class Allocator> |
| 25 | // multimap(initializer_list<Key>, Allocator) |
| 26 | // -> multimap<Key, less<Key>, Allocator>; |
| 27 | |
| 28 | #include <algorithm> // std::equal |
| 29 | #include <cassert> |
| 30 | #include <climits> // INT_MAX |
| 31 | #include <functional> |
| 32 | #include <iterator> |
| 33 | #include <map> |
| 34 | #include <type_traits> |
| 35 | |
| 36 | #include "test_allocator.h" |
| 37 | |
| 38 | using P = std::pair<int, long>; |
| 39 | using PC = std::pair<const int, long>; |
| 40 | using PCC = std::pair<const int, const long>; |
| 41 | |
| 42 | int main(int, char**) { |
| 43 | { |
| 44 | const PCC arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; |
| 45 | std::multimap m(std::begin(arr: arr), std::end(arr: arr)); |
| 46 | |
| 47 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, const long>); |
| 48 | const PCC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; |
| 49 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 50 | } |
| 51 | |
| 52 | { |
| 53 | const PCC arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; |
| 54 | std::multimap m(std::begin(arr: arr), std::end(arr: arr), std::greater<int>()); |
| 55 | |
| 56 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, const long, std::greater<int>>); |
| 57 | const PCC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; |
| 58 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 59 | } |
| 60 | |
| 61 | { |
| 62 | const PCC arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; |
| 63 | std::multimap m(std::begin(arr: arr), std::end(arr: arr), std::greater<int>(), test_allocator<PCC>(0, 42)); |
| 64 | |
| 65 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, const long, std::greater<int>, test_allocator<PCC>>); |
| 66 | const PCC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; |
| 67 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 68 | assert(m.get_allocator().get_id() == 42); |
| 69 | } |
| 70 | |
| 71 | { |
| 72 | std::multimap m{PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}; |
| 73 | |
| 74 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, long>); |
| 75 | const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; |
| 76 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | std::multimap m({PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, std::greater<int>()); |
| 81 | |
| 82 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, long, std::greater<int>>); |
| 83 | const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; |
| 84 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 85 | } |
| 86 | |
| 87 | { |
| 88 | std::multimap m( |
| 89 | {PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, std::greater<int>(), test_allocator<PC>(0, 43)); |
| 90 | |
| 91 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, long, std::greater<int>, test_allocator<PC>>); |
| 92 | const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; |
| 93 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 94 | assert(m.get_allocator().get_id() == 43); |
| 95 | } |
| 96 | |
| 97 | { |
| 98 | std::multimap m({PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, test_allocator<PC>(0, 45)); |
| 99 | |
| 100 | ASSERT_SAME_TYPE(decltype(m), std::multimap<int, long, std::less<int>, test_allocator<PC>>); |
| 101 | const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; |
| 102 | assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 103 | assert(m.get_allocator().get_id() == 45); |
| 104 | } |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |