Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
cetlib
cetlib
test
value_ptr_test_2.cc
Go to the documentation of this file.
1
#include "
cetlib/value_ptr.h
"
2
3
#include <cassert>
4
#include <map>
5
#include <memory>
6
7
#include "
cetlib/compiler_macros.h
"
8
9
class
simple
{
10
int
i
;
11
12
public
:
13
static
int
n_alive
;
14
static
int
n_born
;
15
16
simple
() : i(0)
17
{
18
++
n_alive
;
19
++
n_born
;
20
}
21
explicit
simple
(
int
j) : i(j)
22
{
23
++
n_alive
;
24
++
n_born
;
25
}
26
27
simple
(
simple
const
&
s
) : i(s.i)
28
{
29
++
n_alive
;
30
++
n_born
;
31
}
32
33
~simple
() { --
n_alive
; }
34
35
bool
36
operator==
(
simple
const
& o)
const
37
{
38
return
i == o.
i
;
39
}
40
bool
41
isSame
(
simple
const
& o)
const
42
{
43
return
&o ==
this
;
44
}
45
46
};
// simple
47
48
int
simple::n_alive
= 0;
49
int
simple::n_born
= 0;
50
51
int
52
main
()
53
{
54
assert(
simple::n_alive
== 0);
55
{
56
cet::value_ptr<simple>
a
(
new
simple
(10));
57
assert(
simple::n_born
== 1);
58
assert(
simple::n_alive
== 1);
59
60
{
61
cet::value_ptr<simple>
b
(a);
62
assert(
simple::n_born
== 2);
63
assert(
simple::n_alive
== 2);
64
65
assert(*a == *b);
66
assert(a->isSame(*b) ==
false
);
67
}
// b destroyed
68
assert(
simple::n_born
== 2);
69
assert(
simple::n_alive
== 1);
70
}
// a destroyed, too
71
assert(
simple::n_born
== 2);
72
assert(
simple::n_alive
== 0);
73
74
{
75
std::unique_ptr<simple>
c
(
new
simple
(11));
76
std::unique_ptr<simple>
d
(
new
simple
(11));
77
simple
*
pc
= c.get();
78
simple
* pd = d.get();
79
assert(pc != 0);
80
assert(pd != 0);
81
82
cet::value_ptr<simple>
e
(c.release());
83
assert(c.get() == 0);
84
assert(*d == *
e
);
85
assert(
e
.operator->() ==
pc
);
86
87
cet::value_ptr<simple>
f
;
88
if
(f)
89
assert(0);
90
else
{
91
}
92
f.reset(d.release());
93
assert(d.get() == 0);
94
assert(*
e
== *f);
95
assert(f.operator->() == pd);
96
if
(f) {
97
}
else
98
assert(0);
99
100
assert(
simple::n_alive
== 2);
101
assert(
simple::n_born
== 4);
102
103
std::map<cet::value_ptr<simple>,
int
>
m
;
104
m[
f
] = 0;
105
#if GCC_IS_AT_LEAST(4, 8, 1) || defined(__ICC) || defined(__clang__)
106
// Avoids a copy of f.
107
assert(
simple::n_born
== 5);
108
#else
109
assert(
simple::n_born
== 6);
110
#endif
111
}
112
assert(
simple::n_alive
== 0);
113
#if GCC_IS_AT_LEAST(4, 8, 1) || defined(__ICC) || defined(__clang__)
114
assert(
simple::n_born
== 5);
115
#else
116
assert(
simple::n_born
== 6);
117
#endif
118
}
keras_to_tensorflow.f
f
Definition:
keras_to_tensorflow.py:162
simple::~simple
~simple()
Definition:
value_ptr_test_2.cc:33
wirecell.units.pc
pc
Definition:
units.py:68
cet::value_ptr
Definition:
value_ptr.h:88
bump_copyright.d
string d
Definition:
bump_copyright.py:70
simple::n_born
static int n_born
Definition:
value_ptr_test_2.cc:14
simple::n_alive
static int n_alive
Definition:
value_ptr_test_2.cc:13
value_ptr.h
simple::simple
simple(int j)
Definition:
value_ptr_test_2.cc:21
simple::simple
simple()
Definition:
value_ptr_test_2.cc:16
e
const double e
Definition:
gUpMuFluxGen.cxx:165
simple::i
int i
Definition:
value_ptr_test_2.cc:10
ValidateOpDetSimulation.c
dictionary c
Definition:
ValidateOpDetSimulation.py:57
a
const double a
Definition:
gUpMuFluxGen.cxx:164
simple::simple
simple(simple const &s)
Definition:
value_ptr_test_2.cc:27
cache_state.m
m
Definition:
cache_state.py:415
simple
Definition:
value_ptr_test_2.cc:9
simple::operator==
bool operator==(simple const &o) const
Definition:
value_ptr_test_2.cc:36
simple::isSame
bool isSame(simple const &o) const
Definition:
value_ptr_test_2.cc:41
b
static bool * b
Definition:
config.cpp:1043
compiler_macros.h
main
int main()
Definition:
value_ptr_test_2.cc:52
s
static QCString * s
Definition:
config.cpp:1042
Generated by
1.8.11