Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template scoped_allocator_adaptor

boost::container::scoped_allocator_adaptor

Synopsis

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

template<typename OuterAlloc,  InnerAllocs> 
class scoped_allocator_adaptor : public  {
public:
  // types
  typedef OuterAlloc                                        ;                  
  typedef allocator_traits< OuterAlloc >                    ;                     
  typedef                    ;                  
  typedef allocator_traits<           ;                     
  typedef outer_traits_type::value_type                     ;                            
  typedef                       ;                             
  typedef                 ;                       
  typedef outer_traits_type::pointer                        ;                               
  typedef outer_traits_type::const_pointer                  ;                         
  typedef                    ;                          
  typedef              ;                    
  typedef  ;
  typedef  ;
  typedef             ;           
  typedef                         ;                       

  // member classes/structs/unions
  template<typename U> 
  struct rebind {
    // types
    typedef scoped_allocator_adaptor< typename U >:: ;
  };

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

  // public member functions
  void (scoped_allocator_adaptor &);
  outer_allocator_type & () ;
  const outer_allocator_type & () ;
   () ;
  const & () ;
   () ;
  template<typename T> void (T *) ;
  pointer ();
  pointer (, );
  void (pointer, );
  scoped_allocator_adaptor () ;
  template<typename T,  Args> void (T *, Args &&...);

  // friend functions
  void (scoped_allocator_adaptor &, scoped_allocator_adaptor &);
};

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 > ;

    Type: For exposition only

  2. typedef ;

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

  3. typedef ;

    Type: A type with a constant boolean value == true if allocator_traits<Allocator>:: propagate_on_container_copy_assignment::value is true for any Allocator in the set of OuterAlloc and InnerAllocs..., false otherwise.

  4. typedef ;

    Type: A type with a constant boolean value == true if allocator_traits<Allocator>:: propagate_on_container_move_assignment::value is true for any Allocator in the set of OuterAlloc and InnerAllocs..., false otherwise.

  5. typedef ;

    Type: A type with a constant boolean value == true if allocator_traits<Allocator>:: propagate_on_container_swap::value is true for any Allocator in the set of OuterAlloc and InnerAllocs..., false otherwise.

  6. typedef ;

    Type: A type with a constant boolean value == true if allocator_traits<Allocator>:: is_always_equal::value is true for all Allocator in the set of OuterAlloc and InnerAllocs..., false otherwise.

scoped_allocator_adaptor public construct/copy/destruct

  1. ();

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

  2. (const scoped_allocator_adaptor & other);

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

  3. (scoped_allocator_adaptor && other);

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

  4. template<typename OuterA2> 
      (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> 
      (const scoped_allocator_adaptor< OuterA2,  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< OuterA2,  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 & (const scoped_allocator_adaptor & other);
  8. scoped_allocator_adaptor & (scoped_allocator_adaptor && other);
  9. ~();

scoped_allocator_adaptor public member functions

  1. void (scoped_allocator_adaptor & r);

    Effects: swaps *this with r.

  2. outer_allocator_type & () ;

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

  3. const outer_allocator_type & () ;

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

  4.  () ;

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

  5. const & () ;

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

  6.  () ;

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

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

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

  8. pointer ( n);

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

  9. pointer ( n,  hint);

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

  10. void (pointer p,  n);

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

  11. scoped_allocator_adaptor () ;

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

  12. template<typename T,  Args> void (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]

scoped_allocator_adaptor friend functions

  1. void (scoped_allocator_adaptor & l, scoped_allocator_adaptor & r);

    Effects: swaps *this with r.


PrevUpHomeNext