1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCONTAINERINFO_H
5#define QCONTAINERINFO_H
6
7#include <QtCore/qglobal.h>
8#include <type_traits>
9
10QT_BEGIN_NAMESPACE
11
12namespace QContainerInfo {
13
14template<typename C>
15using value_type = typename C::value_type;
16
17template<typename C>
18using key_type = typename C::key_type;
19
20template<typename C>
21using mapped_type = typename C::mapped_type;
22
23template<typename C>
24using iterator = typename C::iterator;
25
26template<typename C>
27using const_iterator = typename C::const_iterator;
28
29// Some versions of Apple clang warn about the constexpr variables below being unused.
30QT_WARNING_PUSH
31QT_WARNING_DISABLE_CLANG("-Wunused-const-variable")
32
33template<typename C, typename = void>
34inline constexpr bool has_value_type_v = false;
35template<typename C>
36inline constexpr bool has_value_type_v<C, std::void_t<value_type<C>>> = true;
37
38template<typename C, typename = void>
39inline constexpr bool has_key_type_v = false;
40template<typename C>
41inline constexpr bool has_key_type_v<C, std::void_t<key_type<C>>> = true;
42
43template<typename C, typename = void>
44inline constexpr bool has_mapped_type_v = false;
45template<typename C>
46inline constexpr bool has_mapped_type_v<C, std::void_t<mapped_type<C>>> = true;
47
48template<typename C, typename = void>
49inline constexpr bool has_size_v = false;
50template<typename C>
51inline constexpr bool has_size_v<C, std::void_t<decltype(C().size())>> = true;
52
53template<typename C, typename = void>
54inline constexpr bool has_reserve_v = false;
55template<typename C>
56inline constexpr bool has_reserve_v<C, std::void_t<decltype(C().reserve(0))>> = true;
57
58template<typename C, typename = void>
59inline constexpr bool has_clear_v = false;
60template<typename C>
61inline constexpr bool has_clear_v<C, std::void_t<decltype(C().clear())>> = true;
62
63template<typename, typename = void>
64inline constexpr bool has_at_index_v = false;
65template<typename C>
66inline constexpr bool has_at_index_v<C, std::void_t<decltype(C().at(0))>> = true;
67
68template<typename, typename = void>
69inline constexpr bool has_at_key_v = false;
70template<typename C>
71inline constexpr bool has_at_key_v<C, std::void_t<decltype(C().at(key_type<C>()))>> = true;
72
73template<typename, typename = void>
74inline constexpr bool can_get_at_index_v = false;
75template<typename C>
76inline constexpr bool can_get_at_index_v<C, std::void_t<value_type<C>(decltype(C()[0]))>> = true;
77
78template<typename, typename = void>
79inline constexpr bool can_set_at_index_v = false;
80template<typename C>
81inline constexpr bool can_set_at_index_v<C, std::void_t<decltype(C()[0] = value_type<C>())>> = true;
82
83template<typename, typename = void>
84inline constexpr bool has_push_front_v = false;
85template<typename C>
86inline constexpr bool has_push_front_v<C, std::void_t<decltype(C().push_front(value_type<C>()))>> = true;
87
88template<typename, typename = void>
89inline constexpr bool has_push_back_v = false;
90template<typename C>
91inline constexpr bool has_push_back_v<C, std::void_t<decltype(C().push_back(value_type<C>()))>> = true;
92
93template<typename, typename = void>
94inline constexpr bool has_insert_v = false;
95template<typename C>
96inline constexpr bool has_insert_v<C, std::void_t<decltype(C().insert(value_type<C>()))>> = true;
97
98template<typename, typename = void>
99inline constexpr bool has_pop_front_v = false;
100template<typename C>
101inline constexpr bool has_pop_front_v<C, std::void_t<decltype(C().pop_front())>> = true;
102
103template<typename, typename = void>
104inline constexpr bool has_pop_back_v = false;
105template<typename C>
106inline constexpr bool has_pop_back_v<C, std::void_t<decltype(C().pop_back())>> = true;
107
108template<typename, typename = void>
109inline constexpr bool has_iterator_v = false;
110template<typename C>
111inline constexpr bool has_iterator_v<C, std::void_t<iterator<C>>> = true;
112
113template<typename, typename = void>
114inline constexpr bool has_const_iterator_v = false;
115template<typename C>
116inline constexpr bool has_const_iterator_v<C, std::void_t<const_iterator<C>>> = true;
117
118template<typename, typename = void>
119inline constexpr bool can_set_value_at_iterator_v = false;
120template<typename C>
121inline constexpr bool can_set_value_at_iterator_v<C, std::void_t<decltype(*C().begin() = value_type<C>())>> = true;
122
123template<typename, typename = void>
124inline constexpr bool can_set_mapped_at_iterator_v = false;
125template<typename C>
126inline constexpr bool can_set_mapped_at_iterator_v<C, std::void_t<decltype(*C().begin() = mapped_type<C>())>> = true;
127
128template<typename, typename = void>
129inline constexpr bool can_insert_value_at_iterator_v = false;
130template<typename C>
131inline constexpr bool can_insert_value_at_iterator_v<C, std::void_t<decltype(C().insert(C().begin(), value_type<C>()))>> = true;
132
133template<typename, typename = void>
134inline constexpr bool can_erase_at_iterator_v = false;
135template<typename C>
136inline constexpr bool can_erase_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin()))>> = true;
137
138template<typename, typename = void>
139inline constexpr bool can_erase_range_at_iterator_v = false;
140template<typename C>
141inline constexpr bool can_erase_range_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin(), C().end()))>> = true;
142
143template<typename, typename = void>
144inline constexpr bool can_get_at_key_v = false;
145template<typename C>
146inline constexpr bool can_get_at_key_v<C, std::void_t<mapped_type<C>(decltype(C()[key_type<C>()]))>> = true;
147
148template<typename, typename = void>
149inline constexpr bool can_set_at_key_v = false;
150template<typename C>
151inline constexpr bool can_set_at_key_v<C, std::void_t<decltype(C()[key_type<C>()] = mapped_type<C>())>> = true;
152
153template<typename, typename = void>
154inline constexpr bool can_erase_at_key_v = false;
155template<typename C>
156inline constexpr bool can_erase_at_key_v<C, std::void_t<decltype(C().erase(key_type<C>()))>> = true;
157
158template<typename, typename = void>
159inline constexpr bool can_remove_at_key_v = false;
160template<typename C>
161inline constexpr bool can_remove_at_key_v<C, std::void_t<decltype(C().remove(key_type<C>()))>> = true;
162
163template<typename, typename = void>
164inline constexpr bool can_insert_key_v = false;
165template<typename C>
166inline constexpr bool can_insert_key_v<C, std::void_t<decltype(C().insert(key_type<C>()))>> = true;
167
168template<typename, typename = void>
169inline constexpr bool can_insert_pair_v = false;
170template<typename C>
171inline constexpr bool can_insert_pair_v<C, std::void_t<decltype(C().insert({key_type<C>(), mapped_type<C>()}))>> = true;
172
173template<typename, typename = void>
174inline constexpr bool can_insert_key_mapped_v = false;
175template<typename C>
176inline constexpr bool can_insert_key_mapped_v<C, std::void_t<decltype(C().insert(key_type<C>(), mapped_type<C>()))>> = true;
177
178template<typename, typename = void>
179inline constexpr bool has_contains_v = false;
180template<typename C>
181inline constexpr bool has_contains_v<C, std::void_t<decltype(bool(C().contains(key_type<C>())))>> = true;
182
183template<typename, typename = void>
184inline constexpr bool has_find_v = false;
185template<typename C>
186inline constexpr bool has_find_v<C, std::void_t<decltype(C().find(key_type<C>()))>> = true;
187
188template<typename, typename = void>
189inline constexpr bool iterator_dereferences_to_value_v = false;
190template<typename C>
191inline constexpr bool iterator_dereferences_to_value_v<C, std::void_t<decltype(value_type<C>(*C().begin()))>> = true;
192
193template<typename, typename = void>
194inline constexpr bool iterator_has_key_v = false;
195template<typename C>
196inline constexpr bool iterator_has_key_v<C, std::void_t<decltype(key_type<C>(C().begin().key()))>> = true;
197
198template<typename, typename = void>
199inline constexpr bool value_type_has_first_v = false;
200template<typename C>
201inline constexpr bool value_type_has_first_v<C, std::void_t<decltype(key_type<C>(value_type<C>().first))>> = true;
202
203template<typename, typename = void>
204inline constexpr bool iterator_dereferences_to_key_v = false;
205template<typename C>
206inline constexpr bool iterator_dereferences_to_key_v<C, std::void_t<decltype(key_type<C>(*C().begin()))>> = true;
207
208template<typename, typename = void>
209inline constexpr bool iterator_has_value_v = false;
210template<typename C>
211inline constexpr bool iterator_has_value_v<C, std::void_t<decltype(mapped_type<C>(C().begin().value()))>> = true;
212
213template<typename, typename = void>
214inline constexpr bool value_type_has_second_v = false;
215template<typename C>
216inline constexpr bool value_type_has_second_v<C, std::void_t<decltype(mapped_type<C>(value_type<C>().second))>> = true;
217
218template<typename, typename = void>
219inline constexpr bool iterator_dereferences_to_mapped_v = false;
220template<typename C>
221inline constexpr bool iterator_dereferences_to_mapped_v<C, std::void_t<decltype(mapped_type<C>(*C().begin()))>> = true;
222
223QT_WARNING_POP
224
225}
226
227QT_END_NAMESPACE
228
229#endif // QCONTAINERINFO_H
230

source code of qtbase/src/corelib/global/qcontainerinfo.h