Index: include/unordered_map =================================================================== --- include/unordered_map +++ include/unordered_map @@ -1345,6 +1345,67 @@ #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template>, + class _Pred = equal_to<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template, + class _Pred = equal_to<_Key>, class _Allocator = allocator>, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_map(initializer_list>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_map<_Key, _Tp, _Hash, _Pred, _Allocator>; + +template::value, void>::type> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type> +unordered_map(_InputIterator, _InputIterator, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type> +unordered_map(initializer_list>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_map<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; + +template::value, void>::type> +unordered_map(initializer_list>, _Allocator) + -> unordered_map<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; + +template::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_map(initializer_list>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_map<_Key, _Tp, _Hash, equal_to<_Key>, _Allocator>; +#endif + template unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( size_type __n, const hasher& __hf, const key_equal& __eql) @@ -2035,6 +2096,67 @@ }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template>, + class _Pred = equal_to<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template, + class _Pred = equal_to<_Key>, class _Allocator = allocator>, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_multimap(initializer_list>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Allocator>; + +template::value, void>::type> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type> +unordered_multimap(_InputIterator, _InputIterator, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template::value, void>::type> +unordered_multimap(initializer_list>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multimap<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; + +template::value, void>::type> +unordered_multimap(initializer_list>, _Allocator) + -> unordered_multimap<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>; + +template::value, void>::type, + class = typename enable_if::value, void>::type, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +unordered_multimap(initializer_list>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_multimap<_Key, _Tp, _Hash, equal_to<_Key>, _Allocator>; +#endif + template unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( size_type __n, const hasher& __hf, const key_equal& __eql) Index: test/std/containers/unord/unord.map/unord.map.cnstr/deduct.fail.cpp =================================================================== --- /dev/null +++ test/std/containers/unord/unord.map/unord.map.cnstr/deduct.fail.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template>, +// class Pred = equal_to>, +// class Allocator = allocator>> +// unordered_map(InputIterator, InputIterator, typename see below::size_type = see below, +// Hash = Hash(), Pred = Pred(), Allocator = Allocator()) +// -> unordered_map, iter-mapped-type, Hash, Pred, +// Allocator>; +// +// template, +// class Pred = equal_to, class Allocator = allocator>> +// unordered_map(initializer_list>, +// typename see below::size_type = see below, Hash = Hash(), +// Pred = Pred(), Allocator = Allocator()) +// -> unordered_map; +// +// template +// unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator) +// -> unordered_map, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_map(InputIterator, InputIterator, Allocator) +// -> unordered_map, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator) +// -> unordered_map, iter-mapped-type, Hash, +// equal_to>, Allocator>; +// +// template +// unordered_map(initializer_list>, typename see below::size_type, Allocator) +// -> unordered_map, equal_to, Allocator>; +// +// template +// unordered_map(initializer_list>, Allocator) +// -> unordered_map, equal_to, Allocator>; +// +// template +// unordered_map(initializer_list>, typename see below::size_type, Hash, +// Allocator) +// -> unordered_map, Allocator>; + +#include // INT_MAX +#include +#include + +int main(int, char**) +{ + using P = std::pair; + { + // cannot deduce Key from nothing + std::unordered_map m; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size) + std::unordered_map m(42); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size, Hash) + std::unordered_map m(42, std::hash()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size, Hash, Pred) + std::unordered_map m(42, std::hash(), std::equal_to()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size, Hash, Pred, Allocator) + std::unordered_map m(42, std::hash(), std::equal_to(), std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Allocator) + std::unordered_map m(std::allocator

