Lumiera  0.pre.03
»edit your freedom«
scoped-holder-transfer.hpp
Go to the documentation of this file.
1 /*
2  SCOPED-HOLDER-TRANSFER.hpp - using ScopedHolder within a STL vector
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
23 #ifndef LIB_SCOPEDHOLDER_TRANSFER_H
24 #define LIB_SCOPEDHOLDER_TRANSFER_H
25 
26 #include "lib/error.hpp"
27 #include <memory>
28 
29 
30 namespace lib {
31 
32 
33 
34 
67  template<class TY, class PAR = std::allocator<TY>>
69  {
71 
72  PAR par_;
73 
74 
75  public:
76  typedef typename PAR::size_type size_type;
77  typedef typename PAR::difference_type difference_type;
78  typedef typename PAR::pointer pointer;
79  typedef typename PAR::const_pointer const_pointer;
80  typedef typename PAR::reference reference;
81  typedef typename PAR::const_reference const_reference;
82  typedef typename PAR::value_type value_type;
83 
84  template<typename XX>
85  struct rebind
87 
89 
90  Allocator_TransferNoncopyable(const _ThisType& allo)
91  : par_(allo.par_) { }
92  Allocator_TransferNoncopyable(const PAR& allo)
93  : par_(allo) { }
94 
95  template<typename X>
96  Allocator_TransferNoncopyable(const std::allocator<X>&) { }
97 
99 
100 
101  //------------proxying-the-parent-allocator------------------------------------
102 
103  size_type max_size() const { return par_.max_size(); }
104  pointer address(reference r) const { return par_.address(r); }
105  const_pointer address(const_reference cr) const { return par_.address(cr); }
106  pointer allocate(size_type n, const void *p=0){ return par_.allocate(n,p); }
107  void deallocate(pointer p, size_type n) { par_.deallocate(p,n); }
108  void destroy(pointer p) { par_.destroy(p); }
109 
110 
111  void
112  construct (pointer p, const TY& ref)
113  {
114  new(p) TY();
115  ASSERT (p);
116  ASSERT (!(*p), "protocol violation: target already manages another object.");
117  if (ref)
118  transfer_control (const_cast<TY&>(ref), *p);
119  }
120  };
121 
122  template<typename TY1, typename TY2, class ALO>
123  inline bool
125  { return true; }
126 
127  template<typename TY1, typename TY2, class ALO>
128  inline bool
130  { return false; }
131 
132 
133 
134 
135 } // namespace lib
136 #endif
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
Implementation namespace for support and library code.
Addendum to scoped-holder.hpp for transferring the lifecycle management to another instance...
Lumiera error handling (C++ interface).