From: Jonathan Wakely Date: Wed, 2 Jan 2019 16:30:49 +0000 (+0000) Subject: Add more testcases for class template argument deduction of maps X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b3e2dc1ed96ff476ed880f151331237c64f9bfe7;p=gcc.git Add more testcases for class template argument deduction of maps This adds additional tests for std::map and std::multimap CTAD. The tests ensure that deduction works for braced-init-list of value_type objects, and for pairs of input iterators (with both std::pair and value_type as the iterator's value_type). This ensures deduction from value_type still works, as well as the non-value_type cases in LWG 3025. Similar tests for unordered maps do not work, apparently because the constructor taking an initializer_list is not usable for deduction, and the deduction guide taking initializer_list> deduces key_type to be const. I am not addressing that. * testsuite/23_containers/map/cons/deduction.cc: Test deduction from initializer_list and from input iterator ranges. * testsuite/23_containers/multimap/cons/deduction.cc: Likewise. From-SVN: r267518 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 13535aaf786..ba965268484 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2019-01-02 Jonathan Wakely + * testsuite/23_containers/map/cons/deduction.cc: Test deduction from + initializer_list and from input iterator ranges. + * testsuite/23_containers/multimap/cons/deduction.cc: Likewise. + * testsuite/experimental/string_view/element_access/char/empty.cc: Fix year range in copyright header. diff --git a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc index 3880cd5e79d..f4195257e9c 100644 --- a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc @@ -3,32 +3,58 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::map::value_type; + +static_assert(std::is_same_v< + decltype(std::map{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::map>); static_assert(std::is_same_v< decltype(std::map{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), std::map>); +static_assert(std::is_same_v< + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::map>); + static_assert(std::is_same_v< decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), std::map>); static_assert(std::is_same_v< - decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - std::less{}, {}}), + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less{}, {}}), std::map>); static_assert(std::is_same_v< decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - {}}), + std::less{}, {}}), + std::map>); + +/* This is not deducible, {} could be deduced as _Compare or _Allocator. +static_assert(std::is_same_v< + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::map>); +*/ + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), + std::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>{}}), + {}, SimpleAllocator{}}), std::map, - SimpleAllocator>>>); + SimpleAllocator>>); void f() { @@ -39,13 +65,94 @@ void f() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - std::less{}, - std::allocator>{}}), + std::less{}, + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, {}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end(), + {})), + std::map>); + + 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>>); +} + +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::map(x.begin(), x.end())), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, + std::allocator{}}), std::map>); - + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, {}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end(), + {})), + std::map>); + + 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>>); +} + +void h() +{ + std::pair array[1]; + test_container, input_iterator_wrapper> x(array); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end())), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::map>); + static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - std::less{}, {}}), + std::less{}, {}}), std::map>); static_assert(std::is_same_v< @@ -55,14 +162,14 @@ void f() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - {}, - std::allocator>{}}), + {}, + std::allocator{}}), std::map>); static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - {}, - SimpleAllocator>{}}), + {}, + SimpleAllocator{}}), std::map, - SimpleAllocator>>>); + SimpleAllocator>>); } diff --git a/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc index ee48bfda26b..2f9373a5bef 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc @@ -3,32 +3,60 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::multimap::value_type; + +static_assert(std::is_same_v< + decltype(std::multimap{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), std::multimap>); +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::multimap>); + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), std::multimap>); +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less{}, {}}), + std::multimap>); + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, std::less{}, {}}), std::multimap>); +/* This is not deducible, {} could be deduced as _Compare or _Allocator. +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}}), + std::multimap>); +*/ + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::multimap>); +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator{}}), + std::multimap, + SimpleAllocator>>); + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - {}, SimpleAllocator>{}}), + {}, SimpleAllocator{}}), std::multimap, - SimpleAllocator>>>); + SimpleAllocator>>); void f() { @@ -39,30 +67,111 @@ void f() static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - std::less{}, - std::allocator>{}}), + std::less{}, + std::allocator{}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - std::less{}, {}}), + std::less{}, {}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap(x.begin(), x.end(), - {})), + {})), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), {}, - std::allocator>{}}), + std::allocator{}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - {}, - SimpleAllocator>{}}), + {}, + SimpleAllocator{}}), + std::multimap, + 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::multimap(x.begin(), x.end())), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, {}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end(), + {})), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::multimap, + SimpleAllocator>>); +} + +void h() +{ + std::pair array[1]; + test_container, input_iterator_wrapper> x(array); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end())), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, {}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end(), + {})), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + SimpleAllocator{}}), std::multimap, - SimpleAllocator>>>); + SimpleAllocator>>); }