Allow get_rcp() to be called on a const reference
This commit is contained in:
parent
0de327d442
commit
7d5316bd79
@ -297,9 +297,9 @@ rcp<T> rcp_dynamic_cast(rcp<U> && other)
|
||||
|
||||
#define rcp_managed(classname) \
|
||||
public: \
|
||||
rcp<classname> get_rcp() \
|
||||
rcp<classname> get_rcp() const \
|
||||
{ \
|
||||
return rcp<classname>(this); \
|
||||
return rcp<classname>(const_cast<classname *>(this)); \
|
||||
} \
|
||||
template <typename... Args> \
|
||||
static rcp<classname> create(Args&&... args) \
|
||||
|
||||
11
tests.cpp
11
tests.cpp
@ -114,6 +114,16 @@ struct Receiver
|
||||
}
|
||||
};
|
||||
|
||||
void test_get_rcp_const()
|
||||
{
|
||||
auto a = MyObj::create();
|
||||
const MyObj & ref = *a;
|
||||
rcp<MyObj> b = ref.get_rcp();
|
||||
assert(b);
|
||||
assert(b->v == 42);
|
||||
assert(b.use_count() == 2);
|
||||
}
|
||||
|
||||
void test_multi_construct_from_raw_pointers()
|
||||
{
|
||||
Receiver r;
|
||||
@ -423,6 +433,7 @@ int main(int argc, char * argv[])
|
||||
test_dereference();
|
||||
test_booleans();
|
||||
test_create();
|
||||
test_get_rcp_const();
|
||||
test_multi_construct_from_raw_pointers();
|
||||
test_listener_self_registration();
|
||||
test_copy_assignment_decrements_previous_reference();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user