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 // UNSUPPORTED: libcpp-no-deduction-guides 12 13 // template<class InputIterator, 14 // class Compare = less<iter-value-type<InputIterator>>, 15 // class Allocator = allocator<iter-value-type<InputIterator>>> 16 // map(InputIterator, InputIterator, 17 // Compare = Compare(), Allocator = Allocator()) 18 // -> map<iter-value-type<InputIterator>, Compare, Allocator>; 19 // template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>> 20 // map(initializer_list<Key>, Compare = Compare(), Allocator = Allocator()) 21 // -> map<Key, Compare, Allocator>; 22 // template<class InputIterator, class Allocator> 23 // map(InputIterator, InputIterator, Allocator) 24 // -> map<iter-value-type<InputIterator>, less<iter-value-type<InputIterator>>, Allocator>; 25 // template<class Key, class Allocator> 26 // map(initializer_list<Key>, Allocator) 27 // -> map<Key, less<Key>, Allocator>; 28 29 #include <algorithm> // std::equal 30 #include <cassert> 31 #include <climits> // INT_MAX 32 #include <functional> 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 { 45 const PCC arr[] = { {1,1L}, {2,2L}, {1,1L}, {INT_MAX,1L}, {3,1L} }; 46 std::map m(std::begin(arr), std::end(arr)); 47 48 ASSERT_SAME_TYPE(decltype(m), std::map<int, const long>); 49 const PCC expected_m[] = { {1,1L}, {2,2L}, {3,1L}, {INT_MAX,1L} }; 50 assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); 51 } 52 53 { 54 const PCC arr[] = { {1,1L}, {2,2L}, {1,1L}, {INT_MAX,1L}, {3,1L} }; 55 std::map m(std::begin(arr), std::end(arr), std::greater<int>()); 56 57 ASSERT_SAME_TYPE(decltype(m), std::map<int, const long, std::greater<int>>); 58 const PCC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {1, 1L} }; 59 assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); 60 } 61 62 { 63 const PCC arr[] = { {1,1L}, {2,2L}, {1,1L}, {INT_MAX,1L}, {3,1L} }; 64 std::map m(std::begin(arr), std::end(arr), std::greater<int>(), test_allocator<PCC>(0, 42)); 65 66 ASSERT_SAME_TYPE(decltype(m), std::map<int, const long, std::greater<int>, test_allocator<PCC>>); 67 const PCC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {1, 1L} }; 68 assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); 69 assert(m.get_allocator().get_id() == 42); 70 } 71 72 { 73 std::map m{ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }; 74 75 ASSERT_SAME_TYPE(decltype(m), std::map<int, long>); 76 const PC expected_m[] = { {1, 1L}, {2,2L}, {3,1L}, {INT_MAX,1L} }; 77 assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); 78 } 79 80 { 81 std::map m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, std::greater<int>()); 82 83 ASSERT_SAME_TYPE(decltype(m), std::map<int, long, std::greater<int>>); 84 const PC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {1, 1L} }; 85 assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); 86 } 87 88 { 89 std::map m({ 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::map<int, long, std::greater<int>, test_allocator<PC>>); 92 const PC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {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::map 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::map<int, long, std::less<int>, test_allocator<PC>>); 101 const PC expected_m[] = { {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