IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
my_auto_ptr.h
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
26
template
<
class
X>
27
class
my_auto_ptr
{
28
X* px;
29
30
public
:
31
my_auto_ptr
()
32
: px(0) {}
33
my_auto_ptr
(X* p)
34
: px(p) {}
35
my_auto_ptr
(
const
my_auto_ptr<X>
& r)
36
: px(r.release()) {}
37
my_auto_ptr
& operator=(
const
my_auto_ptr<X>
& r) {
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
my_auto_ptr
Definition
my_auto_ptr.h:27
ippl-src
src
Utility
my_auto_ptr.h
Generated by
1.9.8