summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qcontainerinfo.h
blob: 14468510a5a6049daf12cae7497769c33a13a3f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QCONTAINERINFO_H
#define QCONTAINERINFO_H

#include <QtCore/qglobal.h>
#include <type_traits>

QT_BEGIN_NAMESPACE

namespace QContainerInfo {

template<typename C>
using value_type = typename C::value_type;

template<typename C>
using key_type = typename C::key_type;

template<typename C>
using mapped_type = typename C::mapped_type;

template<typename C>
using iterator = typename C::iterator;

template<typename C>
using const_iterator = typename C::const_iterator;

// Some versions of Apple clang warn about the constexpr variables below being unused.
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wunused-const-variable")

template<typename C, typename = void>
inline constexpr bool has_value_type_v = false;
template<typename C>
inline constexpr bool has_value_type_v<C, std::void_t<value_type<C>>> = true;

template<typename C, typename = void>
inline constexpr bool has_key_type_v = false;
template<typename C>
inline constexpr bool has_key_type_v<C, std::void_t<key_type<C>>> = true;

template<typename C, typename = void>
inline constexpr bool has_mapped_type_v = false;
template<typename C>
inline constexpr bool has_mapped_type_v<C, std::void_t<mapped_type<C>>> = true;

template<typename C, typename = void>
inline constexpr bool has_size_v = false;
template<typename C>
inline constexpr bool has_size_v<C, std::void_t<decltype(C().size())>> = true;

template<typename C, typename = void>
inline constexpr bool has_reserve_v = false;
template<typename C>
inline constexpr bool has_reserve_v<C, std::void_t<decltype(C().reserve(0))>> = true;

template<typename C, typename = void>
inline constexpr bool has_clear_v = false;
template<typename C>
inline constexpr bool has_clear_v<C, std::void_t<decltype(C().clear())>> = true;

template<typename, typename = void>
inline constexpr bool has_at_index_v = false;
template<typename C>
inline constexpr bool has_at_index_v<C, std::void_t<decltype(C().at(0))>> = true;

template<typename, typename = void>
inline constexpr bool has_at_key_v = false;
template<typename C>
inline constexpr bool has_at_key_v<C, std::void_t<decltype(C().at(key_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool can_get_at_index_v = false;
template<typename C>
inline constexpr bool can_get_at_index_v<C, std::void_t<value_type<C>(decltype(C()[0]))>> = true;

template<typename, typename = void>
inline constexpr bool can_set_at_index_v = false;
template<typename C>
inline constexpr bool can_set_at_index_v<C, std::void_t<decltype(C()[0] = value_type<C>())>> = true;

template<typename, typename = void>
inline constexpr bool has_push_front_v = false;
template<typename C>
inline constexpr bool has_push_front_v<C, std::void_t<decltype(C().push_front(value_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool has_push_back_v = false;
template<typename C>
inline constexpr bool has_push_back_v<C, std::void_t<decltype(C().push_back(value_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool has_insert_v = false;
template<typename C>
inline constexpr bool has_insert_v<C, std::void_t<decltype(C().insert(value_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool has_pop_front_v = false;
template<typename C>
inline constexpr bool has_pop_front_v<C, std::void_t<decltype(C().pop_front())>> = true;

template<typename, typename = void>
inline constexpr bool has_pop_back_v = false;
template<typename C>
inline constexpr bool has_pop_back_v<C, std::void_t<decltype(C().pop_back())>> = true;

template<typename, typename = void>
inline constexpr bool has_iterator_v = false;
template<typename C>
inline constexpr bool has_iterator_v<C, std::void_t<iterator<C>>> = true;

template<typename, typename = void>
inline constexpr bool has_const_iterator_v = false;
template<typename C>
inline constexpr bool has_const_iterator_v<C, std::void_t<const_iterator<C>>> = true;

template<typename, typename = void>
inline constexpr bool can_set_value_at_iterator_v = false;
template<typename C>
inline constexpr bool can_set_value_at_iterator_v<C, std::void_t<decltype(*C().begin() = value_type<C>())>> = true;

template<typename, typename = void>
inline constexpr bool can_set_mapped_at_iterator_v = false;
template<typename C>
inline constexpr bool can_set_mapped_at_iterator_v<C, std::void_t<decltype(*C().begin() = mapped_type<C>())>> = true;

template<typename, typename = void>
inline constexpr bool can_insert_value_at_iterator_v = false;
template<typename C>
inline constexpr bool can_insert_value_at_iterator_v<C, std::void_t<decltype(C().insert(C().begin(), value_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool can_erase_at_iterator_v = false;
template<typename C>
inline constexpr bool can_erase_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin()))>> = true;

template<typename, typename = void>
inline constexpr bool can_erase_range_at_iterator_v = false;
template<typename C>
inline constexpr bool can_erase_range_at_iterator_v<C, std::void_t<decltype(C().erase(C().begin(), C().end()))>> = true;

template<typename, typename = void>
inline constexpr bool can_get_at_key_v = false;
template<typename C>
inline constexpr bool can_get_at_key_v<C, std::void_t<mapped_type<C>(decltype(C()[key_type<C>()]))>> = true;

template<typename, typename = void>
inline constexpr bool can_set_at_key_v = false;
template<typename C>
inline constexpr bool can_set_at_key_v<C, std::void_t<decltype(C()[key_type<C>()] = mapped_type<C>())>> = true;

template<typename, typename = void>
inline constexpr bool can_erase_at_key_v = false;
template<typename C>
inline constexpr bool can_erase_at_key_v<C, std::void_t<decltype(C().erase(key_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool can_remove_at_key_v = false;
template<typename C>
inline constexpr bool can_remove_at_key_v<C, std::void_t<decltype(C().remove(key_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool can_insert_key_v = false;
template<typename C>
inline constexpr bool can_insert_key_v<C, std::void_t<decltype(C().insert(key_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool can_insert_pair_v = false;
template<typename C>
inline constexpr bool can_insert_pair_v<C, std::void_t<decltype(C().insert({key_type<C>(), mapped_type<C>()}))>> = true;

template<typename, typename = void>
inline constexpr bool can_insert_key_mapped_v = false;
template<typename C>
inline constexpr bool can_insert_key_mapped_v<C, std::void_t<decltype(C().insert(key_type<C>(), mapped_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool has_contains_v = false;
template<typename C>
inline constexpr bool has_contains_v<C, std::void_t<decltype(bool(C().contains(key_type<C>())))>> = true;

template<typename, typename = void>
inline constexpr bool has_find_v = false;
template<typename C>
inline constexpr bool has_find_v<C, std::void_t<decltype(C().find(key_type<C>()))>> = true;

template<typename, typename = void>
inline constexpr bool iterator_dereferences_to_value_v = false;
template<typename C>
inline constexpr bool iterator_dereferences_to_value_v<C, std::void_t<decltype(value_type<C>(*C().begin()))>> = true;

template<typename, typename = void>
inline constexpr bool iterator_has_key_v = false;
template<typename C>
inline constexpr bool iterator_has_key_v<C, std::void_t<decltype(key_type<C>(C().begin().key()))>> = true;

template<typename, typename = void>
inline constexpr bool value_type_has_first_v = false;
template<typename C>
inline constexpr bool value_type_has_first_v<C, std::void_t<decltype(key_type<C>(value_type<C>().first))>> = true;

template<typename, typename = void>
inline constexpr bool iterator_dereferences_to_key_v = false;
template<typename C>
inline constexpr bool iterator_dereferences_to_key_v<C, std::void_t<decltype(key_type<C>(*C().begin()))>> = true;

template<typename, typename = void>
inline constexpr bool iterator_has_value_v = false;
template<typename C>
inline constexpr bool iterator_has_value_v<C, std::void_t<decltype(mapped_type<C>(C().begin().value()))>> = true;

template<typename, typename = void>
inline constexpr bool value_type_has_second_v = false;
template<typename C>
inline constexpr bool value_type_has_second_v<C, std::void_t<decltype(mapped_type<C>(value_type<C>().second))>> = true;

template<typename, typename = void>
inline constexpr bool iterator_dereferences_to_mapped_v = false;
template<typename C>
inline constexpr bool iterator_dereferences_to_mapped_v<C, std::void_t<decltype(mapped_type<C>(*C().begin()))>> = true;

QT_WARNING_POP

}

QT_END_NAMESPACE

#endif // QCONTAINERINFO_H