//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // UNSUPPORTED: c++03, c++11, c++14 // template>, // class Allocator = allocator>> // multimap(InputIterator, InputIterator, // Compare = Compare(), Allocator = Allocator()) // -> multimap, Compare, Allocator>; // template, class Allocator = allocator> // multimap(initializer_list, Compare = Compare(), Allocator = Allocator()) // -> multimap; // template // multimap(InputIterator, InputIterator, Allocator) // -> multimap, less>, Allocator>; // template // multimap(initializer_list, Allocator) // -> multimap, Allocator>; // // template>, // class Allocator = allocator>> // multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator()) // -> multimap, range-mapped-type, Compare, Allocator>; // C++23 // // template // multimap(from_range_t, R&&, Allocator) // -> multimap, range-mapped-type, less>, Allocator>; // C++23 #include // std::equal #include #include #include // INT_MAX #include #include #include #include #include #include #include "deduction_guides_sfinae_checks.h" #include "test_allocator.h" using P = std::pair; using PC = std::pair; int main(int, char**) { { const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; std::multimap m(std::begin(arr), std::end(arr)); ASSERT_SAME_TYPE(decltype(m), std::multimap); const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); } { const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; std::multimap m(std::begin(arr), std::end(arr), std::greater()); ASSERT_SAME_TYPE(decltype(m), std::multimap>); const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); } { const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; std::multimap m(std::begin(arr), std::end(arr), std::greater(), test_allocator(0, 42)); ASSERT_SAME_TYPE(decltype(m), std::multimap, test_allocator>); const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); assert(m.get_allocator().get_id() == 42); } { std::multimap source; std::multimap m(source); ASSERT_SAME_TYPE(decltype(m), decltype(source)); assert(m.size() == 0); } { std::multimap source; std::multimap m{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(m), decltype(source)); assert(m.size() == 0); } { std::multimap source; std::multimap m(source, std::map::allocator_type()); ASSERT_SAME_TYPE(decltype(m), decltype(source)); assert(m.size() == 0); } { std::multimap m{P{1, 1L}, P{2, 2L}, P{1, 1L}, P{INT_MAX, 1L}, P{3, 1L}}; ASSERT_SAME_TYPE(decltype(m), std::multimap); const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); } { std::multimap m({P{1, 1L}, P{2, 2L}, P{1, 1L}, P{INT_MAX, 1L}, P{3, 1L}}, std::greater()); ASSERT_SAME_TYPE(decltype(m), std::multimap>); const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); } { std::multimap m( {P{1, 1L}, P{2, 2L}, P{1, 1L}, P{INT_MAX, 1L}, P{3, 1L}}, std::greater(), test_allocator(0, 43)); ASSERT_SAME_TYPE(decltype(m), std::multimap, test_allocator>); const PC expected_m[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); assert(m.get_allocator().get_id() == 43); } { const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}; std::multimap m(std::begin(arr), std::end(arr), test_allocator(0, 44)); ASSERT_SAME_TYPE(decltype(m), std::multimap, test_allocator>); const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); assert(m.get_allocator().get_id() == 44); } { std::multimap m({P{1, 1L}, P{2, 2L}, P{1, 1L}, P{INT_MAX, 1L}, P{3, 1L}}, test_allocator(0, 45)); ASSERT_SAME_TYPE(decltype(m), std::multimap, test_allocator>); const PC expected_m[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}}; assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); assert(m.get_allocator().get_id() == 45); } { // Examples from LWG3025 std::multimap m{std::pair{1, 1}, {2, 2}, {3, 3}}; ASSERT_SAME_TYPE(decltype(m), std::multimap); std::multimap m2{m.begin(), m.end()}; ASSERT_SAME_TYPE(decltype(m2), std::multimap); } { // Examples from LWG3531 std::multimap m1{{std::pair{1, 2}, {3, 4}}, std::less()}; ASSERT_SAME_TYPE(decltype(m1), std::multimap); using value_type = std::pair; std::multimap m2{{value_type{1, 2}, {3, 4}}, std::less()}; ASSERT_SAME_TYPE(decltype(m2), std::multimap); } #if TEST_STD_VER >= 23 { using Range = std::array; using Comp = std::greater; using DefaultComp = std::less; using Alloc = test_allocator; { // (from_range, range) std::multimap c(std::from_range, Range()); static_assert(std::is_same_v>); } { // (from_range, range, comp) std::multimap c(std::from_range, Range(), Comp()); static_assert(std::is_same_v>); } { // (from_range, range, comp, alloc) std::multimap c(std::from_range, Range(), Comp(), Alloc()); static_assert(std::is_same_v>); } { // (from_range, range, alloc) std::multimap c(std::from_range, Range(), Alloc()); static_assert(std::is_same_v>); } } { std::vector> pair_vec = {{1, 1.1f}, {2, 2.2f}, {3, 3.3f}}; std::multimap mm1(pair_vec.begin(), pair_vec.end()); ASSERT_SAME_TYPE(decltype(mm1), std::multimap); std::vector> tuple_vec = {{10, 1.1}, {20, 2.2}, {30, 3.3}}; std::multimap mm2(tuple_vec.begin(), tuple_vec.end()); ASSERT_SAME_TYPE(decltype(mm2), std::multimap); std::vector> array_vec = {{100L, 101L}, {200L, 201L}, {300L, 301L}}; std::multimap mm3(array_vec.begin(), array_vec.end()); ASSERT_SAME_TYPE(decltype(mm3), std::multimap); // Check deduction with non-const key in input pair std::vector> non_const_key_pair_vec = {{5, 'a'}, {6, 'b'}}; std::multimap mm4(non_const_key_pair_vec.begin(), non_const_key_pair_vec.end()); ASSERT_SAME_TYPE(decltype(mm4), std::multimap); } #endif AssociativeContainerDeductionGuidesSfinaeAway>(); return 0; }