OPAL (Object Oriented Parallel Accelerator Library)
2021.1.99
OPAL
src
ippl
src
Utility
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
26
template
<
class
X>
27
class
my_auto_ptr
28
{
29
X
*
px
;
30
public
:
31
my_auto_ptr
() :
px
(0) {}
32
my_auto_ptr
(
X
* p) :
px
(p) {}
33
my_auto_ptr
(
const
my_auto_ptr<X>
& r) :
px
(r.
release
()) {}
34
my_auto_ptr
&
operator=
(
const
my_auto_ptr<X>
& r)
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
X
#define X(arg)
Definition:
fftpack.cpp:112
my_auto_ptr
Definition:
my_auto_ptr.h:28
my_auto_ptr::operator*
X & operator*() const
Definition:
my_auto_ptr.h:44
my_auto_ptr::my_auto_ptr
my_auto_ptr()
Definition:
my_auto_ptr.h:31
my_auto_ptr::operator=
my_auto_ptr & operator=(const my_auto_ptr< X > &r)
Definition:
my_auto_ptr.h:34
my_auto_ptr::my_auto_ptr
my_auto_ptr(X *p)
Definition:
my_auto_ptr.h:32
my_auto_ptr::my_auto_ptr
my_auto_ptr(const my_auto_ptr< X > &r)
Definition:
my_auto_ptr.h:33
my_auto_ptr::~my_auto_ptr
~my_auto_ptr()
Definition:
my_auto_ptr.h:43
my_auto_ptr::operator->
X * operator->() const
Definition:
my_auto_ptr.h:45
my_auto_ptr::get
X * get() const
Definition:
my_auto_ptr.h:46
my_auto_ptr::px
X * px
Definition:
my_auto_ptr.h:29
my_auto_ptr::release
X * release() const
Definition:
my_auto_ptr.h:47
Generated on Wed Aug 25 2021 16:41:00 for OPAL (Object Oriented Parallel Accelerator Library) by
1.9.1