From 08abbddaaa7e41f0586c641f883b7c2c8bb742e0 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 26 Feb 2019 23:12:44 +0000 Subject: [PATCH] PR libstdc++/89477 constrain deduction guides for maps and sets The Compare, Hash, and Pred template parameters should be constrained in the C++17 deduction guides for associative and unordered containers. The deduction guides for stack, queue and priority_queue are already constrained, but this patch makes them use the _RequireNotAllocator helper instead of reproducing the logic each time. PR libstdc++/89477 * include/bits/alloc_traits.h (_RequireNotAllocator): New helper for container deduction guides. * include/bits/hashtable.h (_RequireNotAllocatorOrIntegral): Likewise. * include/bits/stl_map.h (map): Use _RequireNotAllocator to constrain parameters in deduction guides. * include/bits/stl_multimap.h (multimap): Likewise. * include/bits/stl_multiset.h (multiset): Likewise. * include/bits/stl_queue.h (queue, priority_queue): Likewise. * include/bits/stl_set.h (set): Likewise. * include/bits/stl_stack.h (stack): Likewise. * include/bits/unordered_map.h (unordered_map, unordered_multimap): use _RequireNotAllocator and _RequireNotAllocatorOrIntegral to constrain parameters in deduction guides. * include/bits/unordered_set.h (unordered_set, unordered_multiset): Likewise. * testsuite/23_containers/map/cons/deduction.cc: Test additional deduction cases. * testsuite/23_containers/multiset/cons/deduction.cc: Likewise. * testsuite/23_containers/set/cons/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. From-SVN: r269234 --- libstdc++-v3/ChangeLog | 27 ++++++++ libstdc++-v3/include/bits/alloc_traits.h | 4 ++ libstdc++-v3/include/bits/hashtable.h | 7 ++ libstdc++-v3/include/bits/stl_map.h | 2 + libstdc++-v3/include/bits/stl_multimap.h | 2 + libstdc++-v3/include/bits/stl_multiset.h | 52 +++++++------- libstdc++-v3/include/bits/stl_queue.h | 20 +++--- libstdc++-v3/include/bits/stl_set.h | 2 + libstdc++-v3/include/bits/stl_stack.h | 6 +- libstdc++-v3/include/bits/unordered_map.h | 12 ++++ libstdc++-v3/include/bits/unordered_set.h | 24 +++++-- .../testsuite/23_containers/map/cons/deduction.cc | 50 +++++++++++++ .../23_containers/multiset/cons/deduction.cc | 81 +++++++++++++++++++--- .../testsuite/23_containers/set/cons/deduction.cc | 66 ++++++++++++++++++ .../23_containers/unordered_map/cons/deduction.cc | 41 ++++++++++- .../unordered_multimap/cons/deduction.cc | 56 +++++++++++++-- .../unordered_multiset/cons/deduction.cc | 65 +++++++++++++++-- .../23_containers/unordered_set/cons/deduction.cc | 60 ++++++++++++++-- 18 files changed, 512 insertions(+), 65 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d6ae322..e2f44b3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,32 @@ 2019-02-26 Jonathan Wakely + PR libstdc++/89477 + * include/bits/alloc_traits.h (_RequireNotAllocator): New helper for + container deduction guides. + * include/bits/hashtable.h (_RequireNotAllocatorOrIntegral): Likewise. + * include/bits/stl_map.h (map): Use _RequireNotAllocator to constrain + parameters in deduction guides. + * include/bits/stl_multimap.h (multimap): Likewise. + * include/bits/stl_multiset.h (multiset): Likewise. + * include/bits/stl_queue.h (queue, priority_queue): Likewise. + * include/bits/stl_set.h (set): Likewise. + * include/bits/stl_stack.h (stack): Likewise. + * include/bits/unordered_map.h (unordered_map, unordered_multimap): + use _RequireNotAllocator and _RequireNotAllocatorOrIntegral to + constrain parameters in deduction guides. + * include/bits/unordered_set.h (unordered_set, unordered_multiset): + Likewise. + * testsuite/23_containers/map/cons/deduction.cc: Test additional + deduction cases. + * testsuite/23_containers/multiset/cons/deduction.cc: Likewise. + * testsuite/23_containers/set/cons/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. + PR libstdc++/89416 * include/bits/alloc_traits.h (__is_alloc_insertable_impl): Change to class template and partial specialization using void_t. diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index b8689da..cda768b 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -634,6 +634,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using _RequireAllocator = typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type; + template + using _RequireNotAllocator + = typename enable_if::value, _Alloc>::type; + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 31794fb..4737247 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -2214,6 +2214,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class _Hash_merge_helper { }; #endif // C++17 +#if __cpp_deduction_guides >= 201606 + // Used to constrain deduction guides + template + using _RequireNotAllocatorOrIntegral + = __enable_if_t, __is_allocator<_Hash>>::value>; +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index a61d23c..322d0a8 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -1411,6 +1411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Compare = less<__iter_key_t<_InputIterator>>, typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) @@ -1419,6 +1420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Allocator = allocator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> map(initializer_list>, _Compare = _Compare(), _Allocator = _Allocator()) diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index 29a96d8..4c4ccad 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -1075,6 +1075,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Compare = less<__iter_key_t<_InputIterator>>, typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) @@ -1083,6 +1084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Allocator = allocator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> multimap(initializer_list>, _Compare = _Compare(), _Allocator = _Allocator()) diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index 7a0fb83..af733ea 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -917,32 +917,34 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Allocator = allocator::value_type>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> - multiset(_InputIterator, _InputIterator, - _Compare = _Compare(), _Allocator = _Allocator()) - -> multiset::value_type, - _Compare, _Allocator>; - - template, - typename _Allocator = allocator<_Key>, - typename = _RequireAllocator<_Allocator>> - multiset(initializer_list<_Key>, - _Compare = _Compare(), _Allocator = _Allocator()) - -> multiset<_Key, _Compare, _Allocator>; - - template, - typename = _RequireAllocator<_Allocator>> - multiset(_InputIterator, _InputIterator, _Allocator) - -> multiset::value_type, - less::value_type>, - _Allocator>; - - template> - multiset(initializer_list<_Key>, _Allocator) - -> multiset<_Key, less<_Key>, _Allocator>; + multiset(_InputIterator, _InputIterator, + _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset::value_type, + _Compare, _Allocator>; + + template, + typename _Allocator = allocator<_Key>, + typename = _RequireNotAllocator<_Compare>, + typename = _RequireAllocator<_Allocator>> + multiset(initializer_list<_Key>, + _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset<_Key, _Compare, _Allocator>; + + template, + typename = _RequireAllocator<_Allocator>> + multiset(_InputIterator, _InputIterator, _Allocator) + -> multiset::value_type, + less::value_type>, + _Allocator>; + + template> + multiset(initializer_list<_Key>, _Allocator) + -> multiset<_Key, less<_Key>, _Allocator>; #endif diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index dd1d5d9..f7b2d3a 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -312,12 +312,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_deduction_guides >= 201606 template::value>> + typename = _RequireNotAllocator<_Container>> queue(_Container) -> queue; template::value>, - typename = enable_if_t<__is_allocator<_Allocator>::value>> + typename = _RequireNotAllocator<_Container>, + typename = _RequireAllocator<_Allocator>> queue(_Container, _Allocator) -> queue; #endif @@ -687,8 +687,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_deduction_guides >= 201606 template::value>, - typename = enable_if_t::value>> + typename = _RequireNotAllocator<_Compare>, + typename = _RequireNotAllocator<_Container>> priority_queue(_Compare, _Container) -> priority_queue; @@ -697,16 +697,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename _Compare = less<_ValT>, typename _Container = vector<_ValT>, typename = _RequireInputIter<_InputIterator>, - typename = enable_if_t::value>, - typename = enable_if_t::value>> + typename = _RequireNotAllocator<_Compare>, + typename = _RequireNotAllocator<_Container>> priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container()) -> priority_queue<_ValT, _Container, _Compare>; template::value>, - typename = enable_if_t::value>, - typename = enable_if_t<__is_allocator<_Allocator>::value>> + typename = _RequireNotAllocator<_Compare>, + typename = _RequireNotAllocator<_Container>, + typename = _RequireAllocator<_Allocator>> priority_queue(_Compare, _Container, _Allocator) -> priority_queue; #endif diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 7c903cf..3131a79 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -934,6 +934,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Allocator = allocator::value_type>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) @@ -942,6 +943,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Allocator = allocator<_Key>, + typename = _RequireNotAllocator<_Compare>, typename = _RequireAllocator<_Allocator>> set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index 28faab2..7b5f8ca 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -286,12 +286,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_deduction_guides >= 201606 template::value>> + typename = _RequireNotAllocator<_Container>> stack(_Container) -> stack; template::value>, - typename = enable_if_t<__is_allocator<_Allocator>::value>> + typename = _RequireNotAllocator<_Container>, + typename = _RequireAllocator<_Allocator>> stack(_Container, _Allocator) -> stack; #endif diff --git a/libstdc++-v3/include/bits/unordered_map.h b/libstdc++-v3/include/bits/unordered_map.h index ecb3ef4..b8243a7 100644 --- a/libstdc++-v3/include/bits/unordered_map.h +++ b/libstdc++-v3/include/bits/unordered_map.h @@ -1145,6 +1145,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Pred = equal_to<__iter_key_t<_InputIterator>>, typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_map(_InputIterator, _InputIterator, typename unordered_map::size_type = {}, @@ -1156,6 +1158,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Pred = equal_to<_Key>, typename _Allocator = allocator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_map(initializer_list>, typename unordered_map::size_type = {}, @@ -1185,6 +1189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, + typename = _RequireNotAllocatorOrIntegral<_Hash>, typename = _RequireAllocator<_Allocator>> unordered_map(_InputIterator, _InputIterator, typename unordered_map::size_type, @@ -1206,6 +1211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER -> unordered_map<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; template, typename = _RequireAllocator<_Allocator>> unordered_map(initializer_list>, typename unordered_map::size_type, @@ -1991,6 +1997,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Pred = equal_to<__iter_key_t<_InputIterator>>, typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_multimap(_InputIterator, _InputIterator, unordered_multimap::size_type = {}, @@ -2003,6 +2011,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Pred = equal_to<_Key>, typename _Allocator = allocator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_multimap(initializer_list>, unordered_multimap::size_type = {}, @@ -2031,6 +2041,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, + typename = _RequireNotAllocatorOrIntegral<_Hash>, typename = _RequireAllocator<_Allocator>> unordered_multimap(_InputIterator, _InputIterator, unordered_multimap::size_type, _Hash, @@ -2052,6 +2063,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER -> unordered_multimap<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; template, typename = _RequireAllocator<_Allocator>> unordered_multimap(initializer_list>, unordered_multimap::size_type, diff --git a/libstdc++-v3/include/bits/unordered_set.h b/libstdc++-v3/include/bits/unordered_set.h index 3e1180f..8ebcaf4 100644 --- a/libstdc++-v3/include/bits/unordered_set.h +++ b/libstdc++-v3/include/bits/unordered_set.h @@ -820,12 +820,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template::value_type>, + hash::value_type>, typename _Pred = - equal_to::value_type>, + equal_to::value_type>, typename _Allocator = - allocator::value_type>, + allocator::value_type>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_set(_InputIterator, _InputIterator, unordered_set::size_type = {}, @@ -836,6 +838,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Pred = equal_to<_Tp>, typename _Allocator = allocator<_Tp>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_set(initializer_list<_Tp>, unordered_set::size_type = {}, @@ -856,6 +860,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, + typename = _RequireNotAllocatorOrIntegral<_Hash>, typename = _RequireAllocator<_Allocator>> unordered_set(_InputIterator, _InputIterator, unordered_set::size_type, @@ -873,6 +878,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; template, typename = _RequireAllocator<_Allocator>> unordered_set(initializer_list<_Tp>, unordered_set::size_type, _Hash, _Allocator) @@ -1608,12 +1614,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template::value_type>, + hash::value_type>, typename _Pred = - equal_to::value_type>, + equal_to::value_type>, typename _Allocator = - allocator::value_type>, + allocator::value_type>, typename = _RequireInputIter<_InputIterator>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_multiset(_InputIterator, _InputIterator, unordered_multiset::size_type = {}, @@ -1625,6 +1633,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, typename _Pred = equal_to<_Tp>, typename _Allocator = allocator<_Tp>, + typename = _RequireNotAllocatorOrIntegral<_Hash>, + typename = _RequireNotAllocator<_Pred>, typename = _RequireAllocator<_Allocator>> unordered_multiset(initializer_list<_Tp>, unordered_multiset::size_type = {}, @@ -1646,6 +1656,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template, + typename = _RequireNotAllocatorOrIntegral<_Hash>, typename = _RequireAllocator<_Allocator>> unordered_multiset(_InputIterator, _InputIterator, unordered_multiset::size_type, @@ -1665,6 +1676,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; template, typename = _RequireAllocator<_Allocator>> unordered_multiset(initializer_list<_Tp>, unordered_multiset::size_type, _Hash, _Allocator) diff --git a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc index f419525..a42d8d6 100644 --- a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc @@ -44,6 +44,23 @@ static_assert(std::is_same_v< decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::map>); +/* This is not deducible, ambiguous candidates: + * map(initializer_list, const Compare&, const _Allocator& = {}) + * map(initializer_list, const _Allocator&) + * map(initializer_list>, const _Allocator&) -> map +static_assert(std::is_same_v< + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); +*/ + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); + static_assert(std::is_same_v< decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}, SimpleAllocator{}}), @@ -81,6 +98,17 @@ void f() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), {}, std::allocator{}}), std::map>); @@ -123,6 +151,17 @@ void g() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), {}, std::allocator{}}), std::map>); @@ -162,6 +201,17 @@ void h() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), {}, std::allocator{}}), std::map>); diff --git a/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc index 4ca3f98..6fe2704 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc @@ -3,8 +3,10 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::multiset::value_type; static_assert(std::is_same_v< decltype(std::multiset{1, 2, 3}), @@ -15,20 +17,20 @@ static_assert(std::is_same_v< std::multiset>); static_assert(std::is_same_v< - decltype(std::multiset{{1, 2, 3}, - std::less{}, {}}), + decltype(std::multiset{{1, 2, 3}, std::less{}, {}}), std::multiset>); static_assert(std::is_same_v< - decltype(std::multiset{{1, 2, 3}, - {}}), + decltype(std::multiset{{1, 2, 3}, {}}), std::multiset>); static_assert(std::is_same_v< - decltype(std::multiset{{1, 2, 3}, - {}, SimpleAllocator{}}), - std::multiset, - SimpleAllocator>>); + decltype(std::multiset{{1, 2, 3}, SimpleAllocator{}}), + std::multiset, SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::multiset{{1, 2, 3}, {}, SimpleAllocator{}}), + std::multiset, SimpleAllocator>>); void f() { @@ -56,6 +58,16 @@ void f() static_assert(std::is_same_v< decltype(std::multiset{x.begin(), x.end(), + std::allocator{}}), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + SimpleAllocator{}}), + std::multiset, SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), {}, std::allocator{}}), std::multiset>); @@ -66,3 +78,56 @@ void f() SimpleAllocator{}}), std::multiset, SimpleAllocator>>); } + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; + +void g() +{ + value_type array[1]; + test_container x(array); + + static_assert(std::is_same_v< + decltype(std::multiset(x.begin(), x.end())), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + std::less{}, {}}), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset(x.begin(), x.end(), + {})), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + std::allocator{}}), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + SimpleAllocator{}}), + std::multiset, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + {}, + std::allocator{}}), + std::multiset>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::multiset, + SimpleAllocator>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc index 73d5cfd..df89fa2 100644 --- a/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc @@ -3,8 +3,10 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::set::value_type; static_assert(std::is_same_v< decltype(std::set{1, 2, 3}), @@ -26,6 +28,12 @@ static_assert(std::is_same_v< static_assert(std::is_same_v< decltype(std::set{{1, 2, 3}, + SimpleAllocator{}}), + std::set, + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::set{{1, 2, 3}, {}, SimpleAllocator{}}), std::set, SimpleAllocator>>); @@ -62,7 +70,65 @@ void f() static_assert(std::is_same_v< decltype(std::set{x.begin(), x.end(), + SimpleAllocator{}}), + std::set, SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), {}, SimpleAllocator{}}), std::set, SimpleAllocator>>); } + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; + +void g() +{ + value_type array[1]; + test_container x(array); + + static_assert(std::is_same_v< + decltype(std::set(x.begin(), x.end())), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + std::less{}, {}}), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set(x.begin(), x.end(), + {})), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + std::allocator{}}), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + SimpleAllocator{}}), + std::set, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + {}, + std::allocator{}}), + std::set>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::set, + SimpleAllocator>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc index 1905b20..979a56c 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc @@ -17,6 +17,12 @@ static_assert(std::is_same_v< 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{}, {}}), @@ -41,6 +47,7 @@ static_assert(std::is_same_v< void f() { std::unordered_map x; + static_assert(std::is_same_v< decltype(std::unordered_map(x.begin(), x.end())), std::unordered_map>); @@ -58,11 +65,43 @@ void f() 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>); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc index db5e32b..72b2d07 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc @@ -29,10 +29,25 @@ static_assert(std::is_same_v< std::unordered_multimap>); static_assert(std::is_same_v< - decltype(std::unordered_multimap{{std::pair{1, 2.0}, - {2, 3.0}, {3, 4.0}}, - {}, {}, {}, - SimpleAllocator>{}}), + decltype(std::unordered_multimap{ + {std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + 1, std::hash{}}), + std::unordered_multimap>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{ + {std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + 1, std::hash{}, + SimpleAllocator>{}}), + std::unordered_multimap, + std::equal_to, + SimpleAllocator>>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{ + {std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, {}, {}, + SimpleAllocator>{}}), std::unordered_multimap, std::equal_to, SimpleAllocator>>>); @@ -41,6 +56,7 @@ static_assert(std::is_same_v< void f() { std::unordered_multimap x; + static_assert(std::is_same_v< decltype(std::unordered_multimap(x.begin(), x.end())), std::unordered_multimap>); @@ -62,6 +78,38 @@ void f() std::unordered_multimap>); static_assert(std::is_same_v< + decltype(std::unordered_multimap(x.begin(), x.end(), 1)), + std::unordered_multimap>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, + std::allocator>{}}), + std::unordered_multimap>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, + SimpleAllocator>{}}), + std::unordered_multimap, + std::equal_to, + SimpleAllocator>>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + 1, std::hash{}, + std::allocator>{}}), + std::unordered_multimap>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + 1, std::hash{}, + SimpleAllocator>{}}), + std::unordered_multimap, + std::equal_to, + SimpleAllocator>>>); + + static_assert(std::is_same_v< decltype(std::unordered_multimap{x.begin(), x.end(), {}, {}, {}, std::allocator>{}}), diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc index 352176d..fa895d7 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc @@ -11,21 +11,46 @@ static_assert(std::is_same_v< std::unordered_multiset>); static_assert(std::is_same_v< - decltype(std::unordered_multiset{1, 2, 3}), + decltype(std::unordered_multiset{{1, 2, 3}, + 0, std::hash{}, {}}), std::unordered_multiset>); static_assert(std::is_same_v< decltype(std::unordered_multiset{{1, 2, 3}, - 0, std::hash{}, {}}), + {}}), std::unordered_multiset>); static_assert(std::is_same_v< decltype(std::unordered_multiset{{1, 2, 3}, - {}}), + 1}), + std::unordered_multiset>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + 1, std::allocator{}}), std::unordered_multiset>); static_assert(std::is_same_v< decltype(std::unordered_multiset{{1, 2, 3}, + 1, SimpleAllocator{}}), + std::unordered_multiset, + std::equal_to, + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + 1, std::hash{}, std::allocator{}}), + std::unordered_multiset>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + 1, std::hash{}, SimpleAllocator{}}), + std::unordered_multiset, + std::equal_to, + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, {}, {}, {}, std::allocator{}}), std::unordered_multiset>); @@ -59,10 +84,42 @@ void f() static_assert(std::is_same_v< decltype(std::unordered_multiset(x.begin(), x.end(), - {})), + {})), std::unordered_multiset>); static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), 1}), + std::unordered_multiset>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + 1, + std::allocator{}}), + std::unordered_multiset>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + 1, + SimpleAllocator{}}), + std::unordered_multiset, + std::equal_to, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + 1, std::hash{}, + std::allocator{}}), + std::unordered_multiset>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + 1, std::hash{}, + SimpleAllocator{}}), + std::unordered_multiset, + std::equal_to, + SimpleAllocator>>); + + static_assert(std::is_same_v< decltype(std::unordered_multiset{x.begin(), x.end(), {}, {}, {}, std::allocator{}}), diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc index c7e1798..61f21d2 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc @@ -11,21 +11,41 @@ static_assert(std::is_same_v< std::unordered_set>); static_assert(std::is_same_v< - decltype(std::unordered_set{1, 2, 3}), + decltype(std::unordered_set{{1, 2, 3}, + 0, std::hash{}, {}}), std::unordered_set>); static_assert(std::is_same_v< decltype(std::unordered_set{{1, 2, 3}, - 0, std::hash{}, {}}), + {}}), std::unordered_set>); static_assert(std::is_same_v< decltype(std::unordered_set{{1, 2, 3}, - {}}), + 1, std::allocator{}}), std::unordered_set>); static_assert(std::is_same_v< decltype(std::unordered_set{{1, 2, 3}, + 1, SimpleAllocator{}}), + std::unordered_set, + std::equal_to, + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + 1, std::hash{}, std::allocator{}}), + std::unordered_set>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + 1, std::hash{}, SimpleAllocator{}}), + std::unordered_set, + std::equal_to, + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, {}, {}, {}, std::allocator{}}), std::unordered_set>); @@ -59,11 +79,43 @@ void f() static_assert(std::is_same_v< decltype(std::unordered_set(x.begin(), x.end(), - {})), + {})), + std::unordered_set>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), 1}), std::unordered_set>); static_assert(std::is_same_v< decltype(std::unordered_set{x.begin(), x.end(), + 1, + std::allocator{}}), + std::unordered_set>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + 1, + SimpleAllocator{}}), + std::unordered_set, + std::equal_to, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + 1, std::hash{}, + std::allocator{}}), + std::unordered_set>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + 1, std::hash{}, + SimpleAllocator{}}), + std::unordered_set, + std::equal_to, + SimpleAllocator>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), {}, {}, {}, std::allocator{}}), std::unordered_set>); -- 2.7.4