// 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) #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 #include #include "../helpers/postfix.hpp" // clang-format on #include "../helpers/test.hpp" #include #include #include #include #include #include namespace test { template struct allocator { typedef T value_type; allocator() = delete; allocator(int) {} allocator(allocator const&) = default; allocator(allocator&&) = default; template allocator(allocator const&) {} BOOST_ATTRIBUTE_NODISCARD T* allocate(std::size_t n) { return static_cast(::operator new(n * sizeof(T))); } void deallocate(T* p, std::size_t) noexcept { ::operator delete(p); } bool operator==(allocator const&) const { return true; } bool operator!=(allocator const&) const { return false; } }; } // namespace test typedef std::vector > vector_type; typedef std::pair pair_type; typedef std::scoped_allocator_adaptor, test::allocator > allocator_type; typedef boost::unordered_map, std::equal_to, allocator_type> map_type; UNORDERED_AUTO_TEST (scoped_allocator) { allocator_type alloc( test::allocator(1337), test::allocator(7331)); map_type map(alloc); for (unsigned i = 0; i < 10; ++i) { boost::ignore_unused(map[i]); } BOOST_TEST(map.size() == 10); } RUN_TESTS() #endif