{}); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size, Allocator) + std::unordered_map m(42, std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + { + // cannot deduce Key from just (Size, Hash, Allocator) + std::unordered_map m(42, std::hash(), std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_map'}} + } + + return 0; +} Index: test/std/containers/unord/unord.map/unord.map.cnstr/deduct.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/unord/unord.map/unord.map.cnstr/deduct.pass.cpp @@ -0,0 +1,202 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template>, +// class Pred = equal_to>, +// class Allocator = allocator>> +// unordered_map(InputIterator, InputIterator, typename see below::size_type = see below, +// Hash = Hash(), Pred = Pred(), Allocator = Allocator()) +// -> unordered_map, iter-mapped-type, Hash, Pred, +// Allocator>; +// +// template, +// class Pred = equal_to, class Allocator = allocator>> +// unordered_map(initializer_list>, +// typename see below::size_type = see below, Hash = Hash(), +// Pred = Pred(), Allocator = Allocator()) +// -> unordered_map; +// +// template +// unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator) +// -> unordered_map, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_map(InputIterator, InputIterator, Allocator) +// -> unordered_map, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator) +// -> unordered_map, iter-mapped-type, Hash, +// equal_to>, Allocator>; +// +// template +// unordered_map(initializer_list>, typename see below::size_type, Allocator) +// -> unordered_map, equal_to, Allocator>; +// +// template +// unordered_map(initializer_list>, Allocator) +// -> unordered_map, equal_to, Allocator>; +// +// template +// unordered_map(initializer_list>, typename see below::size_type, Hash, +// Allocator) +// -> unordered_map, Allocator>; + +#include // is_permutation +#include +#include // INT_MAX +#include +#include + +#include "test_allocator.h" + +int main(int, char**) +{ + using P = std::pair; + std::pair expected_m[] = { {1,1}, {2,2}, {3,1}, {INT_MAX,1} }; + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42, std::hash()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42, std::hash(), std::equal_to<>()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to<>>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42, std::hash(), std::equal_to<>(), test_allocator

(0, 41)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to<>, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 41); + } + + { + std::unordered_map source; + std::unordered_map m(source); + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.size() == 0); + } + + { + std::unordered_map source; + std::unordered_map m{source}; + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.size() == 0); + } + + { + std::unordered_map, std::equal_to<>, test_allocator

> source; + test_allocator

a(0, 42); + std::unordered_map m(source, a); + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.get_allocator().get_id() == 42); + assert(m.size() == 0); + } + + { + std::unordered_map, std::equal_to<>, test_allocator

> source; + test_allocator

a(0, 43); + std::unordered_map m{source, a}; + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.get_allocator().get_id() == 43); + assert(m.size() == 0); + } + + { + std::unordered_map m { std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }; + ASSERT_SAME_TYPE(decltype(m), std::unordered_map); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), std::equal_to<>()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to<>>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), std::equal_to<>(), test_allocator

(0, 44)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to<>, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 44); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42, test_allocator

(0, 45)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 45); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_map m(std::begin(arr), std::end(arr), 42, std::hash(), test_allocator

(0, 46)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 46); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, test_allocator

(0, 47)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 47); + } + + { + std::unordered_map m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), test_allocator

(0, 48)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_map, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 48); + } + + return 0; +} Index: test/std/containers/unord/unord.multimap/unord.multimap.cnstr/deduct.fail.cpp =================================================================== --- /dev/null +++ test/std/containers/unord/unord.multimap/unord.multimap.cnstr/deduct.fail.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template>, +// class Pred = equal_to>, +// class Allocator = allocator>> +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below, +// Hash = Hash(), Pred = Pred(), Allocator = Allocator()) +// -> unordered_multimap, iter-mapped-type, Hash, Pred, +// Allocator>; +// +// template, +// class Pred = equal_to, class Allocator = allocator>> +// unordered_multimap(initializer_list>, +// typename see below::size_type = see below, Hash = Hash(), +// Pred = Pred(), Allocator = Allocator()) +// -> unordered_multimap; +// +// template +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator) +// -> unordered_multimap, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(InputIterator, InputIterator, Allocator) +// -> unordered_multimap, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator) +// -> unordered_multimap, iter-mapped-type, Hash, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(initializer_list>, typename see below::size_type, Allocator) +// -> unordered_multimap, equal_to, Allocator>; +// +// template +// unordered_multimap(initializer_list>, Allocator) +// -> unordered_multimap, equal_to, Allocator>; +// +// template +// unordered_multimap(initializer_list>, typename see below::size_type, Hash, +// Allocator) +// -> unordered_multimap, Allocator>; + +#include // INT_MAX +#include +#include + +int main(int, char**) +{ + using P = std::pair; + { + // cannot deduce Key from nothing + std::unordered_multimap m; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size) + std::unordered_multimap m(42); // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size, Hash) + std::unordered_multimap m(42, std::hash()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size, Hash, Pred) + std::unordered_multimap m(42, std::hash(), std::equal_to()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size, Hash, Pred, Allocator) + std::unordered_multimap m(42, std::hash(), std::equal_to(), std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Allocator) + std::unordered_multimap m(std::allocator

