From 7cba84ca97a7d7b4cf458ded05784f59ee9305e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 15 Sep 2018 01:16:28 +0200 Subject: [PATCH] Make non-const overload of internal_storage and make them BOOST_CONTAINER_FORCEINLINE --- include/boost/container/small_vector.hpp | 45 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/include/boost/container/small_vector.hpp b/include/boost/container/small_vector.hpp index 70704d6..6f5c050 100644 --- a/include/boost/container/small_vector.hpp +++ b/include/boost/container/small_vector.hpp @@ -276,10 +276,11 @@ class small_vector_allocator using Allocator::allocate_many; using Allocator::deallocate_many;*/ - BOOST_CONTAINER_FORCEINLINE bool is_internal_storage(pointer p) const + BOOST_CONTAINER_FORCEINLINE bool is_internal_storage(const_pointer p) const { return this->internal_storage() == p; } - pointer internal_storage() const + BOOST_CONTAINER_FORCEINLINE + const_pointer internal_storage() const { typedef typename Allocator::value_type value_type; typedef typename allocator_traits_type::size_type size_type; @@ -292,6 +293,21 @@ class small_vector_allocator const derived_type &d_base = static_cast(v_base); return d_base.internal_storage(); } + + BOOST_CONTAINER_FORCEINLINE + pointer internal_storage() + { + typedef typename Allocator::value_type value_type; + typedef typename allocator_traits_type::size_type size_type; + typedef vector_alloc_holder< small_vector_allocator, size_type > vector_alloc_holder_t; + typedef vector > vector_base; + typedef small_vector_base derived_type; + // + vector_alloc_holder_t &v_holder = static_cast(*this); + vector_base &v_base = reinterpret_cast(v_holder); + derived_type &d_base = static_cast(v_base); + return d_base.internal_storage(); + } #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED }; @@ -328,17 +344,34 @@ class small_vector_base public: //Make it public as it will be inherited by small_vector and container //must have this public member - typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::pointer pointer; + typedef typename allocator_traits::const_pointer const_pointer; + typedef typename allocator_traits::void_pointer void_pointer; + typedef typename allocator_traits::const_void_pointer const_void_pointer; private: BOOST_COPYABLE_AND_MOVABLE(small_vector_base) friend class small_vector_allocator; - pointer internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE + const_pointer internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW { - return boost::intrusive::pointer_traits::pointer_to - (*const_cast(static_cast(static_cast(m_storage_start.data)))); + typedef typename boost::intrusive::pointer_traits::template + rebind_pointer::type const_char_pointer; + const_void_pointer void_p = boost::intrusive::pointer_traits:: + pointer_to(*m_storage_start.data); + return boost::intrusive::pointer_traits::static_cast_from(void_p); + } + + BOOST_CONTAINER_FORCEINLINE + pointer internal_storage() BOOST_NOEXCEPT_OR_NOTHROW + { + typedef typename boost::intrusive::pointer_traits::template + rebind_pointer::type char_pointer; + void_pointer void_p = boost::intrusive::pointer_traits:: + pointer_to(*m_storage_start.data); + return boost::intrusive::pointer_traits::static_cast_from(void_p); } typedef vector > base_type;