// Copyright 2021 Christian Mazakas. // 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) // clang-format off #include "../helpers/prefix.hpp" #include #include #include "../helpers/postfix.hpp" // clang-format on #include "../helpers/test.hpp" #include #include #include #include #include #include #include #include #include #include #include #include // This test is based on a user-submitted issue found here: // https://github.com/boostorg/unordered/issues/22 // #if BOOST_CXX_VERSION <= 199711L BOOST_PRAGMA_MESSAGE( "scoped allocator adaptor tests only work under C++11 and above") int main() {} #else namespace bi = boost::interprocess; template struct node_alloc { typedef bi::node_allocator type; }; typedef std::vector::type> vector_type; typedef std::pair pair_type; typedef boost::container::scoped_allocator_adaptor::type, node_alloc::type> allocator_type; typedef boost::unordered_map, std::equal_to, allocator_type> map_type; std::string make_uuid() { return boost::filesystem::unique_path().string(); } UNORDERED_AUTO_TEST (scoped_allocator) { std::string uuid = make_uuid(); bi::managed_shared_memory s(bi::create_only, uuid.c_str(), 65536); allocator_type alloc(node_alloc::type(s.get_segment_manager()), node_alloc::type(s.get_segment_manager())); map_type map(alloc); for (unsigned i = 0; i < 10; ++i) { boost::ignore_unused(map[i]); } BOOST_TEST(map.size() == 10); bi::shared_memory_object::remove(uuid.c_str()); } RUN_TESTS() #endif