// { dg-do compile { target c++17 } } #include #include using __gnu_test::SimpleAllocator; static_assert(std::is_same_v< decltype(std::unordered_map{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{ {std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, 1}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}, std::hash{}, std::equal_to{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}, std::hash{}, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}, {}, {}, SimpleAllocator>{}}), std::unordered_map, std::equal_to, SimpleAllocator>>>); void f() { std::unordered_map x; static_assert(std::is_same_v< decltype(std::unordered_map(x.begin(), x.end())), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), {}, std::hash{}, {}, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), {}, std::hash{}, std::equal_to{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), {}, std::hash{}, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map(x.begin(), x.end(), {})), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), 1}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), 1, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), 1, SimpleAllocator>{}}), std::unordered_map, std::equal_to, SimpleAllocator>>>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), 1, std::hash{}, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), 1, std::hash{}, SimpleAllocator>{}}), std::unordered_map, std::equal_to, SimpleAllocator>>>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), {}, {}, {}, std::allocator>{}}), std::unordered_map>); static_assert(std::is_same_v< decltype(std::unordered_map{x.begin(), x.end(), {}, {}, {}, SimpleAllocator>{}}), std::unordered_map, std::equal_to, SimpleAllocator>>>); } template struct require_same; template struct require_same { using type = void; }; template typename require_same::type check_type(U&) { } struct Pool; template struct Alloc : __gnu_test::SimpleAllocator { Alloc(Pool*) { } template Alloc(const Alloc&) { } }; void test_p1518r2() { // P1518R2 - Stop overconstraining allocators in container deduction guides. // This is a C++23 feature but we support it for C++17 too. using PairAlloc = Alloc>; using Hash = std::hash; using Eq = std::equal_to<>; using UMap = std::unordered_map; Pool* p = nullptr; UMap m(p); std::unordered_map s1(m, p); check_type(s1); std::unordered_map s2(std::move(m), p); check_type(s2); }