{}); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size, Allocator) + std::unordered_multimap m(42, std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + { + // cannot deduce Key from just (Size, Hash, Allocator) + std::unordered_multimap m(42, std::hash(), std::allocator

()); + // expected-error@-1{{no viable constructor or deduction guide for deduction of template arguments of 'unordered_multimap'}} + } + + return 0; +} Index: test/std/containers/unord/unord.multimap/unord.multimap.cnstr/deduct.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/unord/unord.multimap/unord.multimap.cnstr/deduct.pass.cpp @@ -0,0 +1,202 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template>, +// class Pred = equal_to>, +// class Allocator = allocator>> +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below, +// Hash = Hash(), Pred = Pred(), Allocator = Allocator()) +// -> unordered_multimap, iter-mapped-type, Hash, Pred, +// Allocator>; +// +// template, +// class Pred = equal_to, class Allocator = allocator>> +// unordered_multimap(initializer_list>, +// typename see below::size_type = see below, Hash = Hash(), +// Pred = Pred(), Allocator = Allocator()) +// -> unordered_multimap; +// +// template +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator) +// -> unordered_multimap, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(InputIterator, InputIterator, Allocator) +// -> unordered_multimap, iter-mapped-type, +// hash>, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator) +// -> unordered_multimap, iter-mapped-type, Hash, +// equal_to>, Allocator>; +// +// template +// unordered_multimap(initializer_list>, typename see below::size_type, Allocator) +// -> unordered_multimap, equal_to, Allocator>; +// +// template +// unordered_multimap(initializer_list>, Allocator) +// -> unordered_multimap, equal_to, Allocator>; +// +// template +// unordered_multimap(initializer_list>, typename see below::size_type, Hash, +// Allocator) +// -> unordered_multimap, Allocator>; + +#include // is_permutation +#include +#include // INT_MAX +#include +#include + +#include "test_allocator.h" + +int main(int, char**) +{ + using P = std::pair; + std::pair expected_m[] = { {1,1}, {1,1}, {2,2}, {3,1}, {INT_MAX,1} }; + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash(), std::equal_to<>()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to<>>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash(), std::equal_to<>(), test_allocator

(0, 41)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to<>, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 41); + } + + { + std::unordered_multimap source; + std::unordered_multimap m(source); + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.size() == 0); + } + + { + std::unordered_multimap source; + std::unordered_multimap m{source}; + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.size() == 0); + } + + { + std::unordered_multimap, std::equal_to<>, test_allocator

> source; + test_allocator

a(0, 42); + std::unordered_multimap m(source, a); + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.get_allocator().get_id() == 42); + assert(m.size() == 0); + } + + { + std::unordered_multimap, std::equal_to<>, test_allocator

> source; + test_allocator

a(0, 43); + std::unordered_multimap m{source, a}; + ASSERT_SAME_TYPE(decltype(m), decltype(source)); + assert(m.get_allocator().get_id() == 43); + assert(m.size() == 0); + } + + { + std::unordered_multimap m { std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }; + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), std::equal_to<>()); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to<>>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), std::equal_to<>(), test_allocator

(0, 44)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to<>, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 44); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42, test_allocator

(0, 45)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 45); + } + + { + const std::pair arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} }; + std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash(), test_allocator

(0, 46)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 46); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, test_allocator

(0, 47)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 47); + } + + { + std::unordered_multimap m({ std::pair{1,1L}, std::pair{2,2L}, std::pair{1,1L}, std::pair{INT_MAX,1L}, std::pair{3,1L} }, 42, std::hash(), test_allocator

(0, 48)); + ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap, std::equal_to, test_allocator

>); + assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); + assert(m.get_allocator().get_id() == 48); + } + + return 0; +} Index: www/cxx2a_status.html =================================================================== --- www/cxx2a_status.html +++ www/cxx2a_status.html @@ -283,7 +283,7 @@ 2996Missing rvalue overloads for shared_ptr operationsSan Diego 3008make_shared (sub)object destruction semantics are not specifiedSan Diego 3022is_convertible<derived*, base*> may lead to ODRSan DiegoResolved by 1285R0 - 3025Map-like container deduction guides should use pair<Key, T>, not pair<const Key, T>San Diego + 3025Map-like container deduction guides should use pair<Key, T>, not pair<const Key, T>San DiegoComplete 3031Algorithms and predicates with non-const reference argumentsSan Diego 3037polymorphic_allocator and incomplete typesSan Diego 3038polymorphic_allocator::allocate should not allow integer overflow to create vulnerabilitiesSan Diego