4
4
#include " fast_alloc.hpp"
5
5
#include < utility>
6
6
7
- template <typename T> struct ref_counter_base {
8
-
9
- virtual void inc_count ()= 0;
10
- virtual void dec_count ()= 0;
11
- virtual T* get () = 0;
7
+ struct ref_counter_base {
8
+ virtual void inc_count ()= 0;
9
+ virtual void dec_count ()= 0;
10
+ virtual void * get () = 0;
12
11
};
13
12
14
- template <typename T> struct ref_counter : ref_counter_base<T> {
13
+ template <typename T> struct ref_counter : ref_counter_base {
15
14
// / @brief the reference count of the object
16
15
int ref_count;
17
16
T content;
@@ -26,24 +25,18 @@ template <typename T> struct ref_counter : ref_counter_base<T> {
26
25
tm_delete (this );
27
26
}
28
27
}
29
- T * get () { return &content; }
28
+ void * get () { return &content; }
30
29
};
31
-
32
- template <typename Stored, typename Regard_As= Stored, typename ... Params>
33
- inline ref_counter_base<Regard_As>*
34
- make_derived (Params&&... p) {
35
- return reinterpret_cast <ref_counter_base<Regard_As>*> (
36
- tm_new<ref_counter<Stored>> (std::forward<Params> (p)...));
37
- }
38
-
39
30
template <typename T, bool nullable= false > class counted_ptr {
40
31
41
32
protected:
42
- using counter_t = ref_counter_base<T> ;
33
+ using counter_t = ref_counter_base;
43
34
using base = counted_ptr<T, nullable>;
44
- explicit counted_ptr (counter_t * c) : counter (c), rep (c->get ()) {}
45
- template <typename ... Params> static counter_t * make (Params&&... p) {
46
- return tm_new<ref_counter<T>> (std::forward<Params> (p)...);
35
+ explicit counted_ptr (counter_t * c)
36
+ : counter (c), rep (static_cast <T*> (c->get ())) {}
37
+ template <typename Stored= T, typename ... Params>
38
+ static counter_t * make (Params&&... p) {
39
+ return tm_new<ref_counter<Stored>> (std::forward<Params> (p)...);
47
40
}
48
41
49
42
private:
0 commit comments