| Home | Libraries | People | FAQ | More

## Class template small_vector_allocator

boost::container::small_vector_allocator

## Synopsis

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

    template<typename Allocator>
    class small_vector_allocator : public Allocator {
    public:
      // types
      typedef allocator_traits< Allocator >::value_type                             value_type;
      typedef allocator_traits< Allocator >::pointer                                pointer;
      typedef allocator_traits< Allocator >::const_pointer                          const_pointer;
      typedef allocator_traits< Allocator >::reference                              reference;
      typedef allocator_traits< Allocator >::const_reference                        const_reference;
      typedef allocator_traits< Allocator >::size_type                              size_type;
      typedef allocator_traits< Allocator >::difference_type                        difference_type;
      typedef allocator_traits< Allocator >::void_pointer                           void_pointer;
      typedef allocator_traits< Allocator >::const_void_pointer                     const_void_pointer;
      typedef allocator_traits< Allocator >::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;
      typedef allocator_traits< Allocator >::propagate_on_container_move_assignment propagate_on_container_move_assignment;
      typedef allocator_traits< Allocator >::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 >::template rebind_alloc< T2 >::type other;
      };

      // construct/copy/destruct
      template<class... Args> explicit small_vector_allocator(Args &&...);
      small_vector_allocator(const small_vector_allocator &) noexcept;
      small_vector_allocator(small_vector_allocator &&) noexcept;
      template<typename OtherAllocator>
        small_vector_allocator(const small_vector_allocator< OtherAllocator > &) noexcept;
      template<typename OtherAllocator>
        small_vector_allocator(small_vector_allocator< OtherAllocator > &&) noexcept;
      small_vector_allocator & operator=(const small_vector_allocator &) noexcept;
      small_vector_allocator & operator=(small_vector_allocator &&) noexcept;
      template<typename OtherAllocator>
        small_vector_allocator &
        operator=(const small_vector_allocator< OtherAllocator > &) noexcept;
      template<typename OtherAllocator>
        small_vector_allocator &
        operator=(small_vector_allocator< OtherAllocator > &&) 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<Allocator> >` and internal storage can be obtained downcasting that vector to `small_vector_base<T>`.

### `small_vector_allocator` public construct/copy/destruct

1.     template<class... Args> explicit small_vector_allocator(Args &&... args);

   Constructor from arbitrary arguments.

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 OtherAllocator>
         small_vector_allocator(const small_vector_allocator< OtherAllocator > & other) noexcept;

   Constructor from related `small_vector_allocator`. Never throws

5.     template<typename OtherAllocator>
         small_vector_allocator(small_vector_allocator< OtherAllocator > && other) noexcept;

   Move constructor from related `small_vector_allocator`. Never throws

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

   Assignment from other `small_vector_allocator`. Never throws

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

   Move constructor from other `small_vector_allocator`. Never throws

8.     template<typename OtherAllocator>
         small_vector_allocator &
         operator=(const small_vector_allocator< OtherAllocator > & other) noexcept;

   Assignment from related `small_vector_allocator`. Never throws

9.     template<typename OtherAllocator>
         small_vector_allocator &
         operator=(small_vector_allocator< OtherAllocator > && other) noexcept;

   Move assignment from related `small_vector_allocator`. 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