| 1 | |
| 2 | // Copyright 2005-2009 Daniel James. |
| 3 | // Copyright 2022-2023 Christian Mazakas. |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | #if defined(BOOST_MSVC) |
| 8 | #pragma warning(push) |
| 9 | #pragma warning(disable : 4100) // unreferenced formal parameter |
| 10 | #pragma warning(disable : 4610) // class can never be instantiated |
| 11 | #pragma warning(disable : 4510) // default constructor could not be generated |
| 12 | #endif |
| 13 | |
| 14 | #include <boost/concept_check.hpp> |
| 15 | |
| 16 | #if defined(BOOST_MSVC) |
| 17 | #pragma warning(pop) |
| 18 | #endif |
| 19 | |
| 20 | #include "../helpers/check_return_type.hpp" |
| 21 | #include <boost/core/invoke_swap.hpp> |
| 22 | #include <boost/core/pointer_traits.hpp> |
| 23 | #include <boost/limits.hpp> |
| 24 | #include <boost/predef.h> |
| 25 | #include <boost/static_assert.hpp> |
| 26 | #include <boost/tuple/tuple.hpp> |
| 27 | #include <boost/type_traits/cv_traits.hpp> |
| 28 | #include <boost/type_traits/is_const.hpp> |
| 29 | #include <boost/type_traits/is_convertible.hpp> |
| 30 | #include <boost/type_traits/is_same.hpp> |
| 31 | |
| 32 | typedef long double comparison_type; |
| 33 | |
| 34 | template <class T> void sink(T const&) {} |
| 35 | template <class T> T rvalue(T const& v) { return v; } |
| 36 | template <class T> T rvalue_default() { return T(); } |
| 37 | |
| 38 | template <class T> T implicit_construct() { return {}; } |
| 39 | |
| 40 | #define TEST_NOEXCEPT_EXPR(x) BOOST_STATIC_ASSERT((noexcept(x))); |
| 41 | |
| 42 | template <class X, class T> void container_test(X& r, T const&) |
| 43 | { |
| 44 | typedef typename X::iterator iterator; |
| 45 | typedef typename X::const_iterator const_iterator; |
| 46 | typedef typename X::difference_type difference_type; |
| 47 | typedef typename X::size_type size_type; |
| 48 | |
| 49 | typedef |
| 50 | typename std::iterator_traits<iterator>::value_type iterator_value_type; |
| 51 | typedef typename std::iterator_traits<const_iterator>::value_type |
| 52 | const_iterator_value_type; |
| 53 | typedef typename std::iterator_traits<iterator>::difference_type |
| 54 | iterator_difference_type; |
| 55 | typedef typename std::iterator_traits<const_iterator>::difference_type |
| 56 | const_iterator_difference_type; |
| 57 | |
| 58 | typedef typename X::value_type value_type; |
| 59 | typedef typename X::reference reference; |
| 60 | typedef typename X::const_reference const_reference; |
| 61 | |
| 62 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 63 | typedef typename X::node_type node_type; |
| 64 | #endif |
| 65 | |
| 66 | typedef typename X::allocator_type allocator_type; |
| 67 | typedef typename X::pointer pointer; |
| 68 | typedef typename X::const_pointer const_pointer; |
| 69 | |
| 70 | BOOST_STATIC_ASSERT((boost::is_same<pointer, |
| 71 | typename boost::allocator_pointer<allocator_type>::type>::value)); |
| 72 | |
| 73 | BOOST_STATIC_ASSERT((boost::is_same<const_pointer, |
| 74 | typename boost::allocator_const_pointer<allocator_type>::type>::value)); |
| 75 | |
| 76 | // value_type |
| 77 | |
| 78 | BOOST_STATIC_ASSERT((boost::is_same<T, value_type>::value)); |
| 79 | boost::function_requires<boost::CopyConstructibleConcept<X> >(); |
| 80 | |
| 81 | // reference_type / const_reference_type |
| 82 | |
| 83 | BOOST_STATIC_ASSERT((boost::is_same<T&, reference>::value)); |
| 84 | BOOST_STATIC_ASSERT((boost::is_same<T const&, const_reference>::value)); |
| 85 | |
| 86 | // iterator |
| 87 | |
| 88 | boost::function_requires<boost::InputIteratorConcept<iterator> >(); |
| 89 | BOOST_STATIC_ASSERT((boost::is_same<T, iterator_value_type>::value)); |
| 90 | BOOST_STATIC_ASSERT((boost::is_convertible<iterator, const_iterator>::value)); |
| 91 | |
| 92 | // const_iterator |
| 93 | |
| 94 | boost::function_requires<boost::InputIteratorConcept<const_iterator> >(); |
| 95 | BOOST_STATIC_ASSERT((boost::is_same<T, const_iterator_value_type>::value)); |
| 96 | |
| 97 | // node_type |
| 98 | |
| 99 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 100 | BOOST_STATIC_ASSERT(( |
| 101 | boost::is_same<allocator_type, typename node_type::allocator_type>::value)); |
| 102 | #endif |
| 103 | |
| 104 | // difference_type |
| 105 | |
| 106 | BOOST_STATIC_ASSERT(std::numeric_limits<difference_type>::is_signed); |
| 107 | BOOST_STATIC_ASSERT(std::numeric_limits<difference_type>::is_integer); |
| 108 | BOOST_STATIC_ASSERT( |
| 109 | (boost::is_same<difference_type, iterator_difference_type>::value)); |
| 110 | BOOST_STATIC_ASSERT( |
| 111 | (boost::is_same<difference_type, const_iterator_difference_type>::value)); |
| 112 | |
| 113 | // size_type |
| 114 | |
| 115 | BOOST_STATIC_ASSERT(!std::numeric_limits<size_type>::is_signed); |
| 116 | BOOST_STATIC_ASSERT(std::numeric_limits<size_type>::is_integer); |
| 117 | |
| 118 | // size_type can represent any non-negative value type of difference_type |
| 119 | // I'm not sure about either of these tests... |
| 120 | size_type max_diff = |
| 121 | static_cast<size_type>((std::numeric_limits<difference_type>::max)()); |
| 122 | difference_type converted_diff(static_cast<difference_type>(max_diff)); |
| 123 | BOOST_TEST((std::numeric_limits<difference_type>::max)() == converted_diff); |
| 124 | |
| 125 | BOOST_TEST( |
| 126 | static_cast<comparison_type>((std::numeric_limits<size_type>::max)()) > |
| 127 | static_cast<comparison_type>( |
| 128 | (std::numeric_limits<difference_type>::max)())); |
| 129 | |
| 130 | // Constructors |
| 131 | |
| 132 | // I don't test the runtime post-conditions here. |
| 133 | |
| 134 | // It isn't specified in the container requirements that the no argument |
| 135 | // constructor is implicit, but it is defined that way in the concrete |
| 136 | // container specification. |
| 137 | X u_implicit = {}; |
| 138 | sink(u_implicit); |
| 139 | |
| 140 | X u; |
| 141 | BOOST_TEST(u.size() == 0); |
| 142 | BOOST_TEST(X().size() == 0); |
| 143 | |
| 144 | X a, b; |
| 145 | X a_const; |
| 146 | |
| 147 | sink(X(a)); |
| 148 | X u2(a); |
| 149 | X u3 = a; |
| 150 | X u4(rvalue(a_const)); |
| 151 | X u5 = rvalue(a_const); |
| 152 | |
| 153 | a.swap(b); |
| 154 | boost::core::invoke_swap(a, b); |
| 155 | test::check_return_type<X>::equals_ref(r = a); |
| 156 | |
| 157 | // Allocator |
| 158 | |
| 159 | test::check_return_type<allocator_type>::equals(a_const.get_allocator()); |
| 160 | |
| 161 | allocator_type m = a.get_allocator(); |
| 162 | sink(X(m)); |
| 163 | X c(m); |
| 164 | sink(X(a_const, m)); |
| 165 | X c2(a_const, m); |
| 166 | sink(X(rvalue(a_const), m)); |
| 167 | X c3(rvalue(a_const), m); |
| 168 | |
| 169 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 170 | // node_type |
| 171 | |
| 172 | implicit_construct<node_type const>(); |
| 173 | #if !BOOST_COMP_GNUC || BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(4, 8, 0) |
| 174 | TEST_NOEXCEPT_EXPR(node_type()); |
| 175 | #endif |
| 176 | |
| 177 | node_type n1; |
| 178 | node_type n2(rvalue_default<node_type>()); |
| 179 | #if !BOOST_COMP_GNUC || BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(4, 8, 0) |
| 180 | TEST_NOEXCEPT_EXPR(node_type(std::move(n1))); |
| 181 | #endif |
| 182 | node_type n3; |
| 183 | n3 = std::move(n2); |
| 184 | n1.swap(n3); |
| 185 | swap(n1, n3); |
| 186 | // TODO: noexcept for swap? |
| 187 | // value, key, mapped tests in map and set specific testing. |
| 188 | |
| 189 | node_type const n_const; |
| 190 | BOOST_TEST(n_const ? 0 : 1); |
| 191 | TEST_NOEXCEPT_EXPR(n_const ? 0 : 1); |
| 192 | test::check_return_type<bool>::equals(!n_const); |
| 193 | test::check_return_type<bool>::equals(n_const.empty()); |
| 194 | TEST_NOEXCEPT_EXPR(!n_const); |
| 195 | TEST_NOEXCEPT_EXPR(n_const.empty()); |
| 196 | #endif |
| 197 | |
| 198 | // Avoid unused variable warnings: |
| 199 | |
| 200 | sink(u); |
| 201 | sink(u2); |
| 202 | sink(u3); |
| 203 | sink(u4); |
| 204 | sink(u5); |
| 205 | sink(c); |
| 206 | sink(c2); |
| 207 | sink(c3); |
| 208 | } |
| 209 | |
| 210 | template <class X> void unordered_destructible_test(X&) |
| 211 | { |
| 212 | typedef typename X::iterator iterator; |
| 213 | typedef typename X::const_iterator const_iterator; |
| 214 | typedef typename X::size_type size_type; |
| 215 | |
| 216 | X x1; |
| 217 | |
| 218 | X x2(rvalue_default<X>()); |
| 219 | X x3 = rvalue_default<X>(); |
| 220 | // This can only be done if propagate_on_container_move_assignment::value |
| 221 | // is true. |
| 222 | // x2 = rvalue_default<X>(); |
| 223 | |
| 224 | X* ptr = new X(); |
| 225 | X& a1 = *ptr; |
| 226 | (&a1)->~X(); |
| 227 | ::operator delete((void*)(&a1)); |
| 228 | |
| 229 | X a, b; |
| 230 | X const a_const; |
| 231 | test::check_return_type<iterator>::equals(a.begin()); |
| 232 | test::check_return_type<const_iterator>::equals(a_const.begin()); |
| 233 | test::check_return_type<const_iterator>::equals(a.cbegin()); |
| 234 | test::check_return_type<const_iterator>::equals(a_const.cbegin()); |
| 235 | test::check_return_type<iterator>::equals(a.end()); |
| 236 | test::check_return_type<const_iterator>::equals(a_const.end()); |
| 237 | test::check_return_type<const_iterator>::equals(a.cend()); |
| 238 | test::check_return_type<const_iterator>::equals(a_const.cend()); |
| 239 | |
| 240 | a.swap(b); |
| 241 | boost::core::invoke_swap(a, b); |
| 242 | |
| 243 | test::check_return_type<size_type>::equals(a.size()); |
| 244 | test::check_return_type<size_type>::equals(a.max_size()); |
| 245 | test::check_return_type<bool>::convertible(a.empty()); |
| 246 | |
| 247 | // Allocator |
| 248 | |
| 249 | typedef typename X::allocator_type allocator_type; |
| 250 | test::check_return_type<allocator_type>::equals(a_const.get_allocator()); |
| 251 | } |
| 252 | |
| 253 | template <class X, class Key> void unordered_set_test(X& r, Key const&) |
| 254 | { |
| 255 | typedef typename X::value_type value_type; |
| 256 | typedef typename X::key_type key_type; |
| 257 | |
| 258 | BOOST_STATIC_ASSERT((boost::is_same<value_type, key_type>::value)); |
| 259 | |
| 260 | // iterator pointer / const_pointer_type |
| 261 | |
| 262 | typedef typename X::iterator iterator; |
| 263 | typedef typename X::const_iterator const_iterator; |
| 264 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 265 | typedef typename X::local_iterator local_iterator; |
| 266 | typedef typename X::const_local_iterator const_local_iterator; |
| 267 | #endif |
| 268 | typedef typename std::iterator_traits<iterator>::pointer iterator_pointer; |
| 269 | typedef typename std::iterator_traits<const_iterator>::pointer |
| 270 | const_iterator_pointer; |
| 271 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 272 | typedef typename std::iterator_traits<local_iterator>::pointer |
| 273 | local_iterator_pointer; |
| 274 | typedef typename std::iterator_traits<const_local_iterator>::pointer |
| 275 | const_local_iterator_pointer; |
| 276 | #endif |
| 277 | |
| 278 | BOOST_STATIC_ASSERT( |
| 279 | (boost::is_same<value_type const*, iterator_pointer>::value)); |
| 280 | BOOST_STATIC_ASSERT( |
| 281 | (boost::is_same<value_type const*, const_iterator_pointer>::value)); |
| 282 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 283 | BOOST_STATIC_ASSERT( |
| 284 | (boost::is_same<value_type const*, local_iterator_pointer>::value)); |
| 285 | BOOST_STATIC_ASSERT( |
| 286 | (boost::is_same<value_type const*, const_local_iterator_pointer>::value)); |
| 287 | #endif |
| 288 | |
| 289 | // pointer_traits<iterator> |
| 290 | |
| 291 | BOOST_STATIC_ASSERT((boost::is_same<iterator, |
| 292 | typename boost::pointer_traits<iterator>::pointer>::value)); |
| 293 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 294 | typename boost::pointer_traits<iterator>::element_type>::value)); |
| 295 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 296 | typename boost::pointer_traits<iterator>::difference_type>::value)); |
| 297 | |
| 298 | // pointer_traits<const_iterator> |
| 299 | |
| 300 | BOOST_STATIC_ASSERT((boost::is_same<const_iterator, |
| 301 | typename boost::pointer_traits<const_iterator>::pointer>::value)); |
| 302 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 303 | typename boost::pointer_traits<const_iterator>::element_type>::value)); |
| 304 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 305 | typename boost::pointer_traits<const_iterator>::difference_type>::value)); |
| 306 | |
| 307 | (void) r; |
| 308 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 309 | // pointer_traits<local_iterator> |
| 310 | |
| 311 | BOOST_STATIC_ASSERT((boost::is_same<local_iterator, |
| 312 | typename boost::pointer_traits<local_iterator>::pointer>::value)); |
| 313 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 314 | typename boost::pointer_traits<local_iterator>::element_type>::value)); |
| 315 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 316 | typename boost::pointer_traits<local_iterator>::difference_type>::value)); |
| 317 | |
| 318 | // pointer_traits<const_local_iterator> |
| 319 | |
| 320 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator, |
| 321 | typename boost::pointer_traits<const_local_iterator>::pointer>::value)); |
| 322 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 323 | typename boost::pointer_traits<const_local_iterator>::element_type>:: |
| 324 | value)); |
| 325 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 326 | typename boost::pointer_traits<const_local_iterator>::difference_type>:: |
| 327 | value)); |
| 328 | |
| 329 | typedef typename X::node_type node_type; |
| 330 | typedef typename node_type::value_type node_value_type; |
| 331 | BOOST_STATIC_ASSERT((boost::is_same<value_type, node_value_type>::value)); |
| 332 | |
| 333 | // Call node_type functions. |
| 334 | |
| 335 | test::minimal::constructor_param v; |
| 336 | Key k_lvalue(v); |
| 337 | r.emplace(std::move(k_lvalue)); |
| 338 | node_type n1 = r.extract(r.begin()); |
| 339 | test::check_return_type<value_type>::equals_ref(n1.value()); |
| 340 | #endif |
| 341 | } |
| 342 | |
| 343 | template <class X, class Key, class T> |
| 344 | void unordered_map_test(X& r, Key const& k, T const& v) |
| 345 | { |
| 346 | typedef typename X::value_type value_type; |
| 347 | typedef typename X::key_type key_type; |
| 348 | |
| 349 | BOOST_STATIC_ASSERT( |
| 350 | (boost::is_same<value_type, std::pair<key_type const, T> >::value)); |
| 351 | |
| 352 | // iterator pointer / const_pointer_type |
| 353 | |
| 354 | typedef typename X::iterator iterator; |
| 355 | typedef typename X::const_iterator const_iterator; |
| 356 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 357 | typedef typename X::local_iterator local_iterator; |
| 358 | typedef typename X::const_local_iterator const_local_iterator; |
| 359 | #endif |
| 360 | typedef typename std::iterator_traits<iterator>::pointer iterator_pointer; |
| 361 | typedef typename std::iterator_traits<const_iterator>::pointer |
| 362 | const_iterator_pointer; |
| 363 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 364 | typedef typename std::iterator_traits<local_iterator>::pointer |
| 365 | local_iterator_pointer; |
| 366 | typedef typename std::iterator_traits<const_local_iterator>::pointer |
| 367 | const_local_iterator_pointer; |
| 368 | #endif |
| 369 | |
| 370 | BOOST_STATIC_ASSERT((boost::is_same<value_type*, iterator_pointer>::value)); |
| 371 | BOOST_STATIC_ASSERT( |
| 372 | (boost::is_same<value_type const*, const_iterator_pointer>::value)); |
| 373 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 374 | BOOST_STATIC_ASSERT( |
| 375 | (boost::is_same<value_type*, local_iterator_pointer>::value)); |
| 376 | BOOST_STATIC_ASSERT( |
| 377 | (boost::is_same<value_type const*, const_local_iterator_pointer>::value)); |
| 378 | #endif |
| 379 | |
| 380 | // pointer_traits<iterator> |
| 381 | |
| 382 | BOOST_STATIC_ASSERT((boost::is_same<iterator, |
| 383 | typename boost::pointer_traits<iterator>::pointer>::value)); |
| 384 | BOOST_STATIC_ASSERT((boost::is_same<value_type, |
| 385 | typename boost::pointer_traits<iterator>::element_type>::value)); |
| 386 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 387 | typename boost::pointer_traits<iterator>::difference_type>::value)); |
| 388 | |
| 389 | // pointer_traits<const_iterator> |
| 390 | |
| 391 | BOOST_STATIC_ASSERT((boost::is_same<const_iterator, |
| 392 | typename boost::pointer_traits<const_iterator>::pointer>::value)); |
| 393 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 394 | typename boost::pointer_traits<const_iterator>::element_type>::value)); |
| 395 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 396 | typename boost::pointer_traits<const_iterator>::difference_type>::value)); |
| 397 | |
| 398 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 399 | // pointer_traits<local_iterator> |
| 400 | |
| 401 | BOOST_STATIC_ASSERT((boost::is_same<local_iterator, |
| 402 | typename boost::pointer_traits<local_iterator>::pointer>::value)); |
| 403 | BOOST_STATIC_ASSERT((boost::is_same<value_type, |
| 404 | typename boost::pointer_traits<local_iterator>::element_type>::value)); |
| 405 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 406 | typename boost::pointer_traits<local_iterator>::difference_type>::value)); |
| 407 | |
| 408 | // pointer_traits<const_local_iterator> |
| 409 | |
| 410 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator, |
| 411 | typename boost::pointer_traits<const_local_iterator>::pointer>::value)); |
| 412 | BOOST_STATIC_ASSERT((boost::is_same<value_type const, |
| 413 | typename boost::pointer_traits<const_local_iterator>::element_type>:: |
| 414 | value)); |
| 415 | BOOST_STATIC_ASSERT((boost::is_same<std::ptrdiff_t, |
| 416 | typename boost::pointer_traits<const_local_iterator>::difference_type>:: |
| 417 | value)); |
| 418 | |
| 419 | typedef typename X::node_type node_type; |
| 420 | typedef typename node_type::key_type node_key_type; |
| 421 | typedef typename node_type::mapped_type node_mapped_type; |
| 422 | |
| 423 | BOOST_STATIC_ASSERT((boost::is_same<Key, node_key_type>::value)); |
| 424 | BOOST_STATIC_ASSERT((boost::is_same<T, node_mapped_type>::value)); |
| 425 | // Superfluous,but just to make sure. |
| 426 | BOOST_STATIC_ASSERT((!boost::is_const<node_key_type>::value)); |
| 427 | #endif |
| 428 | |
| 429 | // Calling functions |
| 430 | |
| 431 | r.insert(std::pair<Key const, T>(k, v)); |
| 432 | r.insert(r.begin(), std::pair<Key const, T>(k, v)); |
| 433 | std::pair<Key const, T> const value(k, v); |
| 434 | r.insert(value); |
| 435 | r.insert(r.end(), value); |
| 436 | |
| 437 | Key k_lvalue(k); |
| 438 | T v_lvalue(v); |
| 439 | |
| 440 | // Emplace |
| 441 | |
| 442 | r.emplace(k, v); |
| 443 | r.emplace(k_lvalue, v_lvalue); |
| 444 | r.emplace(rvalue(k), rvalue(v)); |
| 445 | |
| 446 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 447 | r.emplace(std::piecewise_construct, std::make_tuple(k), std::make_tuple(v)); |
| 448 | #else |
| 449 | r.emplace(boost::unordered::piecewise_construct, boost::make_tuple(k), |
| 450 | boost::make_tuple(v)); |
| 451 | #endif |
| 452 | |
| 453 | // Emplace with hint |
| 454 | |
| 455 | r.emplace_hint(r.begin(), k, v); |
| 456 | r.emplace_hint(r.begin(), k_lvalue, v_lvalue); |
| 457 | r.emplace_hint(r.begin(), rvalue(k), rvalue(v)); |
| 458 | |
| 459 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 460 | r.emplace_hint(r.begin(), std::piecewise_construct, std::make_tuple(k), |
| 461 | std::make_tuple(v)); |
| 462 | #else |
| 463 | r.emplace_hint(r.begin(), boost::unordered::piecewise_construct, |
| 464 | boost::make_tuple(k), boost::make_tuple(v)); |
| 465 | #endif |
| 466 | |
| 467 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 468 | // Extract |
| 469 | |
| 470 | test::check_return_type<node_type>::equals(r.extract(r.begin())); |
| 471 | |
| 472 | r.emplace(k, v); |
| 473 | test::check_return_type<node_type>::equals(r.extract(k)); |
| 474 | |
| 475 | r.emplace(k, v); |
| 476 | node_type n1 = r.extract(r.begin()); |
| 477 | test::check_return_type<key_type>::equals_ref(n1.key()); |
| 478 | test::check_return_type<T>::equals_ref(n1.mapped()); |
| 479 | |
| 480 | node_type n2 = std::move(n1); |
| 481 | r.insert(std::move(n2)); |
| 482 | r.insert(r.extract(r.begin())); |
| 483 | n2 = r.extract(r.begin()); |
| 484 | r.insert(r.begin(), std::move(n2)); |
| 485 | r.insert(r.end(), r.extract(r.begin())); |
| 486 | |
| 487 | node_type n = r.extract(r.begin()); |
| 488 | test::check_return_type<node_key_type>::equals_ref(n.key()); |
| 489 | test::check_return_type<node_mapped_type>::equals_ref(n.mapped()); |
| 490 | #endif |
| 491 | } |
| 492 | |
| 493 | template <class X> void equality_test(X& r) |
| 494 | { |
| 495 | X const a = r, b = r; |
| 496 | |
| 497 | test::check_return_type<bool>::equals(a == b); |
| 498 | test::check_return_type<bool>::equals(a != b); |
| 499 | } |
| 500 | |
| 501 | template <class X, class T> void unordered_unique_test(X& r, T const& t) |
| 502 | { |
| 503 | typedef typename X::iterator iterator; |
| 504 | test::check_return_type<std::pair<iterator, bool> >::equals(r.insert(t)); |
| 505 | test::check_return_type<std::pair<iterator, bool> >::equals(r.emplace(t)); |
| 506 | |
| 507 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 508 | typedef typename X::node_type node_type; |
| 509 | typedef typename X::insert_return_type insert_return_type; |
| 510 | |
| 511 | // insert_return_type |
| 512 | |
| 513 | // TODO; |
| 514 | // boost::function_requires< |
| 515 | // std::moveConstructibleConcept<insert_return_type> |
| 516 | // >(); |
| 517 | // TODO; |
| 518 | // boost::function_requires< |
| 519 | // std::moveAssignableConcept<insert_return_type> |
| 520 | // >(); |
| 521 | boost::function_requires< |
| 522 | boost::DefaultConstructibleConcept<insert_return_type> >(); |
| 523 | // TODO: |
| 524 | // boost::function_requires< |
| 525 | // boost::DestructibleConcept<insert_return_type> |
| 526 | // >(); |
| 527 | insert_return_type insert_return, insert_return2; |
| 528 | test::check_return_type<bool>::equals(insert_return.inserted); |
| 529 | test::check_return_type<iterator>::equals(insert_return.position); |
| 530 | test::check_return_type<node_type>::equals_ref(insert_return.node); |
| 531 | boost::core::invoke_swap(insert_return, insert_return2); |
| 532 | #endif |
| 533 | } |
| 534 | |
| 535 | template <class X, class T> void unordered_equivalent_test(X& r, T const& t) |
| 536 | { |
| 537 | typedef typename X::iterator iterator; |
| 538 | test::check_return_type<iterator>::equals(r.insert(t)); |
| 539 | test::check_return_type<iterator>::equals(r.emplace(t)); |
| 540 | } |
| 541 | |
| 542 | template <class X, class Key, class T> |
| 543 | void unordered_map_functions(X&, Key const& k, T const& v) |
| 544 | { |
| 545 | typedef typename X::mapped_type mapped_type; |
| 546 | typedef typename X::iterator iterator; |
| 547 | |
| 548 | X a; |
| 549 | test::check_return_type<mapped_type>::equals_ref(a[k]); |
| 550 | test::check_return_type<mapped_type>::equals_ref(a[rvalue(k)]); |
| 551 | test::check_return_type<mapped_type>::equals_ref(a.at(k)); |
| 552 | test::check_return_type<std::pair<iterator, bool> >::equals( |
| 553 | a.try_emplace(k, v)); |
| 554 | test::check_return_type<std::pair<iterator, bool> >::equals( |
| 555 | a.try_emplace(rvalue(k), v)); |
| 556 | test::check_return_type<iterator>::equals(a.try_emplace(a.begin(), k, v)); |
| 557 | test::check_return_type<iterator>::equals( |
| 558 | a.try_emplace(a.begin(), rvalue(k), v)); |
| 559 | test::check_return_type<std::pair<iterator, bool> >::equals( |
| 560 | a.insert_or_assign(k, v)); |
| 561 | test::check_return_type<std::pair<iterator, bool> >::equals( |
| 562 | a.insert_or_assign(rvalue(k), v)); |
| 563 | test::check_return_type<iterator>::equals( |
| 564 | a.insert_or_assign(a.begin(), k, v)); |
| 565 | test::check_return_type<iterator>::equals( |
| 566 | a.insert_or_assign(a.begin(), rvalue(k), v)); |
| 567 | |
| 568 | X const b = a; |
| 569 | test::check_return_type<mapped_type const>::equals_ref(b.at(k)); |
| 570 | } |
| 571 | |
| 572 | template <class X, class Key, class Hash, class Pred> |
| 573 | void unordered_test(X& x, Key& k, Hash& hf, Pred& eq) |
| 574 | { |
| 575 | unordered_destructible_test(x); |
| 576 | |
| 577 | typedef typename X::key_type key_type; |
| 578 | typedef typename X::hasher hasher; |
| 579 | typedef typename X::key_equal key_equal; |
| 580 | typedef typename X::size_type size_type; |
| 581 | |
| 582 | typedef typename X::iterator iterator; |
| 583 | typedef typename X::const_iterator const_iterator; |
| 584 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 585 | typedef typename X::local_iterator local_iterator; |
| 586 | typedef typename X::const_local_iterator const_local_iterator; |
| 587 | |
| 588 | typedef typename std::iterator_traits<iterator>::iterator_category |
| 589 | iterator_category; |
| 590 | typedef typename std::iterator_traits<iterator>::difference_type |
| 591 | iterator_difference; |
| 592 | typedef typename std::iterator_traits<iterator>::pointer iterator_pointer; |
| 593 | typedef typename std::iterator_traits<iterator>::reference iterator_reference; |
| 594 | |
| 595 | typedef typename std::iterator_traits<local_iterator>::iterator_category |
| 596 | local_iterator_category; |
| 597 | typedef typename std::iterator_traits<local_iterator>::difference_type |
| 598 | local_iterator_difference; |
| 599 | typedef typename std::iterator_traits<local_iterator>::pointer |
| 600 | local_iterator_pointer; |
| 601 | typedef typename std::iterator_traits<local_iterator>::reference |
| 602 | local_iterator_reference; |
| 603 | |
| 604 | typedef typename std::iterator_traits<const_iterator>::iterator_category |
| 605 | const_iterator_category; |
| 606 | typedef typename std::iterator_traits<const_iterator>::difference_type |
| 607 | const_iterator_difference; |
| 608 | typedef typename std::iterator_traits<const_iterator>::pointer |
| 609 | const_iterator_pointer; |
| 610 | typedef typename std::iterator_traits<const_iterator>::reference |
| 611 | const_iterator_reference; |
| 612 | |
| 613 | typedef typename std::iterator_traits<const_local_iterator>::iterator_category |
| 614 | const_local_iterator_category; |
| 615 | typedef typename std::iterator_traits<const_local_iterator>::difference_type |
| 616 | const_local_iterator_difference; |
| 617 | typedef typename std::iterator_traits<const_local_iterator>::pointer |
| 618 | const_local_iterator_pointer; |
| 619 | typedef typename std::iterator_traits<const_local_iterator>::reference |
| 620 | const_local_iterator_reference; |
| 621 | #endif |
| 622 | typedef typename X::allocator_type allocator_type; |
| 623 | |
| 624 | BOOST_STATIC_ASSERT((boost::is_same<Key, key_type>::value)); |
| 625 | // boost::function_requires<boost::CopyConstructibleConcept<key_type> >(); |
| 626 | // boost::function_requires<boost::AssignableConcept<key_type> >(); |
| 627 | |
| 628 | BOOST_STATIC_ASSERT((boost::is_same<Hash, hasher>::value)); |
| 629 | test::check_return_type<std::size_t>::equals(hf(k)); |
| 630 | |
| 631 | BOOST_STATIC_ASSERT((boost::is_same<Pred, key_equal>::value)); |
| 632 | test::check_return_type<bool>::convertible(eq(k, k)); |
| 633 | |
| 634 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 635 | boost::function_requires<boost::InputIteratorConcept<local_iterator> >(); |
| 636 | BOOST_STATIC_ASSERT( |
| 637 | (boost::is_same<local_iterator_category, iterator_category>::value)); |
| 638 | BOOST_STATIC_ASSERT( |
| 639 | (boost::is_same<local_iterator_difference, iterator_difference>::value)); |
| 640 | BOOST_STATIC_ASSERT( |
| 641 | (boost::is_same<local_iterator_pointer, iterator_pointer>::value)); |
| 642 | BOOST_STATIC_ASSERT( |
| 643 | (boost::is_same<local_iterator_reference, iterator_reference>::value)); |
| 644 | |
| 645 | boost::function_requires< |
| 646 | boost::InputIteratorConcept<const_local_iterator> >(); |
| 647 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator_category, |
| 648 | const_iterator_category>::value)); |
| 649 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator_difference, |
| 650 | const_iterator_difference>::value)); |
| 651 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator_pointer, |
| 652 | const_iterator_pointer>::value)); |
| 653 | BOOST_STATIC_ASSERT((boost::is_same<const_local_iterator_reference, |
| 654 | const_iterator_reference>::value)); |
| 655 | #endif |
| 656 | |
| 657 | X a; |
| 658 | allocator_type m = a.get_allocator(); |
| 659 | |
| 660 | // Constructors |
| 661 | |
| 662 | X(10, hf, eq); |
| 663 | X a1(10, hf, eq); |
| 664 | X(10, hf); |
| 665 | X a2(10, hf); |
| 666 | X(10); |
| 667 | X a3(10); |
| 668 | X(); |
| 669 | X a4; |
| 670 | |
| 671 | X(10, hf, eq, m); |
| 672 | X a1a(10, hf, eq, m); |
| 673 | X(10, hf, m); |
| 674 | X a2a(10, hf, m); |
| 675 | X(10, m); |
| 676 | X a3a(10, m); |
| 677 | (X(m)); |
| 678 | X a4a(m); |
| 679 | |
| 680 | test::check_return_type<size_type>::equals(a.erase(k)); |
| 681 | |
| 682 | const_iterator q1 = a.cbegin(), q2 = a.cend(); |
| 683 | test::check_return_type<iterator>::equals(a.erase(q1, q2)); |
| 684 | |
| 685 | TEST_NOEXCEPT_EXPR(a.clear()) |
| 686 | a.clear(); |
| 687 | |
| 688 | X const b; |
| 689 | |
| 690 | test::check_return_type<hasher>::equals(b.hash_function()); |
| 691 | test::check_return_type<key_equal>::equals(b.key_eq()); |
| 692 | |
| 693 | test::check_return_type<iterator>::equals(a.find(k)); |
| 694 | test::check_return_type<const_iterator>::equals(b.find(k)); |
| 695 | test::check_return_type<size_type>::equals(b.count(k)); |
| 696 | test::check_return_type<std::pair<iterator, iterator> >::equals( |
| 697 | a.equal_range(k)); |
| 698 | test::check_return_type<std::pair<const_iterator, const_iterator> >::equals( |
| 699 | b.equal_range(k)); |
| 700 | test::check_return_type<size_type>::equals(b.bucket_count()); |
| 701 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 702 | test::check_return_type<size_type>::equals(b.max_bucket_count()); |
| 703 | test::check_return_type<size_type>::equals(b.bucket(k)); |
| 704 | test::check_return_type<size_type>::equals(b.bucket_size(0)); |
| 705 | |
| 706 | test::check_return_type<local_iterator>::equals(a.begin(0)); |
| 707 | test::check_return_type<const_local_iterator>::equals(b.begin(0)); |
| 708 | test::check_return_type<local_iterator>::equals(a.end(0)); |
| 709 | test::check_return_type<const_local_iterator>::equals(b.end(0)); |
| 710 | |
| 711 | test::check_return_type<const_local_iterator>::equals(a.cbegin(0)); |
| 712 | test::check_return_type<const_local_iterator>::equals(b.cbegin(0)); |
| 713 | test::check_return_type<const_local_iterator>::equals(a.cend(0)); |
| 714 | test::check_return_type<const_local_iterator>::equals(b.cend(0)); |
| 715 | #endif |
| 716 | |
| 717 | test::check_return_type<float>::equals(b.load_factor()); |
| 718 | test::check_return_type<float>::equals(b.max_load_factor()); |
| 719 | a.max_load_factor((float)2.0); |
| 720 | a.rehash(100); |
| 721 | |
| 722 | a.merge(a2); |
| 723 | a.merge(rvalue_default<X>()); |
| 724 | |
| 725 | // Avoid unused variable warnings: |
| 726 | |
| 727 | sink(a); |
| 728 | sink(a1); |
| 729 | sink(a2); |
| 730 | sink(a3); |
| 731 | sink(a4); |
| 732 | sink(a1a); |
| 733 | sink(a2a); |
| 734 | sink(a3a); |
| 735 | sink(a4a); |
| 736 | } |
| 737 | |
| 738 | template <class X, class Key, class T, class Hash, class Pred> |
| 739 | void unordered_copyable_test(X& x, Key& k, T& t, Hash& hf, Pred& eq) |
| 740 | { |
| 741 | unordered_test(x, k, hf, eq); |
| 742 | |
| 743 | typedef typename X::iterator iterator; |
| 744 | typedef typename X::const_iterator const_iterator; |
| 745 | typedef typename X::allocator_type allocator_type; |
| 746 | |
| 747 | X a; |
| 748 | allocator_type m = a.get_allocator(); |
| 749 | |
| 750 | typename X::value_type* i = 0; |
| 751 | typename X::value_type* j = 0; |
| 752 | |
| 753 | // Constructors |
| 754 | |
| 755 | X(i, j, 10, hf, eq); |
| 756 | X a5(i, j, 10, hf, eq); |
| 757 | X(i, j, 10, hf); |
| 758 | X a6(i, j, 10, hf); |
| 759 | X(i, j, 10); |
| 760 | X a7(i, j, 10); |
| 761 | X(i, j); |
| 762 | X a8(i, j); |
| 763 | |
| 764 | X(i, j, 10, hf, eq, m); |
| 765 | X a5a(i, j, 10, hf, eq, m); |
| 766 | X(i, j, 10, hf, m); |
| 767 | X a6a(i, j, 10, hf, m); |
| 768 | X(i, j, 10, m); |
| 769 | X a7a(i, j, 10, m); |
| 770 | |
| 771 | // Not specified for some reason (maybe ambiguity with another constructor?) |
| 772 | // X(i, j, m); |
| 773 | // X a8a(i, j, m); |
| 774 | // sink(a8a); |
| 775 | |
| 776 | std::size_t min_buckets = 10; |
| 777 | X({t}); |
| 778 | X({t}, min_buckets); |
| 779 | X({t}, min_buckets, hf); |
| 780 | X({t}, min_buckets, hf, eq); |
| 781 | // X({t}, m); |
| 782 | X({t}, min_buckets, m); |
| 783 | X({t}, min_buckets, hf, m); |
| 784 | X({t}, min_buckets, hf, eq, m); |
| 785 | |
| 786 | X const b; |
| 787 | sink(X(b)); |
| 788 | X a9(b); |
| 789 | a = b; |
| 790 | |
| 791 | sink(X(b, m)); |
| 792 | X a9a(b, m); |
| 793 | |
| 794 | X b1; |
| 795 | b1.insert(t); |
| 796 | X a9b(b1); |
| 797 | sink(a9b); |
| 798 | X a9c(b1, m); |
| 799 | sink(a9c); |
| 800 | |
| 801 | const_iterator q = a.cbegin(); |
| 802 | |
| 803 | test::check_return_type<iterator>::equals(a.insert(q, t)); |
| 804 | test::check_return_type<iterator>::equals(a.emplace_hint(q, t)); |
| 805 | |
| 806 | a.insert(i, j); |
| 807 | std::initializer_list<T> list = {t}; |
| 808 | a.insert(list); |
| 809 | a.insert({t, t, t}); |
| 810 | |
| 811 | #if !BOOST_WORKAROUND(BOOST_MSVC, < 1900) && \ |
| 812 | (!defined(__clang__) || __clang_major__ >= 4 || \ |
| 813 | (__clang_major__ == 3 && __clang_minor__ >= 4)) |
| 814 | a.insert({}); |
| 815 | a.insert({t}); |
| 816 | a.insert({t, t}); |
| 817 | #endif |
| 818 | |
| 819 | X a10; |
| 820 | a10.insert(t); |
| 821 | q = a10.cbegin(); |
| 822 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 823 | test::check_return_type<iterator>::convertible(a10.erase(q)); |
| 824 | #else |
| 825 | test::check_return_type<iterator>::equals(a10.erase(q)); |
| 826 | #endif |
| 827 | |
| 828 | // Avoid unused variable warnings: |
| 829 | |
| 830 | sink(a); |
| 831 | sink(a5); |
| 832 | sink(a6); |
| 833 | sink(a7); |
| 834 | sink(a8); |
| 835 | sink(a9); |
| 836 | sink(a5a); |
| 837 | sink(a6a); |
| 838 | sink(a7a); |
| 839 | sink(a9a); |
| 840 | |
| 841 | #ifndef BOOST_UNORDERED_FOA_TESTS |
| 842 | typedef typename X::node_type node_type; |
| 843 | typedef typename X::allocator_type allocator_type; |
| 844 | node_type const n_const = a.extract(a.begin()); |
| 845 | test::check_return_type<allocator_type>::equals(n_const.get_allocator()); |
| 846 | #endif |
| 847 | } |
| 848 | |
| 849 | template <class X, class Key, class T, class Hash, class Pred> |
| 850 | void unordered_movable_test(X& x, Key& k, T& /* t */, Hash& hf, Pred& eq) |
| 851 | { |
| 852 | unordered_test(x, k, hf, eq); |
| 853 | |
| 854 | typedef typename X::iterator iterator; |
| 855 | typedef typename X::const_iterator const_iterator; |
| 856 | typedef typename X::allocator_type allocator_type; |
| 857 | |
| 858 | X x1(rvalue_default<X>()); |
| 859 | X x2(std::move(x1)); |
| 860 | x1 = rvalue_default<X>(); |
| 861 | x2 = std::move(x1); |
| 862 | |
| 863 | X a; |
| 864 | allocator_type m = a.get_allocator(); |
| 865 | |
| 866 | test::minimal::constructor_param* i = 0; |
| 867 | test::minimal::constructor_param* j = 0; |
| 868 | |
| 869 | // Constructors |
| 870 | |
| 871 | X(i, j, 10, hf, eq); |
| 872 | X a5(i, j, 10, hf, eq); |
| 873 | X(i, j, 10, hf); |
| 874 | X a6(i, j, 10, hf); |
| 875 | X(i, j, 10); |
| 876 | X a7(i, j, 10); |
| 877 | X(i, j); |
| 878 | X a8(i, j); |
| 879 | |
| 880 | X(i, j, 10, hf, eq, m); |
| 881 | X a5a(i, j, 10, hf, eq, m); |
| 882 | X(i, j, 10, hf, m); |
| 883 | X a6a(i, j, 10, hf, m); |
| 884 | X(i, j, 10, m); |
| 885 | X a7a(i, j, 10, m); |
| 886 | |
| 887 | // Not specified for some reason (maybe ambiguity with another constructor?) |
| 888 | // X(i, j, m); |
| 889 | // X a8a(i, j, m); |
| 890 | // sink(a8a); |
| 891 | |
| 892 | const_iterator q = a.cbegin(); |
| 893 | |
| 894 | test::minimal::constructor_param v; |
| 895 | a.emplace(v); |
| 896 | test::check_return_type<iterator>::equals(a.emplace_hint(q, v)); |
| 897 | |
| 898 | T v1(v); |
| 899 | a.emplace(std::move(v1)); |
| 900 | T v2(v); |
| 901 | a.insert(std::move(v2)); |
| 902 | T v3(v); |
| 903 | test::check_return_type<iterator>::equals(a.emplace_hint(q, std::move(v3))); |
| 904 | T v4(v); |
| 905 | test::check_return_type<iterator>::equals(a.insert(q, std::move(v4))); |
| 906 | |
| 907 | a.insert(i, j); |
| 908 | |
| 909 | X a10; |
| 910 | T v5(v); |
| 911 | a10.insert(std::move(v5)); |
| 912 | q = a10.cbegin(); |
| 913 | #ifdef BOOST_UNORDERED_FOA_TESTS |
| 914 | test::check_return_type<iterator>::convertible(a10.erase(q)); |
| 915 | #else |
| 916 | test::check_return_type<iterator>::equals(a10.erase(q)); |
| 917 | #endif |
| 918 | |
| 919 | // Avoid unused variable warnings: |
| 920 | |
| 921 | sink(a); |
| 922 | sink(a5); |
| 923 | sink(a6); |
| 924 | sink(a7); |
| 925 | sink(a8); |
| 926 | sink(a5a); |
| 927 | sink(a6a); |
| 928 | sink(a7a); |
| 929 | sink(a10); |
| 930 | } |
| 931 | |
| 932 | template <class X, class T> void unordered_set_member_test(X& x, T& t) |
| 933 | { |
| 934 | X x1(x); |
| 935 | x1.insert(t); |
| 936 | x1.begin()->dummy_member(); |
| 937 | x1.cbegin()->dummy_member(); |
| 938 | } |
| 939 | |
| 940 | template <class X, class T> void unordered_map_member_test(X& x, T& t) |
| 941 | { |
| 942 | X x1(x); |
| 943 | x1.insert(t); |
| 944 | x1.begin()->first.dummy_member(); |
| 945 | x1.cbegin()->first.dummy_member(); |
| 946 | x1.begin()->second.dummy_member(); |
| 947 | x1.cbegin()->second.dummy_member(); |
| 948 | } |
| 949 | |