diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 733e5ee3..cd671aca 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -61,7 +61,7 @@ test-suite unordered [ run unordered/swap_tests.cpp ] [ run unordered/detail_tests.cpp ] [ run unordered/deduction_tests.cpp ] - [ run unordered/scoped_allocator.cpp /boost/filesystem//boost_filesystem/off ] + [ run unordered/scoped_allocator.cpp ] [ run unordered/transparent_tests.cpp ] [ run unordered/reserve_tests.cpp ] [ run unordered/contains_tests.cpp ] diff --git a/test/unordered/scoped_allocator.cpp b/test/unordered/scoped_allocator.cpp index cd61b9f3..08a9397f 100644 --- a/test/unordered/scoped_allocator.cpp +++ b/test/unordered/scoped_allocator.cpp @@ -3,6 +3,21 @@ // 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 +#include + +#if BOOST_CXX_VERSION <= 199711L + +BOOST_PRAGMA_MESSAGE( + "scoped allocator adaptor tests only work under C++11 and above") +int main() {} + +#else + +// This test is based on a user-submitted issue found here: +// https://github.com/boostorg/unordered/issues/22 +// + // clang-format off #include "../helpers/prefix.hpp" #include @@ -12,67 +27,55 @@ #include "../helpers/test.hpp" -#include -#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 -// +namespace test { + template struct allocator + { + typedef T value_type; -#if BOOST_CXX_VERSION <= 199711L + allocator() = delete; + allocator(int) {} + allocator(allocator const&) = default; + allocator(allocator&&) = default; -BOOST_PRAGMA_MESSAGE( - "scoped allocator adaptor tests only work under C++11 and above") -int main() {} + template allocator(allocator const&) {} -#else + BOOST_ATTRIBUTE_NODISCARD T* allocate(std::size_t n) + { + return static_cast(::operator new(n * sizeof(T))); + } -namespace bi = boost::interprocess; + void deallocate(T* p, std::size_t) noexcept { ::operator delete(p); } -template struct node_alloc -{ - typedef bi::node_allocator - type; -}; + bool operator==(allocator const&) const { return true; } + bool operator!=(allocator const&) const { return false; } + }; +} // namespace test -typedef std::vector::type> +typedef std::vector > vector_type; typedef std::pair pair_type; -typedef boost::container::scoped_allocator_adaptor::type, - node_alloc::type> +typedef std::scoped_allocator_adaptor, + test::allocator > 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())); + allocator_type alloc( + test::allocator(1337), test::allocator(7331)); map_type map(alloc); @@ -81,8 +84,6 @@ UNORDERED_AUTO_TEST (scoped_allocator) { } BOOST_TEST(map.size() == 10); - - bi::shared_memory_object::remove(uuid.c_str()); } RUN_TESTS()