Skip to content

Commit

Permalink
Add compile-time check to make sure allocator_type::value_type and co…
Browse files Browse the repository at this point in the history
…ntainer's value_type are the same type.
  • Loading branch information
igaztanaga committed Sep 10, 2024
1 parent 5bdca12 commit 49440c3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/boost/container/deque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion include/boost/container/detail/flat_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand Down
4 changes: 4 additions & 0 deletions include/boost/container/detail/tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions include/boost/container/devector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/boost/container/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions include/boost/container/slist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions include/boost/container/stable_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions include/boost/container/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion include/boost/container/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,11 @@ class vector
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;
Expand Down

0 comments on commit 49440c3

Please sign in to comment.