Add hub tests and example

This commit is contained in:
Ion Gaztañaga
2026-06-05 23:50:25 +02:00
parent 242c567d20
commit 94608e4cd9
10 changed files with 2446 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
/* Basic example of use of boost::container::hub.
*
* Copyright 2026 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/container/hub.hpp>
#ifdef NDEBUG
# undef NDEBUG
#endif
#include <cassert>
int main()
{
boost::container::hub<int> h;
// Insert some elements and keep an iterator to one of them
for(int i = 0; i < 100; ++i) h.insert(i);
auto it = h.insert(100);
for(int i = 101; i < 200; ++i) h.insert(i);
// Erase some of the elements
erase_if(h, [](int x) { return x % 2 != 0;});
assert(*it == 100); // iterator still valid
// Insert many more elements
for(int i = 200; i < 10000; ++i) h.insert(i);
assert(*it == 100); // iterator still valid
}