mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
888dfffabf
commit
2b4b7232b7
|
|
@ -65,7 +65,7 @@ void test_single_sharedptr_lifetime()
|
||||||
*/
|
*/
|
||||||
void test_instance_sharing()
|
void test_instance_sharing()
|
||||||
{
|
{
|
||||||
SharedPtr<TestStruct> s_ptr1(NULL);
|
SharedPtr<TestStruct> s_ptr1(nullptr);
|
||||||
|
|
||||||
// Sanity-check value of counter
|
// Sanity-check value of counter
|
||||||
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
|
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
|
||||||
|
|
@ -80,7 +80,7 @@ void test_instance_sharing()
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(1, TestStruct::s_count);
|
TEST_ASSERT_EQUAL(1, TestStruct::s_count);
|
||||||
|
|
||||||
s_ptr1 = NULL;
|
s_ptr1 = nullptr;
|
||||||
|
|
||||||
// Destroy shared pointer
|
// Destroy shared pointer
|
||||||
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
|
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,13 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create empty SharedPtr not pointing to anything.
|
||||||
|
*/
|
||||||
|
constexpr SharedPtr(std::nullptr_t) : SharedPtr()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create new SharedPtr
|
* @brief Create new SharedPtr
|
||||||
* @param ptr Pointer to take control over
|
* @param ptr Pointer to take control over
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue