Lumiera  0.pre.03
»edit your freedom«
Allocator_TransferNoncopyable< TY, PAR > Class Template Reference

#include "lib/scoped-holder-transfer.hpp"

Description

template<class TY, class PAR = std::allocator<TY>>
class lib::Allocator_TransferNoncopyable< TY, PAR >

Addendum to scoped-holder.hpp for transferring the lifecycle management to another instance.

Using these wrappers within STL vector and similar containers may result in the need to do a re-allocation in response to a request to grow. Obviously such a feature needs support by the objects being wrapped, which should provide an operation for transferring lifecycle management in a controlled fashion. This behaviour is similar to std::auto_ptr, but because we use a separate dedicated operation, we avoid some of the dangers pertaining the use of the latter: just taking the "value" can't kill the managed object.

To implement this feature we need
  • a custom allocator to be used by the vector. By default it is built as a thin proxy round std::allocator.
  • the noncopyable type to be managed within the vector needs to provide a custom extension point: when the allocator detects the need to transfer control between two instances, it will invoke a free function named transfer_control(TY& from, TY& to) intended to be found by ADL. Note: in case this function throws, it must not have any side effects.
  • besides, the noncopyable type needs to provide an operator bool() yielding true iff currently containing an managed object. This is similar to std::unique_ptr or even the behaviour of a plain old raw pointer, which is equivalent to true when the pointer isn'T NULL
Deprecated:
obsoleted by C++11 rvalue references

Definition at line 77 of file scoped-holder-transfer.hpp.

Public Types

typedef PAR::const_pointer const_pointer
 
typedef PAR::const_reference const_reference
 
typedef PAR::difference_type difference_type
 
typedef PAR::pointer pointer
 
typedef PAR::reference reference
 
typedef PAR::size_type size_type
 
typedef PAR::value_type value_type
 

Public Member Functions

 Allocator_TransferNoncopyable (const _ThisType &allo)
 
 Allocator_TransferNoncopyable (const PAR &allo)
 
template<typename X >
 Allocator_TransferNoncopyable (const std::allocator< X > &)
 
pointer address (reference r) const
 
const_pointer address (const_reference cr) const
 
pointer allocate (size_type n, const void *p=0)
 
void construct (pointer p, const TY &ref)
 
void deallocate (pointer p, size_type n)
 
void destroy (pointer p)
 
size_type max_size () const
 

Classes

struct  rebind
 

Private Types

typedef Allocator_TransferNoncopyable< TY, PAR > _ThisType
 

Private Attributes

PAR par_
 

Class Documentation

◆ lib::Allocator_TransferNoncopyable::rebind

struct lib::Allocator_TransferNoncopyable::rebind
Class Members
typedef
Allocator_TransferNoncopyable
< XX, PAR >
other
+ Collaboration diagram for Allocator_TransferNoncopyable< TY, PAR >::rebind< XX >:
+ Collaboration diagram for Allocator_TransferNoncopyable< TY, PAR >:

The documentation for this class was generated from the following file: