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) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
32 #ifndef LIB_SCOPEDHOLDER_TRANSFER_H
33 #define LIB_SCOPEDHOLDER_TRANSFER_H
34 
35 #include "lib/error.hpp"
36 #include <memory>
37 
38 
39 namespace lib {
40 
41 
42 
43 
76  template<class TY, class PAR = std::allocator<TY>>
78  {
80 
81  PAR par_;
82 
83 
84  public:
85  typedef typename PAR::size_type size_type;
86  typedef typename PAR::difference_type difference_type;
87  typedef typename PAR::pointer pointer;
88  typedef typename PAR::const_pointer const_pointer;
89  typedef typename PAR::reference reference;
90  typedef typename PAR::const_reference const_reference;
91  typedef typename PAR::value_type value_type;
92 
93  template<typename XX>
94  struct rebind
96 
98 
99  Allocator_TransferNoncopyable(const _ThisType& allo)
100  : par_(allo.par_) { }
101  Allocator_TransferNoncopyable(const PAR& allo)
102  : par_(allo) { }
103 
104  template<typename X>
105  Allocator_TransferNoncopyable(const std::allocator<X>&) { }
106 
108 
109 
110  //------------proxying-the-parent-allocator------------------------------------
111 
112  size_type max_size() const { return par_.max_size(); }
113  pointer address(reference r) const { return par_.address(r); }
114  const_pointer address(const_reference cr) const { return par_.address(cr); }
115  pointer allocate(size_type n, const void *p=0){ return par_.allocate(n,p); }
116  void deallocate(pointer p, size_type n) { par_.deallocate(p,n); }
117  void destroy(pointer p) { par_.destroy(p); }
118 
119 
120  void
121  construct (pointer p, const TY& ref)
122  {
123  new(p) TY();
124  ASSERT (p);
125  ASSERT (!(*p), "protocol violation: target already manages another object.");
126  if (ref)
127  transfer_control (const_cast<TY&>(ref), *p);
128  }
129  };
130 
131  template<typename TY1, typename TY2, class ALO>
132  inline bool
134  { return true; }
135 
136  template<typename TY1, typename TY2, class ALO>
137  inline bool
139  { return false; }
140 
141 
142 
143 
144 } // namespace lib
145 #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).