Implement Singleton Auxiliary class#20
Conversation
Codecov ReportBase: 73.04% // Head: 73.22% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
+ Coverage 73.04% 73.22% +0.18%
==========================================
Files 42 43 +1
Lines 742 747 +5
Branches 175 175
==========================================
+ Hits 542 547 +5
Misses 104 104
Partials 96 96
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
| template <typename T, int Index> | ||
| std::shared_ptr<T> Singleton<T, Index>::get_shared_instance() noexcept | ||
| { | ||
| static std::shared_ptr<T> instance_(new T()); |
There was a problem hiding this comment.
Just to leave here our offline conversation:
Getting a pointer instead of a reference to an object in stack might be more dangerous (could be deleted by user), we need to have this in mind when using it and modify it if needed.
There was a problem hiding this comment.
As we discussed, this way allows to control the liveliness of the internal object by shared_ptr, while having it in stack would not.
However, I still think that auto x = shared_ptr<int>(3); delete x.get(); is a possible code, and shared_ptr does not care. We might give the user some credit and trust its intelect 😋 .
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu <javierparis@eprosima.com>
bdaa5a0 to
fac88b7
Compare
Signed-off-by: jparisu <javierparis@eprosima.com>
Signed-off-by: jparisu javierparis@eprosima.com