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

This is an old version of boost. Click here for the latest version's documentation home page.
PrevUpHomeNext

Class template scoped_allocator_adaptor

boost::container::scoped_allocator_adaptor

Synopsis

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

template<typename OuterAlloc, typename... InnerAllocs> 
class scoped_allocator_adaptor {
public:
  // types
  typedef OuterAlloc                                        outer_allocator_type;                  
  typedef allocator_traits< OuterAlloc >                    outer_traits_type;                     
  typedef base_type::inner_allocator_type                   inner_allocator_type;                  
  typedef outer_traits_type::value_type                     value_type;                            
  typedef outer_traits_type::size_type                      size_type;                             
  typedef outer_traits_type::difference_type                difference_type;                       
  typedef outer_traits_type::pointer                        pointer;                               
  typedef outer_traits_type::const_pointer                  const_pointer;                         
  typedef outer_traits_type::void_pointer                   void_pointer;                          
  typedef outer_traits_type::const_void_pointer             const_void_pointer;                    
  typedef base_type::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;
  typedef base_type::propagate_on_container_move_assignment propagate_on_container_move_assignment;
  typedef base_type::propagate_on_container_swap            propagate_on_container_swap;           

  // member classes/structs/unions
  template<typename U> 
  struct rebind {
    // types
    typedef scoped_allocator_adaptor< typename outer_traits_type::template portable_rebind_alloc< U >::type, InnerAllocs... > other;
  };

  // construct/copy/destruct
  scoped_allocator_adaptor();
  scoped_allocator_adaptor(const scoped_allocator_adaptor &);
  scoped_allocator_adaptor(scoped_allocator_adaptor &&);
  template<typename OuterA2> 
    scoped_allocator_adaptor(OuterA2 &&, const InnerAllocs &...);
  template<typename OuterA2> 
    scoped_allocator_adaptor(const scoped_allocator_adaptor< OuterA2, InnerAllocs... > &);
  template<typename OuterA2> 
    scoped_allocator_adaptor(scoped_allocator_adaptor< OuterA2, InnerAllocs... > &&);
  scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor &);
  scoped_allocator_adaptor& operator=(scoped_allocator_adaptor &&);
  ~scoped_allocator_adaptor();

  // public member functions
  outer_allocator_type & outer_allocator();
  const outer_allocator_type & outer_allocator() const;
  inner_allocator_type & inner_allocator();
  inner_allocator_type const & inner_allocator() const;
  size_type max_size() const;
  template<typename T> void destroy(T *);
  pointer allocate(size_type);
  pointer allocate(size_type, const_void_pointer);
  void deallocate(pointer, size_type);
  scoped_allocator_adaptor select_on_container_copy_construction() const;
  template<typename T, class... Args> void construct(T *, Args &&...);
  template<typename T1, typename T2> void construct(std::pair< T1, T2 > *);
  template<typename T1, typename T2> void construct(unspecified);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(std::pair< T1, T2 > *, U &&, V &&);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(unspecified, U &&, V &&);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(std::pair< T1, T2 > *, const std::pair< U, V > &);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(unspecified, unspecified);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(std::pair< T1, T2 > *, std::pair< U, V > &&);
  template<typename T1, typename T2, typename U, typename V> 
    void construct(unspecified, unspecified);
};

Description

This class is a C++03-compatible implementation of std::scoped_allocator_adaptor. The class template scoped_allocator_adaptor is an allocator template that specifies the memory resource (the outer allocator) to be used by a container (as any other allocator does) and also specifies an inner allocator resource to be passed to the constructor of every element within the container.

This adaptor is instantiated with one outer and zero or more inner allocator types. If instantiated with only one allocator type, the inner allocator becomes the scoped_allocator_adaptor itself, thus using the same allocator resource for the container and every element within the container and, if the elements themselves are containers, each of their elements recursively. If instantiated with more than one allocator, the first allocator is the outer allocator for use by the container, the second allocator is passed to the constructors of the container's elements, and, if the elements themselves are containers, the third allocator is passed to the elements' elements, and so on. If containers are nested to a depth greater than the number of allocators, the last allocator is used repeatedly, as in the single-allocator case, for any remaining recursions.

