1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10
11// <unordered_map>
12
13// template<class InputIterator,
14// class Hash = hash<iter-key-type<InputIterator>>,
15// class Pred = equal_to<iter-key-type<InputIterator>>,
16// class Allocator = allocator<iter-to-alloc-type<InputIterator>>>
17// unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
18// Hash = Hash(), Pred = Pred(), Allocator = Allocator())
19// -> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash, Pred,
20// Allocator>;
21//
22// template<class Key, class T, class Hash = hash<Key>,
23// class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
24// unordered_map(initializer_list<pair<Key, T>>,
25// typename see below::size_type = see below, Hash = Hash(),
26// Pred = Pred(), Allocator = Allocator())
27// -> unordered_map<Key, T, Hash, Pred, Allocator>;
28//
29// template<class InputIterator, class Allocator>
30// unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
31// -> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
32// hash<iter-key-type<InputIterator>>,
33// equal_to<iter-key-type<InputIterator>>, Allocator>;
34//
35// template<class InputIterator, class Allocator>
36// unordered_map(InputIterator, InputIterator, Allocator)
37// -> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
38// hash<iter-key-type<InputIterator>>,
39// equal_to<iter-key-type<InputIterator>>, Allocator>;
40//
41// template<class InputIterator, class Hash, class Allocator>
42// unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
43// -> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash,
44// equal_to<iter-key-type<InputIterator>>, Allocator>;
45//
46// template<class Key, class T, class Allocator>
47// unordered_map(initializer_list<pair<Key, T>>, typename see below::size_type, Allocator)
48// -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
49//
50// template<class Key, class T, class Allocator>
51// unordered_map(initializer_list<pair<Key, T>>, Allocator)
52// -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
53//
54// template<class Key, class T, class Hash, class Allocator>
55// unordered_map(initializer_list<pair<Key, T>>, typename see below::size_type, Hash,
56// Allocator)
57// -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>;
58
59#include <array>
60#include <functional>
61#include <tuple>
62#include <unordered_map>
63
64int main(int, char**) {
65 using P = std::pair<const int, int>;
66 {
67 // cannot deduce Key from nothing
68 std::unordered_map m;
69 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
70 }
71 {
72 // cannot deduce Key from just (Size)
73 std::unordered_map m(42);
74 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
75 }
76 {
77 // cannot deduce Key from just (Size, Hash)
78 std::unordered_map m(42, std::hash<int>());
79 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
80 }
81 {
82 // cannot deduce Key from just (Size, Hash, Pred)
83 std::unordered_map m(42, std::hash<int>(), std::equal_to<int>());
84 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
85 }
86 {
87 // cannot deduce Key from just (Size, Hash, Pred, Allocator)
88 std::unordered_map m(42, std::hash<int>(), std::equal_to<int>(), std::allocator<P>());
89 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
90 }
91 {
92 // cannot deduce Key from just (Allocator)
93 std::unordered_map m(std::allocator<P>{});
94 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
95 }
96 {
97 // cannot deduce Key from just (Size, Allocator)
98 std::unordered_map m(42, std::allocator<P>());
99 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
100 }
101 {
102 // cannot deduce Key from just (Size, Hash, Allocator)
103 std::unordered_map m(42, std::hash<int>(), std::allocator<P>());
104 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
105 }
106 {
107 // cannot deduce from tuple-like objects without proper iterator
108 std::tuple<int, double> t{1, 2.0};
109 std::unordered_map m(t);
110 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
111 }
112 {
113 // cannot deduce from array-like objects without proper iterator
114 std::array<int, 2> arr{1, 2};
115 std::unordered_map m(arr);
116 // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}unordered_map'}}
117 }
118
119 return 0;
120}
121

source code of libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/deduct.verify.cpp