diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-02-26 23:12:44 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-02-26 23:12:44 +0000 |
commit | 08abbddaaa7e41f0586c641f883b7c2c8bb742e0 (patch) | |
tree | 72465054c25ef809adeac6217526acd25aa229e5 /libstdc++-v3/testsuite/23_containers/multiset | |
parent | 8735903781aabdb48683d24d783eba6c76fd8c99 (diff) | |
download | gcc-08abbddaaa7e41f0586c641f883b7c2c8bb742e0.tar.gz |
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
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/multiset')
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc | 81 |
1 files changed, 73 insertions, 8 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc index 4ca3f98129a..6fe2704da17 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 <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}), @@ -15,20 +17,20 @@ static_assert(std::is_same_v< std::multiset<int>>); static_assert(std::is_same_v< - decltype(std::multiset{{1, 2, 3}, - std::less<int>{}, {}}), + decltype(std::multiset{{1, 2, 3}, std::less<int>{}, {}}), std::multiset<int>>); static_assert(std::is_same_v< - decltype(std::multiset{{1, 2, 3}, - {}}), + decltype(std::multiset{{1, 2, 3}, {}}), 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>>>); + 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() { @@ -56,6 +58,16 @@ void f() 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>>); @@ -66,3 +78,56 @@ void f() 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::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>>>); +} |