From 247ffd0336bb7f6ca9c6ee8a4adad8174b3b67c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 27 Oct 2025 23:55:05 +0100 Subject: [PATCH] Fixes #304 ("Usage of boost::container::small_vector with custom allocator") --- doc/container.qbk | 3 ++- include/boost/container/small_vector.hpp | 7 +++++-- test/vector_test.hpp | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index a530492..3b94449 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1434,7 +1434,7 @@ use [*Boost.Container]? There are several reasons for that: [section:release_notes Release Notes] -[section:release_notes_boost_1_90_00 Boost Release] +[section:release_notes_boost_1_90_00 Boost 1.90 Release] * Reimplemented [classref boost::container::deque]. The original implementation was based on the SGI's original data structure (similar to libstdc++). Main changes: @@ -1450,6 +1450,7 @@ use [*Boost.Container]? There are several reasons for that: * [@https://github.com/boostorg/container/pull/317/ GitHub #293: ['"UBSAN reports unaligned access error"]]. * [@https://github.com/boostorg/container/pull/294 GitHub #294: ['"CMake: Add option to use header-only Boost::container"]]. * [@https://github.com/boostorg/container/issues/300 GitHub #300: ['"Warnings when building with clang-20"]]. + * [@https://github.com/boostorg/container/issues/300 GitHub #304: ['"Usage of boost::container::small_vector with custom allocator"]]. * [@https://github.com/boostorg/container/pull/305 GitHub #305: ['"Warnings with -Wstrict-prototypes"]]. * [@https://github.com/boostorg/container/pull/307 GitHub #307: ['"Fix all instances of MSVC warning C4146 (unsigned negation)"]]. * [@https://github.com/boostorg/container/issues/309 GitHub #309: ['"Performance regression of boost::container::static_vector introduced in boost v1.86"]]. diff --git a/include/boost/container/small_vector.hpp b/include/boost/container/small_vector.hpp index afed910..c01718a 100644 --- a/include/boost/container/small_vector.hpp +++ b/include/boost/container/small_vector.hpp @@ -127,10 +127,11 @@ class small_vector_allocator { typedef unsigned int allocation_type; #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED - private: + public: typedef typename allocator_traits::template portable_rebind_alloc::type allocator_type; + private: BOOST_COPYABLE_AND_MOVABLE(small_vector_allocator) inline const allocator_type &as_base() const BOOST_NOEXCEPT @@ -353,7 +354,8 @@ class small_vector_base typedef typename real_allocator::type underlying_allocator_t; typedef typename allocator_traits:: template portable_rebind_alloc::type void_underlying_allocator_t; - typedef small_vector_allocatorallocator_type; + typedef typename small_vector_allocator + ::allocator_type allocator_type; typedef typename dtl::get_small_vector_opt::type options_t; typedef typename dtl::vector_for_small_vector ::type base_type; @@ -548,6 +550,7 @@ class small_vector BOOST_COPYABLE_AND_MOVABLE(small_vector) public: + typedef dtl::true_type is_partially_propagable; typedef small_vector_base base_type; typedef typename base_type::allocator_type allocator_type; typedef typename base_type::size_type size_type; diff --git a/test/vector_test.hpp b/test/vector_test.hpp index b120d5a..fb2550f 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -626,8 +626,11 @@ int vector_test() if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; } - if (0 != vector_test_fully_propagable - ( dtl::bool_< !allocator_traits::is_partially_propagable::value >() )) return 1; + typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, MyBoostVector, + is_partially_propagable, dtl::false_type) + is_partially_propagable_t; + + if (0 != vector_test_fully_propagable( dtl::bool_< !is_partially_propagable_t::value >() )) return 1; if (0 != vector_move_assignable_only< MyBoostVector>(dtl::bool_::value>())) return 1;