Classes | Functions
value_ptr_test_2.cc File Reference
#include "cetlib/value_ptr.h"
#include <cassert>
#include <map>
#include <memory>
#include "cetlib/compiler_macros.h"

Go to the source code of this file.

Classes

class  simple
 

Functions

int main ()
 

Function Documentation

int main ( void  )

Definition at line 52 of file value_ptr_test_2.cc.

53 {
54  assert(simple::n_alive == 0);
55  {
57  assert(simple::n_born == 1);
58  assert(simple::n_alive == 1);
59 
60  {
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 
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 }
static int n_born
static int n_alive
const double e
const double a
static bool * b
Definition: config.cpp:1043