|
14 | 14 |
|
15 | 15 | #include "invariant.h"
|
16 | 16 |
|
17 |
| -template<typename T> |
| 17 | +/// \tparam empty: pointer to empty data, if unspecified use a reference to |
| 18 | +/// T::blank |
| 19 | +template <typename T, const T &empty = T::blank> |
18 | 20 | // NOLINTNEXTLINE(readability/identifiers)
|
19 | 21 | class reference_counting
|
20 | 22 | {
|
@@ -67,7 +69,7 @@ class reference_counting
|
67 | 69 | const T &read() const
|
68 | 70 | {
|
69 | 71 | if(d==nullptr)
|
70 |
| - return T::blank; |
| 72 | + return empty; |
71 | 73 | return *d;
|
72 | 74 | }
|
73 | 75 |
|
@@ -115,8 +117,8 @@ class reference_counting
|
115 | 117 | }
|
116 | 118 | };
|
117 | 119 |
|
118 |
| -template<class T> |
119 |
| -void reference_counting<T>::remove_ref(dt *old_d) |
| 120 | +template <class T, const T &empty> |
| 121 | +void reference_counting<T, empty>::remove_ref(dt *old_d) |
120 | 122 | {
|
121 | 123 | if(old_d==nullptr)
|
122 | 124 | return;
|
@@ -144,8 +146,8 @@ void reference_counting<T>::remove_ref(dt *old_d)
|
144 | 146 | }
|
145 | 147 | }
|
146 | 148 |
|
147 |
| -template<class T> |
148 |
| -void reference_counting<T>::detach() |
| 149 | +template <class T, const T &empty> |
| 150 | +void reference_counting<T, empty>::detach() |
149 | 151 | {
|
150 | 152 | #ifdef REFERENCE_COUNTING_DEBUG
|
151 | 153 | std::cout << "DETACH1: " << d << '\n';
|
@@ -179,20 +181,20 @@ void reference_counting<T>::detach()
|
179 | 181 | #endif
|
180 | 182 | }
|
181 | 183 |
|
182 |
| -template<class T> |
| 184 | +template <class T, const T &empty> |
183 | 185 | bool operator==(
|
184 |
| - const reference_counting<T> &o1, |
185 |
| - const reference_counting<T> &o2) |
| 186 | + const reference_counting<T, empty> &o1, |
| 187 | + const reference_counting<T, empty> &o2) |
186 | 188 | {
|
187 | 189 | if(o1.get_d()==o2.get_d())
|
188 | 190 | return true;
|
189 | 191 | return o1.read()==o2.read();
|
190 | 192 | }
|
191 | 193 |
|
192 |
| -template<class T> |
| 194 | +template <class T, const T &empty> |
193 | 195 | inline bool operator!=(
|
194 |
| - const reference_counting<T> &i1, |
195 |
| - const reference_counting<T> &i2) |
| 196 | + const reference_counting<T, empty> &i1, |
| 197 | + const reference_counting<T, empty> &i2) |
196 | 198 | { return !(i1==i2); }
|
197 | 199 |
|
198 | 200 | #endif // CPROVER_UTIL_REFERENCE_COUNTING_H
|
0 commit comments