1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCONTAINERINFO_H
41#define QCONTAINERINFO_H
42
43#include <QtCore/qglobal.h>
44#include <type_traits>
45
46QT_BEGIN_NAMESPACE
47
48namespace QContainerTraits {
49
50template<typename C>
51using value_type = typename C::value_type;
52
53template<typename C>
54using key_type = typename C::key_type;
55
56template<typename C>
57using mapped_type = typename C::mapped_type;
58
59template<typename C>
60using iterator = typename C::iterator;
61
62template<typename C>
63using const_iterator = typename C::const_iterator;
64
65// Some versions of Apple clang warn about the constexpr variables below being unused.
66QT_WARNING_PUSH
67QT_WARNING_DISABLE_CLANG("-Wunused-const-variable")
68
69template<typename C, typename = void>
70inline constexpr bool has_value_type_v = false;
71template<typename C>
72inline constexpr bool has_value_type_v<C, std::void_t<value_type<C>>> = true;
73
74template<typename C, typename = void>
75inline constexpr bool has_key_type_v = false;
76template<typename C>
77inline constexpr bool has_key_type_v<C, std::void_t<key_type<C>>> = true;
78
79template<typename C, typename = void>
80inline constexpr bool has_mapped_type_v = false;
81template<typename C>
82inline constexpr bool has_mapped_type_v<C, std::void_t<mapped_type<C>>> = true;
83
84template<typename C, typename = void>
85inline constexpr bool has_size_v = false;
86template<typename C>
87inline constexpr bool has_size_v<C, std::void_t<decltype(C().size())>> = true;
88
89template<typename C, typename = void>
90inline constexpr bool has_clear_v = false;
91template<typename C>
92inline constexpr bool has_clear_v<C, std::void_t<decltype(C().clear())>> = true;
93
94template<typename, typename = void>
95inline constexpr bool has_at_index_v = false;
96template<typename C>
97inline constexpr bool has_at_index_v<C, std::void_t<decltype(C().at(0))>> = true;
98
99template<typename, typename = void>
100inline constexpr bool has_at_key_v = false;
101template<typename C>
102inline constexpr bool has_at_key_v<C, std::void_t<decltype(C().at(key_type<C>()))>> = true;
103
104template<typename, typename = void>
105inline constexpr bool can_get_at_index_v = false;
106template<typename C>
107inline constexpr bool can_get_at_index_v<C, std::void_t<value_type<C>(decltype(C()[0]))>> = true;
108
109template<typename, typename = void>
110inline constexpr bool can_set_at_index_v = false;
111template<typename C>
112inline constexpr bool can_set_at_index_v<C, std::void_t<decltype(C()[0] = value_type<C>())>> = true;
113
114template<typename, typename = void>
115inline constexpr bool has_push_front_v = false;
116template<typename C>
117inline constexpr bool has_push_front_v<C, std::void_t<decltype(C().push_front(value_type<C>()))>> = true;
118
119template<typename, typename = void>
120inline constexpr bool has_push_back_v = false;
121template<typename C>
122inline constexpr bool has_push_back_v<C, std::void_t<decltype(C().push_back(value_type<C>()))>> = true;
123
124template<typename, typename = void>
125inline constexpr bool has_insert_v = false;
126template<typename C>
127inline constexpr bool has_insert_v<C, std::void_t<decltype(C().insert(value_type<C>()))>> = true;
128
129template<typename, typename = void>
130inline constexpr bool has_pop_front_v = false;
131template<typename C>
132inline constexpr bool has_pop_front_v<C, std::void_t<decltype(C().pop_front())>> = true;
133
134template<typename, typename = void>
135inline constexpr bool has_pop_back_v = false;
136template<typename C>
137inline constexpr bool has_pop_back_v<C, std::void_t<decltype(C().pop_back())>> = true;
138
139template<typename, typename = void>
140inline constexpr bool has_iterator_v = false;
141template<typename C>
142inline constexpr bool has_iterator_v<C, std::void_t<iterator<C>>> = true;
143
144template<typename, typename = void>
145inline constexpr bool has_const_iterator_v = false;
146template<typename C>
147inline constexpr bool has_const_iterator_v<C, std::void_t<const_iterator<C>>> = true;
148
149template<typename, typename = void>
150inline constexpr bool can_set_value_at_iterator_v = false;
151template<typename C>
152inline constexpr bool can_set_value_at_iterator_v<C, std::void_t<decltype(*C().begin() = value_type<C>())>> = true;
153
154template<typename, typename = void>
155inline constexpr bool can_set_mapped_at_iterator_v = false;
156template<typename C>
157inline constexpr bool can_set_mapped_at_iterator_v<C, std::void_t<decltype(*C().begin() = mapped_type<C>())>> = true;
158
159template<typename, typename = void>
160inline constexpr bool can_insert_value_at_iterator_v = false;
161template<typename C>
162inline constexpr bool can_insert_value_at_iterator_v<C, std::void_t<decltype(C().insert(C().begin(), value_type<C>()))>> = true;
163
164template<typename, typename = void>
165inline constexpr bool can_erase_at_iterator_v = false;
166template<typename C>
167inline constexpr bool can_erase_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin()))>> = true;
168
169template<typename, typename = void>
170inline constexpr bool can_erase_range_at_iterator_v = false;
171template<typename C>
172inline constexpr bool can_erase_range_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin(), C().end()))>> = true;
173
174template<typename, typename = void>
175inline constexpr bool can_get_at_key_v = false;
176template<typename C>
177inline constexpr bool can_get_at_key_v<C, std::void_t<mapped_type<C>(decltype(C()[key_type<C>()]))>> = true;
178
179template<typename, typename = void>
180inline constexpr bool can_set_at_key_v = false;
181template<typename C>
182inline constexpr bool can_set_at_key_v<C, std::void_t<decltype(C()[key_type<C>()] = mapped_type<C>())>> = true;
183
184template<typename, typename = void>
185inline constexpr bool can_erase_at_key_v = false;
186template<typename C>
187inline constexpr bool can_erase_at_key_v<C, std::void_t<decltype(C().erase(key_type<C>()))>> = true;
188
189template<typename, typename = void>
190inline constexpr bool can_remove_at_key_v = false;
191template<typename C>
192inline constexpr bool can_remove_at_key_v<C, std::void_t<decltype(C().remove(key_type<C>()))>> = true;
193
194template<typename, typename = void>
195inline constexpr bool can_insert_key_v = false;
196template<typename C>
197inline constexpr bool can_insert_key_v<C, std::void_t<decltype(C().insert(key_type<C>()))>> = true;
198
199template<typename, typename = void>
200inline constexpr bool can_insert_pair_v = false;
201template<typename C>
202inline constexpr bool can_insert_pair_v<C, std::void_t<decltype(C().insert({key_type<C>(), mapped_type<C>()}))>> = true;
203
204template<typename, typename = void>
205inline constexpr bool can_insert_key_mapped_v = false;
206template<typename C>
207inline constexpr bool can_insert_key_mapped_v<C, std::void_t<decltype(C().insert(key_type<C>(), mapped_type<C>()))>> = true;
208
209template<typename, typename = void>
210inline constexpr bool has_contains_v = false;
211template<typename C>
212inline constexpr bool has_contains_v<C, std::void_t<decltype(bool(C().contains(key_type<C>())))>> = true;
213
214template<typename, typename = void>
215inline constexpr bool has_find_v = false;
216template<typename C>
217inline constexpr bool has_find_v<C, std::void_t<decltype(C().find(key_type<C>()))>> = true;
218
219template<typename, typename = void>
220inline constexpr bool iterator_dereferences_to_value_v = false;
221template<typename C>
222inline constexpr bool iterator_dereferences_to_value_v<C, std::void_t<decltype(value_type<C>(*C().begin()))>> = true;
223
224template<typename, typename = void>
225inline constexpr bool iterator_has_key_v = false;
226template<typename C>
227inline constexpr bool iterator_has_key_v<C, std::void_t<decltype(key_type<C>(C().begin().key()))>> = true;
228
229template<typename, typename = void>
230inline constexpr bool value_type_has_first_v = false;
231template<typename C>
232inline constexpr bool value_type_has_first_v<C, std::void_t<decltype(key_type<C>(value_type<C>().first))>> = true;
233
234template<typename, typename = void>
235inline constexpr bool iterator_dereferences_to_key_v = false;
236template<typename C>
237inline constexpr bool iterator_dereferences_to_key_v<C, std::void_t<decltype(key_type<C>(*C().begin()))>> = true;
238
239template<typename, typename = void>
240inline constexpr bool iterator_has_value_v = false;
241template<typename C>
242inline constexpr bool iterator_has_value_v<C, std::void_t<decltype(mapped_type<C>(C().begin().value()))>> = true;
243
244template<typename, typename = void>
245inline constexpr bool value_type_has_second_v = false;
246template<typename C>
247inline constexpr bool value_type_has_second_v<C, std::void_t<decltype(mapped_type<C>(value_type<C>().second))>> = true;
248
249template<typename, typename = void>
250inline constexpr bool iterator_dereferences_to_mapped_v = false;
251template<typename C>
252inline constexpr bool iterator_dereferences_to_mapped_v<C, std::void_t<decltype(mapped_type<C>(*C().begin()))>> = true;
253
254QT_WARNING_POP
255
256}
257
258QT_END_NAMESPACE
259
260#endif // QCONTAINERINFO_H
261