SharedPtr: add nullptr constructor

For consistency with `std::shared_ptr`, and `mbed::Callback`, and as a
potential optimisation aid, give `SharedPtr` a distinct constructor for
`nullptr`.
pull/12048/head
Kevin Bracey 2019-12-09 10:12:29 +02:00
parent 888dfffabf
commit 2b4b7232b7
2 changed files with 9 additions and 2 deletions

View File

@ -65,7 +65,7 @@ void test_single_sharedptr_lifetime()
*/
void test_instance_sharing()
{
SharedPtr<TestStruct> s_ptr1(NULL);
SharedPtr<TestStruct> s_ptr1(nullptr);
// Sanity-check value of counter
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
@ -80,7 +80,7 @@ void test_instance_sharing()
TEST_ASSERT_EQUAL(1, TestStruct::s_count);
s_ptr1 = NULL;
s_ptr1 = nullptr;
// Destroy shared pointer
TEST_ASSERT_EQUAL(0, TestStruct::s_count);

View File

@ -75,6 +75,13 @@ public:
{
}
/**
* @brief Create empty SharedPtr not pointing to anything.
*/
constexpr SharedPtr(std::nullptr_t) : SharedPtr()
{
}
/**
* @brief Create new SharedPtr
* @param ptr Pointer to take control over