| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
// Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the terms |
| 7 |
// of the GNU General Public License as published by the Free Software |
| 8 |
// Foundation; either version 3, or (at your option) any later |
| 9 |
// version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, but |
| 12 |
// WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
// General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#ifndef _GLIBCXX_TESTSUITE_CONTAINER_TRAITS_H |
| 21 |
#define _GLIBCXX_TESTSUITE_CONTAINER_TRAITS_H |
| 22 |
|
| 23 |
#include <bits/stdc++.h> |
| 24 |
#include <ext/vstring.h> |
| 25 |
#include <debug/string> |
| 26 |
|
| 27 |
namespace __gnu_test |
| 28 |
{ |
| 29 |
// Container traits. |
| 30 |
// Base class with default false values for all traits. |
| 31 |
struct traits_base |
| 32 |
{ |
| 33 |
// Type, nested type, and typedef related traits. |
| 34 |
typedef std::false_type is_container; |
| 35 |
typedef std::false_type is_adaptor; |
| 36 |
typedef std::false_type is_reversible; |
| 37 |
typedef std::false_type is_allocator_aware; |
| 38 |
typedef std::false_type is_associative; |
| 39 |
typedef std::false_type is_unordered; |
| 40 |
typedef std::false_type is_mapped; |
| 41 |
|
| 42 |
typedef std::false_type has_erase; |
| 43 |
typedef std::false_type has_erase_after; |
| 44 |
typedef std::false_type has_throwing_erase; |
| 45 |
typedef std::false_type has_insert; |
| 46 |
typedef std::false_type has_insert_after; |
| 47 |
typedef std::false_type has_emplace; |
| 48 |
typedef std::false_type has_push_pop; |
| 49 |
typedef std::false_type has_size_type_constructor; |
| 50 |
}; |
| 51 |
|
| 52 |
// Primary template does nothing. Specialize on each type under |
| 53 |
// test, derive off of traits_base and just add the true traits. |
| 54 |
template<typename _Tp> |
| 55 |
struct traits; |
| 56 |
|
| 57 |
// Specialize for each container. |
| 58 |
template<typename _Tp, size_t _Np> |
| 59 |
struct traits<std::array<_Tp, _Np>> : public traits_base |
| 60 |
{ |
| 61 |
typedef std::true_type is_container; |
| 62 |
typedef std::true_type is_reversible; |
| 63 |
}; |
| 64 |
|
| 65 |
template<typename _Tp1, typename _Tp2> |
| 66 |
struct traits<std::deque<_Tp1, _Tp2>> : public traits_base |
| 67 |
{ |
| 68 |
typedef std::true_type is_container; |
| 69 |
typedef std::true_type is_reversible; |
| 70 |
typedef std::true_type is_allocator_aware; |
| 71 |
|
| 72 |
typedef std::true_type has_erase; |
| 73 |
typedef std::true_type has_throwing_erase; |
| 74 |
typedef std::true_type has_insert; |
| 75 |
typedef std::true_type has_push_pop; |
| 76 |
typedef std::true_type has_size_type_constructor; |
| 77 |
typedef std::true_type has_emplace; |
| 78 |
}; |
| 79 |
|
| 80 |
template<typename _Tp1, typename _Tp2> |
| 81 |
struct traits<std::forward_list<_Tp1, _Tp2>> : public traits_base |
| 82 |
{ |
| 83 |
typedef std::true_type is_container; |
| 84 |
typedef std::true_type is_allocator_aware; |
| 85 |
|
| 86 |
typedef std::true_type has_erase_after; |
| 87 |
typedef std::true_type has_insert_after; |
| 88 |
typedef std::true_type has_push_pop; |
| 89 |
typedef std::true_type has_size_type_constructor; |
| 90 |
typedef std::true_type has_emplace; |
| 91 |
}; |
| 92 |
|
| 93 |
template<typename _Tp1, typename _Tp2> |
| 94 |
struct traits<std::list<_Tp1, _Tp2>> : public traits_base |
| 95 |
{ |
| 96 |
typedef std::true_type is_container; |
| 97 |
typedef std::true_type is_reversible; |
| 98 |
typedef std::true_type is_allocator_aware; |
| 99 |
|
| 100 |
typedef std::true_type has_erase; |
| 101 |
typedef std::true_type has_insert; |
| 102 |
typedef std::true_type has_push_pop; |
| 103 |
typedef std::true_type has_size_type_constructor; |
| 104 |
typedef std::true_type has_emplace; |
| 105 |
}; |
| 106 |
|
| 107 |
template<typename _Tp1, typename _Tp2> |
| 108 |
struct traits<std::vector<_Tp1, _Tp2>> : public traits_base |
| 109 |
{ |
| 110 |
typedef std::true_type is_container; |
| 111 |
typedef std::true_type is_reversible; |
| 112 |
typedef std::true_type is_allocator_aware; |
| 113 |
|
| 114 |
typedef std::true_type has_erase; |
| 115 |
typedef std::true_type has_throwing_erase; |
| 116 |
typedef std::true_type has_insert; |
| 117 |
typedef std::true_type has_size_type_constructor; |
| 118 |
typedef std::true_type has_emplace; |
| 119 |
}; |
| 120 |
|
| 121 |
template<typename _Tp1, typename _Tp2, typename _Tp3> |
| 122 |
struct traits<std::basic_string<_Tp1, _Tp2, _Tp3>> : public traits_base |
| 123 |
{ |
| 124 |
typedef std::true_type is_container; |
| 125 |
typedef std::true_type is_reversible; |
| 126 |
typedef std::true_type is_allocator_aware; |
| 127 |
|
| 128 |
typedef std::true_type has_erase; |
| 129 |
typedef std::true_type has_insert; |
| 130 |
}; |
| 131 |
|
| 132 |
template<typename _Tp1, typename _Tp2, typename _Tp3> |
| 133 |
struct traits<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>> : public traits_base |
| 134 |
{ |
| 135 |
typedef std::true_type is_container; |
| 136 |
typedef std::true_type is_reversible; |
| 137 |
typedef std::true_type is_allocator_aware; |
| 138 |
|
| 139 |
typedef std::true_type has_erase; |
| 140 |
typedef std::true_type has_insert; |
| 141 |
}; |
| 142 |
|
| 143 |
template<typename _Tp1, typename _Tp2, typename _Tp3, |
| 144 |
template <typename, typename, typename> class _Tp4> |
| 145 |
struct traits<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>> |
| 146 |
: public traits_base |
| 147 |
{ |
| 148 |
typedef std::true_type is_container; |
| 149 |
typedef std::true_type is_reversible; |
| 150 |
typedef std::true_type is_allocator_aware; |
| 151 |
|
| 152 |
typedef std::true_type has_erase; |
| 153 |
typedef std::true_type has_insert; |
| 154 |
}; |
| 155 |
|
| 156 |
template<typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> |
| 157 |
struct traits<std::map<_Tp1, _Tp2, _Tp3, _Tp4>> : public traits_base |
| 158 |
{ |
| 159 |
typedef std::true_type is_container; |
| 160 |
typedef std::true_type is_reversible; |
| 161 |
typedef std::true_type is_allocator_aware; |
| 162 |
typedef std::true_type is_associative; |
| 163 |
typedef std::true_type is_mapped; |
| 164 |
|
| 165 |
typedef std::true_type has_erase; |
| 166 |
typedef std::true_type has_insert; |
| 167 |
typedef std::true_type has_emplace; |
| 168 |
}; |
| 169 |
|
| 170 |
template<typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> |
| 171 |
struct traits<std::multimap<_Tp1, _Tp2, _Tp3, _Tp4>> : public traits_base |
| 172 |
{ |
| 173 |
typedef std::true_type is_container; |
| 174 |
typedef std::true_type is_reversible; |
| 175 |
typedef std::true_type is_allocator_aware; |
| 176 |
typedef std::true_type is_associative; |
| 177 |
typedef std::true_type is_mapped; |
| 178 |
|
| 179 |
typedef std::true_type has_erase; |
| 180 |
typedef std::true_type has_insert; |
| 181 |
typedef std::true_type has_emplace; |
| 182 |
}; |
| 183 |
|
| 184 |
template<typename _Tp1, typename _Tp2, typename _Tp3> |
| 185 |
struct traits<std::set<_Tp1, _Tp2, _Tp3>> : public traits_base |
| 186 |
{ |
| 187 |
typedef std::true_type is_container; |
| 188 |
typedef std::true_type is_reversible; |
| 189 |
typedef std::true_type is_allocator_aware; |
| 190 |
typedef std::true_type is_associative; |
| 191 |
|
| 192 |
typedef std::true_type has_erase; |
| 193 |
typedef std::true_type has_insert; |
| 194 |
typedef std::true_type has_emplace; |
| 195 |
}; |
| 196 |
|
| 197 |
template<typename _Tp1, typename _Tp2, typename _Tp3> |
| 198 |
struct traits<std::multiset<_Tp1, _Tp2, _Tp3>> : public traits_base |
| 199 |
{ |
| 200 |
typedef std::true_type is_container; |
| 201 |
typedef std::true_type is_reversible; |
| 202 |
typedef std::true_type is_allocator_aware; |
| 203 |
typedef std::true_type is_associative; |
| 204 |
|
| 205 |
typedef std::true_type has_erase; |
| 206 |
typedef std::true_type has_insert; |
| 207 |
typedef std::true_type has_emplace; |
| 208 |
}; |
| 209 |
|
| 210 |
template<typename _Tp1, typename _Tp2> |
| 211 |
struct traits<std::priority_queue<_Tp1, _Tp2>> : public traits_base |
| 212 |
{ |
| 213 |
typedef std::true_type is_adaptor; |
| 214 |
}; |
| 215 |
|
| 216 |
template<typename _Tp1, typename _Tp2> |
| 217 |
struct traits<std::queue<_Tp1, _Tp2>> : public traits_base |
| 218 |
{ |
| 219 |
typedef std::true_type is_adaptor; |
| 220 |
}; |
| 221 |
|
| 222 |
template<typename _Tp1, typename _Tp2> |
| 223 |
struct traits<std::stack<_Tp1, _Tp2> > : public traits_base |
| 224 |
{ |
| 225 |
typedef std::true_type is_adaptor; |
| 226 |
}; |
| 227 |
|
| 228 |
template<typename _Tp1, typename _Tp2, typename _Tp3, |
| 229 |
typename _Tp4, typename _Tp5> |
| 230 |
struct traits<std::unordered_map<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5>> |
| 231 |
: public traits_base |
| 232 |
{ |
| 233 |
typedef std::true_type is_container; |
| 234 |
typedef std::true_type is_allocator_aware; |
| 235 |
typedef std::true_type is_unordered; |
| 236 |
typedef std::true_type is_mapped; |
| 237 |
|
| 238 |
typedef std::true_type has_erase; |
| 239 |
typedef std::true_type has_insert; |
| 240 |
typedef std::true_type has_emplace; |
| 241 |
}; |
| 242 |
|
| 243 |
template<typename _Tp1, typename _Tp2, typename _Tp3, |
| 244 |
typename _Tp4, typename _Tp5> |
| 245 |
struct traits<std::unordered_multimap<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5>> |
| 246 |
: public traits_base |
| 247 |
{ |
| 248 |
typedef std::true_type is_container; |
| 249 |
typedef std::true_type is_allocator_aware; |
| 250 |
typedef std::true_type is_unordered; |
| 251 |
typedef std::true_type is_mapped; |
| 252 |
|
| 253 |
typedef std::true_type has_erase; |
| 254 |
typedef std::true_type has_insert; |
| 255 |
typedef std::true_type has_emplace; |
| 256 |
}; |
| 257 |
|
| 258 |
template<typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> |
| 259 |
struct traits<std::unordered_multiset<_Tp1, _Tp2, _Tp3, _Tp4>> |
| 260 |
: public traits_base |
| 261 |
{ |
| 262 |
typedef std::true_type is_container; |
| 263 |
typedef std::true_type is_allocator_aware; |
| 264 |
typedef std::true_type is_unordered; |
| 265 |
|
| 266 |
typedef std::true_type has_erase; |
| 267 |
typedef std::true_type has_insert; |
| 268 |
typedef std::true_type has_emplace; |
| 269 |
}; |
| 270 |
|
| 271 |
template<typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> |
| 272 |
struct traits<std::unordered_set<_Tp1, _Tp2, _Tp3, _Tp4>> |
| 273 |
: public traits_base |
| 274 |
{ |
| 275 |
typedef std::true_type is_container; |
| 276 |
typedef std::true_type is_allocator_aware; |
| 277 |
typedef std::true_type is_unordered; |
| 278 |
|
| 279 |
typedef std::true_type has_erase; |
| 280 |
typedef std::true_type has_insert; |
| 281 |
typedef std::true_type has_emplace; |
| 282 |
}; |
| 283 |
} // namespace __gnu_test |
| 284 |
|
| 285 |
#endif |