1 | // |
2 | // immer: immutable data structures for C++ |
3 | // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente |
4 | // |
5 | // This software is distributed under the Boost Software License, Version 1.0. |
6 | // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt |
7 | // |
8 | |
9 | #pragma once |
10 | |
11 | #include <immer/refcount/no_refcount_policy.hpp> |
12 | |
13 | namespace immer { |
14 | |
15 | template <typename Deriv, typename RefcountPolicy> |
16 | class enable_intrusive_ptr |
17 | { |
18 | mutable RefcountPolicy refcount_data_; |
19 | |
20 | public: |
21 | enable_intrusive_ptr() |
22 | : refcount_data_{disowned{}} |
23 | {} |
24 | |
25 | friend void intrusive_ptr_add_ref(const Deriv* x) |
26 | { |
27 | x->refcount_data_.inc(); |
28 | } |
29 | |
30 | friend void intrusive_ptr_release(const Deriv* x) |
31 | { |
32 | if (x->refcount_data_.dec()) |
33 | delete x; |
34 | } |
35 | }; |
36 | |
37 | } // namespace immer |
38 | |