OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
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{
29 X* px;
30public:
31 my_auto_ptr() : px(0) {}
32 my_auto_ptr(X* p) : px(p) {}
35 {
36 if (&r != this)
37 {
38 delete px;
39 px = r.release();
40 }
41 return *this;
42 }
43 ~my_auto_ptr() { delete px; }
44 X& operator*() const { return *px; }
45 X* operator->() const { return px; }
46 X* get() const { return px; }
47 X* release() const { X *p=px; ((my_auto_ptr<X>*)(this))->px=0; return p; }
48};
49
50
51#endif // MY_AUTO_PTR_H
#define X(arg)
Definition: fftpack.cpp:112
X & operator*() const
Definition: my_auto_ptr.h:44
X * get() const
Definition: my_auto_ptr.h:46
my_auto_ptr(X *p)
Definition: my_auto_ptr.h:32
my_auto_ptr(const my_auto_ptr< X > &r)
Definition: my_auto_ptr.h:33
X * operator->() const
Definition: my_auto_ptr.h:45
my_auto_ptr & operator=(const my_auto_ptr< X > &r)
Definition: my_auto_ptr.h:34
X * release() const
Definition: my_auto_ptr.h:47