Add compile-time check to make sure allocator_type::value_type and container's value_type are the same type.

This commit is contained in:
Ion Gaztañaga
2024-09-10 23:50:24 +02:00
parent 5bdca12ac7
commit 49440c3525
9 changed files with 43 additions and 2 deletions

View File

@ -1026,6 +1026,11 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private: // Internal typedefs
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits<ValAllocator>::value_type>::value));
BOOST_COPYABLE_AND_MOVABLE(deque)
typedef typename Base::ptr_alloc_ptr index_pointer;
typedef allocator_traits<ValAllocator> allocator_traits_type;

View File

@ -592,6 +592,10 @@ class flat_tree
typedef typename container_type::reverse_iterator reverse_iterator;
typedef typename container_type::const_reverse_iterator const_reverse_iterator;
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((is_same<value_type, typename allocator_traits_type::value_type>::value));
//!Standard extension
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
(boost::container::dtl::, container_type
@ -733,7 +737,8 @@ class flat_tree
}
inline ~flat_tree()
{}
{
}
inline flat_tree& operator=(BOOST_COPY_ASSIGN_REF(flat_tree) x)
{ m_data = x.m_data; return *this; }

View File

@ -456,6 +456,10 @@ class tree
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits<allocator_type>::value_type>::value));
typedef key_node_pred<key_compare, key_of_value_t, Node> KeyNodeCompare;
public:

View File

@ -173,6 +173,11 @@ class devector
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits<allocator_type>::value_type>::value));
BOOST_COPYABLE_AND_MOVABLE(devector)
// Guard to deallocate buffer on exception

View File

@ -1378,6 +1378,10 @@ class list
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits_type::value_type>::value));
void priv_move_assign(BOOST_RV_REF(list) x, dtl::bool_<true> /*steal_resources*/)
{
//Destroy objects but retain memory in case x reuses it in the future

View File

@ -1565,6 +1565,11 @@ class slist
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits_type::value_type>::value));
void priv_move_assign(BOOST_RV_REF(slist) x, dtl::bool_<true> /*steal_resources*/)
{
//Destroy objects but retain memory in case x reuses it in the future

View File

@ -597,6 +597,11 @@ class stable_vector
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits<allocator_type>::value_type>::value));
BOOST_COPYABLE_AND_MOVABLE(stable_vector)
BOOST_STATIC_CONSTEXPR size_type ExtraPointers = index_traits_type::ExtraPointers;

View File

@ -628,6 +628,11 @@ class basic_string
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits<allocator_type>::value_type>::value));
typedef constant_iterator<CharT> cvalue_iterator;
typedef typename base_t::alloc_version alloc_version;
typedef ::boost::intrusive::pointer_traits<pointer> pointer_traits;

View File

@ -813,8 +813,11 @@ public:
typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
private:
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//`allocator_type::value_type` must match container's `value type`. If this
//assertion fails, please review your allocator definition.
BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<value_type, typename allocator_traits_t::value_type>::value));
typedef typename boost::container::
allocator_traits<allocator_type>::size_type alloc_size_type;
typedef typename get_vector_opt<Options, alloc_size_type>::type options_type;