summaryrefslogtreecommitdiff
path: root/tests/run/cpp_smart_ptr_helper.h
blob: 02d73868cd7b76a094af782361bf70c55823f065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class CountAllocDealloc {
  public:
      CountAllocDealloc(int* alloc_count, int* dealloc_count)
          : _alloc_count(alloc_count), _dealloc_count(dealloc_count) {
        (*_alloc_count)++;
      }
      ~CountAllocDealloc() {
        (*_dealloc_count)++;
      }
  private:
    int* _alloc_count;
    int* _dealloc_count;
};

template<typename T>
struct FreePtr {
  void operator()( T * t )
  {
    if(t != nullptr) {
      delete t;
      t=nullptr;
    }
  }
};