Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class template small_vector_allocator

boost::container::small_vector_allocator

Synopsis

// In header: <boost/container/small_vector.hpp>

template<typename T, typename VoidAlloc = void, typename Options = void> 
class small_vector_allocator :
  public allocator_traits::template portable_rebind_alloc< T >::type
{
public:
  // types
  typedef allocator_traits< allocator_type >::value_type                             value_type;                            
  typedef allocator_traits< allocator_type >::pointer                                pointer;                               
  typedef allocator_traits< allocator_type >::const_pointer                          const_pointer;                         
  typedef allocator_traits< allocator_type >::reference                              reference;                             
  typedef allocator_traits< allocator_type >::const_reference                        const_reference;                       
  typedef allocator_traits< allocator_type >::size_type                              size_type;                             
  typedef allocator_traits< allocator_type >::difference_type                        difference_type;                       
  typedef allocator_traits< allocator_type >::void_pointer                           void_pointer;                          
  typedef allocator_traits< allocator_type >::const_void_pointer                     const_void_pointer;                    
  typedef allocator_traits< allocator_type >::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;
  typedef allocator_traits< allocator_type >::propagate_on_container_move_assignment propagate_on_container_move_assignment;
  typedef allocator_traits< allocator_type >::propagate_on_container_swap            propagate_on_container_swap;           
  typedef implementation_defined                                                     is_always_equal;                         // An integral constant with member value == false
  typedef implementation_defined                                                     is_partially_propagable;                 // An integral constant with member value == true

  // member classes/structs/unions
  template<typename T2> 
  struct rebind {
    // types
    typedef allocator_traits< allocator_type >::template portable_rebind_alloc< T2 >::type other;
  };

  // construct/copy/destruct
  small_vector_allocator() noexcept(dtl::is_nothrow_default_constructible< allocator_type >::value);
  small_vector_allocator(const small_vector_allocator &) noexcept;
  small_vector_allocator(small_vector_allocator &&) noexcept;
  template<typename U, typename OtherVoidAllocator, typename OtherOptions> 
    small_vector_allocator(const small_vector_allocator< U, OtherVoidAllocator, OtherOptions > &) noexcept;
  template<typename U, typename OtherVoidAllocator, typename OtherOptions> 
    small_vector_allocator(small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I OtherOptions > &&) noexcept;
  explicit small_vector_allocator(const allocator_type &) noexcept;
  small_vector_allocator & operator=(const small_vector_allocator &) noexcept;
  small_vector_allocator & operator=(small_vector_allocator &&) noexcept;
  template<typename U, typename OtherVoidAllocator> 
    small_vector_allocator & 
    operator=(const small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I Options > &) noexcept;
  template<typename U, typename OtherVoidAllocator> 
    small_vector_allocator & 
    operator=(small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I Options > &&) noexcept;
  small_vector_allocator & operator=(const allocator_type &) noexcept;

  // public member functions
  pointer allocate(size_type, const_void_pointer = const_void_pointer());
  void deallocate(pointer, size_type) noexcept;
  size_type max_size() const noexcept;
  small_vector_allocator select_on_container_copy_construction() const;
  bool storage_is_unpropagable(pointer) const;

  // friend functions
  friend void swap(small_vector_allocator &, small_vector_allocator &) noexcept;
  friend bool operator==(const small_vector_allocator &, 
                         const small_vector_allocator &) noexcept;
  friend bool operator!=(const small_vector_allocator &, 
                         const small_vector_allocator &) noexcept;
};

Description

A non-standard allocator used to implement small_vector. Users should never use it directly. It is described here for documentation purposes.

This allocator inherits from a standard-conforming allocator and forwards member functions to the standard allocator except when internal storage is being used as memory source.

This allocator is a "partially_propagable" allocator and defines is_partially_propagable as true_type.

A partially propagable allocator means that not all storage allocatod by an instance of small_vector_allocator can be deallocated by another instance of this type, even if both instances compare equal or an instance is propagated to another one using the copy/move constructor or assignment. The storage that can never be propagated is identified by storage_is_unpropagable(p).

boost::container::vector supports partially propagable allocators fallbacking to deep copy/swap/move operations when internal storage is being used to store vector elements.

small_vector_allocator assumes that will be instantiated as boost::container::vector< T, small_vector_allocator<T, Allocator> > and internal storage can be obtained downcasting that vector to small_vector_base<T>.

small_vector_allocator public construct/copy/destruct

  1. small_vector_allocator() noexcept(dtl::is_nothrow_default_constructible< allocator_type >::value);
  2. small_vector_allocator(const small_vector_allocator & other) noexcept;

    Constructor from other small_vector_allocator. Never throws

  3. small_vector_allocator(small_vector_allocator && other) noexcept;

    Move constructor from small_vector_allocator. Never throws

  4. template<typename U, typename OtherVoidAllocator, typename OtherOptions> 
      small_vector_allocator(const small_vector_allocator< U, OtherVoidAllocator, OtherOptions > & other) noexcept;

    Constructor from related small_vector_allocator. Never throws

  5. template<typename U, typename OtherVoidAllocator, typename OtherOptions> 
      small_vector_allocator(small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I OtherOptions > && other) noexcept;

    Move constructor from related small_vector_allocator. Never throws

  6. explicit small_vector_allocator(const allocator_type & other) noexcept;

    Constructor from allocator_type. Never throws

  7. small_vector_allocator & 
    operator=(const small_vector_allocator & other) noexcept;

    Assignment from other small_vector_allocator. Never throws

  8. small_vector_allocator & operator=(small_vector_allocator && other) noexcept;

    Move assignment from other small_vector_allocator. Never throws

  9. template<typename U, typename OtherVoidAllocator> 
      small_vector_allocator & 
      operator=(const small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I Options > & other) noexcept;

    Assignment from related small_vector_allocator. Never throws

  10. template<typename U, typename OtherVoidAllocator> 
      small_vector_allocator & 
      operator=(small_vector_allocator< U BOOST_MOVE_I OtherVoidAllocator BOOST_MOVE_I Options > && other) noexcept;

    Move assignment from related small_vector_allocator. Never throws

  11. small_vector_allocator & operator=(const allocator_type & other) noexcept;

    Move assignment from allocator_type. Never throws

small_vector_allocator public member functions

  1. pointer allocate(size_type count, 
                     const_void_pointer hint = const_void_pointer());
    Allocates storage from the standard-conforming allocator.
  2. void deallocate(pointer ptr, size_type n) noexcept;

    Deallocates previously allocated memory. Never throws

  3. size_type max_size() const noexcept;

    Returns the maximum number of elements that could be allocated. Never throws

  4. small_vector_allocator select_on_container_copy_construction() const;
  5. bool storage_is_unpropagable(pointer p) const;

small_vector_allocator friend functions

  1. friend void swap(small_vector_allocator & l, small_vector_allocator & r) noexcept;

    Swaps two allocators, does nothing because this small_vector_allocator is stateless

  2. friend bool operator==(const small_vector_allocator & l, 
                           const small_vector_allocator & r) noexcept;

    An small_vector_allocator always compares to true, as memory allocated with one instance can be deallocated by another instance (except for unpropagable storage)

  3. friend bool operator!=(const small_vector_allocator & l, 
                           const small_vector_allocator & r) noexcept;

    An small_vector_allocator always compares to false, as memory allocated with one instance can be deallocated by another instance


PrevUpHomeNext