IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
my_auto_ptr.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 *
7 * Visit http://people.web.psi.ch/adelmann/ for more details
8 *
9 ***************************************************************************/
10
11#ifndef MY_AUTO_PTR_H
12#define MY_AUTO_PTR_H
13
15/*
16 A simple compliant implementation of auto_ptr.
17 This is from Greg Colvin's implementation posted to comp.std.c++.
18
19 Instead of using mutable this casts away const in release.
20
21 We have to do this because we can't build containers of these
22 things otherwise.
23 */
25
26template <class X>
28 X* px;
29
30public:
32 : px(0) {}
34 : px(p) {}
36 : px(r.release()) {}
38 if (&r != this) {
39 delete px;
40 px = r.release();
41 }
42 return *this;
43 }
44 ~my_auto_ptr() { delete px; }
45 X& operator*() const { return *px; }
46 X* operator->() const { return px; }
47 X* get() const { return px; }
48 X* release() const {
49 X* p = px;
50 ((my_auto_ptr<X>*)(this))->px = 0;
51 return p;
52 }
53};
54
55#endif // MY_AUTO_PTR_H
X & operator*() const
Definition my_auto_ptr.h:45
X * get() const
Definition my_auto_ptr.h:47
my_auto_ptr(X *p)
Definition my_auto_ptr.h:33
my_auto_ptr(const my_auto_ptr< X > &r)
Definition my_auto_ptr.h:35
X * operator->() const
Definition my_auto_ptr.h:46
my_auto_ptr & operator=(const my_auto_ptr< X > &r)
Definition my_auto_ptr.h:37
X * release() const
Definition my_auto_ptr.h:48