From 2b4b7232b79f98764c3a0a7962d75dc493ac4079 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Mon, 9 Dec 2019 10:12:29 +0200 Subject: [PATCH] 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`. --- TESTS/mbed_platform/SharedPtr/main.cpp | 4 ++-- platform/SharedPtr.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TESTS/mbed_platform/SharedPtr/main.cpp b/TESTS/mbed_platform/SharedPtr/main.cpp index 3afc936763..35d40e48b1 100644 --- a/TESTS/mbed_platform/SharedPtr/main.cpp +++ b/TESTS/mbed_platform/SharedPtr/main.cpp @@ -65,7 +65,7 @@ void test_single_sharedptr_lifetime() */ void test_instance_sharing() { - SharedPtr s_ptr1(NULL); + SharedPtr 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); diff --git a/platform/SharedPtr.h b/platform/SharedPtr.h index edaa8198b3..74ae53a90f 100644 --- a/platform/SharedPtr.h +++ b/platform/SharedPtr.h @@ -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