| Home | Libraries | People | FAQ | More

## Struct template allocator_traits

allocator_traits

## Synopsis

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

    template<typename Alloc>
    struct allocator_traits {
      // types
      typedef Alloc             allocator_type;
      typedef Alloc::value_type value_type;
      typedef unspecified       pointer;
      typedef unspecified       const_pointer;
      typedef unspecified       reference;
      typedef unspecified       const_reference;
      typedef unspecified       void_pointer;
      typedef unspecified       const_void_pointer;
      typedef unspecified       difference_type;
      typedef unspecified       size_type;
      typedef unspecified       propagate_on_container_copy_assignment;
      typedef unspecified       propagate_on_container_move_assignment;
      typedef unspecified       propagate_on_container_swap;

      // member classes/structs/unions
      template<typename T>
      struct portable_rebind_alloc {
        // types
        typedef unspecified_type type;
      };

      // public static functions
      static pointer allocate(Alloc &, size_type);
      static void deallocate(Alloc &, pointer, size_type);
      static pointer allocate(Alloc &, size_type, const_void_pointer);
      template<typename T> static void destroy(Alloc &, T *);
      static size_type max_size(const Alloc &);
      static Alloc select_on_container_copy_construction(const Alloc &);
      template<typename T, class... Args>
        static void construct(Alloc &, T *, Args &&...);
    };

## Description

The class template allocator_traits supplies a uniform interface to all allocator types. This class is a C++03-compatible implementation of std::allocator_traits

### `allocator_traits` public types

1. typedef unspecified pointer;

   Alloc::pointer if such a type exists; otherwise, value_type*

2. typedef unspecified const_pointer;

   Alloc::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const

3. typedef unspecified reference;

   Non-standard extension Alloc::reference if such a type exists; otherwise, value_type&

4. typedef unspecified const_reference;

   Non-standard extension Alloc::const_reference if such a type exists ; otherwise, const value_type&

5. typedef unspecified void_pointer;

   Alloc::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>.

6. typedef unspecified const_void_pointer;

   Alloc::const_void_pointer if such a type exists ; otherwis e, pointer_traits<pointer>::rebind<const

7. typedef unspecified difference_type;

   Alloc::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type.

8. typedef unspecified size_type;

   Alloc::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type

9. typedef unspecified propagate_on_container_copy_assignment;

   Alloc::propagate_on_container_copy_assignment if such a type exists, otherwise an integral_constant type with internal constant static member `value` == false.

10. typedef unspecified propagate_on_container_move_assignment;

    Alloc::propagate_on_container_move_assignment if such a type exists, otherwise an integral_constant type with internal constant static member `value` == false.

11. typedef unspecified propagate_on_container_swap;

    Alloc::propagate_on_container_swap if such a type exists, otherwise an integral_constant type with internal constant static member `value` == false.

### `allocator_traits` public static functions

1.     static pointer allocate(Alloc & a, size_type n);

   Returns: `a.allocate(n)`

2.     static void deallocate(Alloc & a, pointer p, size_type n);

   Returns: `a.deallocate(p, n)`

   Throws: Nothing

3.     static pointer allocate(Alloc & a, size_type n, const_void_pointer p);

   Effects: calls `a.allocate(n, p)` if that call is well-formed; otherwise, invokes `a.allocate(n)`

4.     template<typename T> static void destroy(Alloc & a, T * p);

   Effects: calls `a.destroy(p)` if that call is well-formed; otherwise, invokes `p->~T()`.

5.     static size_type max_size(const Alloc & a);

   Returns: `a.max_size()` if that expression is well-formed; otherwise, `numeric_limits<size_type>::max()`.

6.     static Alloc select_on_container_copy_construction(const Alloc & a);

   Returns: `a.select_on_container_copy_construction()` if that expression is well-formed; otherwise, a.

7.     template<typename T, class... Args>
         static void construct(Alloc & a, T * p, Args &&... args);

   Effects: calls `a.construct(p, std::forward<Args>(args)...)` if that call is well-formed; otherwise, invokes `::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`