Make non-const overload of internal_storage and make them BOOST_CONTAINER_FORCEINLINE

This commit is contained in:
Ion Gaztañaga
2018-09-15 01:16:28 +02:00
parent 6504af8708
commit 7cba84ca97

View File

@@ -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<const derived_type &>(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<Allocator>, size_type > vector_alloc_holder_t;
typedef vector<value_type, small_vector_allocator<Allocator> > vector_base;
typedef small_vector_base<value_type, Allocator> derived_type;
//
vector_alloc_holder_t &v_holder = static_cast<vector_alloc_holder_t &>(*this);
vector_base &v_base = reinterpret_cast<vector_base &>(v_holder);
derived_type &d_base = static_cast<derived_type &>(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<SecondaryAllocator>::pointer pointer;
typedef typename allocator_traits<SecondaryAllocator>::pointer pointer;
typedef typename allocator_traits<SecondaryAllocator>::const_pointer const_pointer;
typedef typename allocator_traits<SecondaryAllocator>::void_pointer void_pointer;
typedef typename allocator_traits<SecondaryAllocator>::const_void_pointer const_void_pointer;
private:
BOOST_COPYABLE_AND_MOVABLE(small_vector_base)
friend class small_vector_allocator<SecondaryAllocator>;
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>::pointer_to
(*const_cast<T*>(static_cast<const T*>(static_cast<const void*>(m_storage_start.data))));
typedef typename boost::intrusive::pointer_traits<const_pointer>::template
rebind_pointer<const unsigned char>::type const_char_pointer;
const_void_pointer void_p = boost::intrusive::pointer_traits<const_char_pointer>::
pointer_to(*m_storage_start.data);
return boost::intrusive::pointer_traits<const_pointer>::static_cast_from(void_p);
}
BOOST_CONTAINER_FORCEINLINE
pointer internal_storage() BOOST_NOEXCEPT_OR_NOTHROW
{
typedef typename boost::intrusive::pointer_traits<pointer>::template
rebind_pointer<unsigned char>::type char_pointer;
void_pointer void_p = boost::intrusive::pointer_traits<char_pointer>::
pointer_to(*m_storage_start.data);
return boost::intrusive::pointer_traits<pointer>::static_cast_from(void_p);
}
typedef vector<T, small_vector_allocator<SecondaryAllocator> > base_type;