
This implements the C++23 P1518R2 proposal "Stop overconstraining allocators in container deduction guides" as a fix for C++17 and C++20 too. The changes allow class template argument deduction to ignore the type of a constructor argument that initializes an allocator_type parameter if the type should be deducible only from the other arguments. So for the constructor vector(const vector&, const allocator_type&) only the first argument is used for deduction, allowing the second argument to be anything that is implicitly convertible to argument_type. Previously deduction would fail or an ill-formed type would be deduced if the second argument wasn't of type allocator_type. The unordered containers do not need changes, because their allocator-extended constructors use the allocator_type alias, which comes from the dependent base class so is already a non-deduced context. libstdc++-v3/ChangeLog: * include/bits/forward_list.h (forward_list): Use non-deduced context for allocator parameter of allocator-extended copy and move constructors. * include/bits/stl_bvector.h (vector<bool>): Likewise. * include/bits/stl_deque.h (deque): Likewise. * include/bits/stl_list.h (list): Likewise. * include/bits/stl_map.h (map): Likewise. * include/bits/stl_multimap.h (multimap): Likewise. * include/bits/stl_multiset.h (multiset): Likewise. * include/bits/stl_set.h (set): Likewise. * include/bits/stl_vector.h (vector): Likewise. * include/bits/stl_queue.h (queue, priority_queue): Do not constrain Allocator template parameter of deduction guides that have a Container parameter. * include/bits/stl_stack.h (stack): Likewise. * include/debug/deque (__gnu_debug::deque): Use non-deduced context for allocator parameter of allocator-extended copy and move constructors. * include/debug/list (__gnu_debug::list): Likewise. * include/debug/map.h (__gnu_debug::map): Likewise. * include/debug/multimap.h (__gnu_debug::multimap): Likewise. * include/debug/multiset.h (__gnu_debug::multiset): Likewise. * include/debug/set.h (__gnu_debug::set): Likewise. * include/debug/vector (__gnu_debug::vector): Likewise. * testsuite/23_containers/deque/cons/deduction.cc: Test class template argument deduction with non-deduced allocator arguments. * testsuite/23_containers/forward_list/cons/deduction.cc: Likewise. * testsuite/23_containers/list/cons/deduction.cc: Likewise. * testsuite/23_containers/map/cons/deduction.cc: Likewise. * testsuite/23_containers/multimap/cons/deduction.cc: Likewise. * testsuite/23_containers/multiset/cons/deduction.cc: Likewise. * testsuite/23_containers/priority_queue/deduction.cc: Likewise. * testsuite/23_containers/queue/deduction.cc: Likewise. * testsuite/23_containers/set/cons/deduction.cc: Likewise. * testsuite/23_containers/stack/deduction.cc: Likewise. * testsuite/23_containers/unordered_map/cons/deduction.cc: Likewise. * testsuite/23_containers/unordered_multimap/cons/deduction.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/deduction.cc: Likewise. * testsuite/23_containers/unordered_set/cons/deduction.cc: Likewise. * testsuite/23_containers/vector/cons/deduction.cc: Likewise.
167 lines
4.3 KiB
C++
167 lines
4.3 KiB
C++
// { dg-do compile { target c++17 } }
|
|
|
|
#include <set>
|
|
#include <testsuite_allocator.h>
|
|
#include <testsuite_iterators.h>
|
|
|
|
using __gnu_test::SimpleAllocator;
|
|
using value_type = std::multiset<int>::value_type;
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{1, 2, 3}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{1, 2, 3}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{{1, 2, 3}, std::less<int>{}, {}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{{1, 2, 3}, std::less<int>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{{1, 2, 3}, SimpleAllocator<int>{}}),
|
|
std::multiset<int, std::less<int>, SimpleAllocator<int>>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{{1, 2, 3}, {}, SimpleAllocator<int>{}}),
|
|
std::multiset<int, std::less<int>, SimpleAllocator<int>>>);
|
|
|
|
void f()
|
|
{
|
|
std::multiset<int> x;
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset(x.begin(), x.end())),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::less<int>{},
|
|
std::allocator<int>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::less<int>{}, {}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset(x.begin(), x.end(),
|
|
std::less<int>{})),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::allocator<int>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
SimpleAllocator<int>{}}),
|
|
std::multiset<int, std::less<int>, SimpleAllocator<int>>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
{},
|
|
std::allocator<int>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
{},
|
|
SimpleAllocator<int>{}}),
|
|
std::multiset<int, std::less<int>, SimpleAllocator<int>>>);
|
|
}
|
|
|
|
using __gnu_test::test_container;
|
|
using __gnu_test::input_iterator_wrapper;
|
|
|
|
void g()
|
|
{
|
|
value_type array[1];
|
|
test_container<value_type, input_iterator_wrapper> x(array);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset(x.begin(), x.end())),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::less<int>{},
|
|
std::allocator<value_type>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::less<int>{}, {}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset(x.begin(), x.end(),
|
|
std::less<int>{})),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
std::allocator<value_type>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
SimpleAllocator<value_type>{}}),
|
|
std::multiset<int, std::less<int>,
|
|
SimpleAllocator<value_type>>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
{},
|
|
std::allocator<value_type>{}}),
|
|
std::multiset<int>>);
|
|
|
|
static_assert(std::is_same_v<
|
|
decltype(std::multiset{x.begin(), x.end(),
|
|
{},
|
|
SimpleAllocator<value_type>{}}),
|
|
std::multiset<int, std::less<int>,
|
|
SimpleAllocator<value_type>>>);
|
|
}
|
|
|
|
template<typename T, typename U> struct require_same;
|
|
template<typename T> struct require_same<T, T> { using type = void; };
|
|
|
|
template<typename T, typename U>
|
|
typename require_same<T, U>::type
|
|
check_type(U&) { }
|
|
|
|
struct Pool;
|
|
|
|
template<typename T>
|
|
struct Alloc : __gnu_test::SimpleAllocator<T>
|
|
{
|
|
Alloc(Pool*) { }
|
|
|
|
template<typename U>
|
|
Alloc(const Alloc<U>&) { }
|
|
};
|
|
|
|
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 MSet = std::multiset<unsigned, std::greater<>, Alloc<unsigned>>;
|
|
Pool* p = nullptr;
|
|
MSet s(p);
|
|
|
|
std::multiset s1(s, p);
|
|
check_type<MSet>(s1);
|
|
|
|
std::multiset s2(std::move(s), p);
|
|
check_type<MSet>(s2);
|
|
}
|