[Note: The scoped_allocator_adaptor is derived from the outer allocator type so it can be substituted for the outer allocator type in most expressions. -end note]

In the construct member functions, `OUTERMOST(x)` is x if x does not have an `outer_allocator()` member function and `OUTERMOST(x.outer_allocator())` otherwise; `OUTERMOST_ALLOC_TRAITS(x)` is `allocator_traits<decltype(OUTERMOST(x))>`.

[Note: `OUTERMOST(x)` and `OUTERMOST_ALLOC_TRAITS(x)` are recursive operations. It is incumbent upon the definition of `outer_allocator()` to ensure that the recursion terminates. It will terminate for all instantiations of scoped_allocator_adaptor. -end note]

scoped_allocator_adaptor public types

  1. typedef allocator_traits< OuterAlloc > outer_traits_type;

    Type: For exposition only

  2. typedef base_type::inner_allocator_type inner_allocator_type;

    Type: `scoped_allocator_adaptor<OuterAlloc>` if `sizeof...(InnerAllocs)` is zero; otherwise, `scoped_allocator_adaptor<InnerAllocs...>`.

  3. typedef base_type::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;

    Type: `true_type` if `allocator_traits::propagate_on_container_copy_assignment::value` is true for any `A` in the set of `OuterAlloc` and `InnerAllocs...`; otherwise, false_type.

  4. typedef base_type::propagate_on_container_move_assignment propagate_on_container_move_assignment;

    Type: `true_type` if `allocator_traits::propagate_on_container_move_assignment::value` is true for any `A` in the set of `OuterAlloc` and `InnerAllocs...`; otherwise, false_type.

  5. typedef base_type::propagate_on_container_swap propagate_on_container_swap;

    Type: `true_type` if `allocator_traits::propagate_on_container_swap::value` is true for any `A` in the set of `OuterAlloc` and `InnerAllocs...`; otherwise, false_type.

scoped_allocator_adaptor public construct/copy/destruct

  1. scoped_allocator_adaptor();

    Effects: value-initializes the OuterAlloc base class and the inner allocator object.

  2. scoped_allocator_adaptor(const scoped_allocator_adaptor & other);

    Effects: initializes each allocator within the adaptor with the corresponding allocator from other.

  3. scoped_allocator_adaptor(scoped_allocator_adaptor && other);

    Effects: move constructs each allocator within the adaptor with the corresponding allocator from other.

  4. template<typename OuterA2> 
      scoped_allocator_adaptor(OuterA2 && outerAlloc, 
                               const InnerAllocs &... innerAllocs);

    Requires: OuterAlloc shall be constructible from OuterA2.

    Effects: initializes the OuterAlloc base class with boost::forward<OuterA2>(outerAlloc) and inner with innerAllocs...(hence recursively initializing each allocator within the adaptor with the corresponding allocator from the argument list).

  5. template<typename OuterA2> 
      scoped_allocator_adaptor(const scoped_allocator_adaptor< OuterA2, InnerAllocs... > & other);

    Requires: OuterAlloc shall be constructible from OuterA2.

    Effects: initializes each allocator within the adaptor with the corresponding allocator from other.

  6. template<typename OuterA2> 
      scoped_allocator_adaptor(scoped_allocator_adaptor< OuterA2, InnerAllocs... > && other);

    Requires: OuterAlloc shall be constructible from OuterA2.

    Effects: initializes each allocator within the adaptor with the corresponding allocator rvalue from other.

  7. scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor & other);
  8. scoped_allocator_adaptor& operator=(scoped_allocator_adaptor && other);
  9. ~scoped_allocator_adaptor();

scoped_allocator_adaptor public member functions

  1. outer_allocator_type & outer_allocator();

    Returns: `static_cast<OuterAlloc&>(*this)`.

  2. const outer_allocator_type & outer_allocator() const;

    Returns: `static_cast<const OuterAlloc&>(*this)`.

  3. inner_allocator_type & inner_allocator();

    Returns: this if `sizeof...(InnerAllocs)` is zero; otherwise, inner.

  4. inner_allocator_type const & inner_allocator() const;

    Returns: this if `sizeof...(InnerAllocs)` is zero; otherwise, inner.

  5. size_type max_size() const;

    Returns: `allocator_traits<OuterAlloc>::max_size(outer_allocator())`.

  6. template<typename T> void destroy(T * p);

    Effects: calls `OUTERMOST_ALLOC_TRAITS(*this)::destroy(OUTERMOST(*this), p)`.

  7. pointer allocate(size_type n);

    Returns: `allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)`.

  8. pointer allocate(size_type n, const_void_pointer hint);

    Returns: `allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint)`.

  9. void deallocate(pointer p, size_type n);

    Effects: `allocator_traits<OuterAlloc>::deallocate(outer_allocator(), p, n)`.

  10. scoped_allocator_adaptor select_on_container_copy_construction() const;

    Returns: A new scoped_allocator_adaptor object where each allocator A in the adaptor is initialized from the result of calling `allocator_traits::select_on_container_copy_construction()` on the corresponding allocator in *this.

  11. template<typename T, class... Args> void construct(T * p, Args &&... args);

    Effects: 1) If `uses_allocator<T, inner_allocator_type>::value` is false calls `OUTERMOST_ALLOC_TRAITS(*this)::construct (OUTERMOST(*this), p, std::forward<Args>(args)...)`.

    2) Otherwise, if `uses_allocator<T, inner_allocator_type>::value` is true and `is_constructible<T, allocator_arg_t, inner_allocator_type, Args...>::value` is true, calls `OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST(*this), p, allocator_arg, inner_allocator(), std::forward<Args>(args)...)`.

    [Note: In compilers without advanced decltype SFINAE support, `is_constructible` can't be implemented so that condition will be replaced by constructible_with_allocator_prefix<T>::value. -end note]

    3) Otherwise, if uses_allocator<T, inner_allocator_type>::value is true and `is_constructible<T, Args..., inner_allocator_type>::value` is true, calls `OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST(*this), p, std::forward<Args>(args)..., inner_allocator())`.

    [Note: In compilers without advanced decltype SFINAE support, `is_constructible` can't be implemented so that condition will be replaced by `constructible_with_allocator_suffix<T>::value`. -end note]

    4) Otherwise, the program is ill-formed.

    [Note: An error will result if `uses_allocator` evaluates to true but the specific constructor does not take an allocator. This definition prevents a silent failure to pass an inner allocator to a contained element. -end note]

  12. template<typename T1, typename T2> void construct(std::pair< T1, T2 > * p);
  13. template<typename T1, typename T2> void construct(unspecified p);
  14. template<typename T1, typename T2, typename U, typename V> 
      void construct(std::pair< T1, T2 > * p, U && x, V && y);
  15. template<typename T1, typename T2, typename U, typename V> 
      void construct(unspecified p, U && x, V && y);
  16. template<typename T1, typename T2, typename U, typename V> 
      void construct(std::pair< T1, T2 > * p, const std::pair< U, V > & x);
  17. template<typename T1, typename T2, typename U, typename V> 
      void construct(unspecified p, unspecified x);
  18. template<typename T1, typename T2, typename U, typename V> 
      void construct(std::pair< T1, T2 > * p, std::pair< U, V > && x);
  19. template<typename T1, typename T2, typename U, typename V> 
      void construct(unspecified p, unspecified x);

PrevUpHomeNext