Skip to content

Commit 2d751cf

Browse files
committed
Do not allocate control block if input pointer is null
1 parent bb4de1c commit 2d751cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/oup/observable_unique_ptr.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class observable_unique_ptr {
194194
* using make_observable_unique() instead of this constructor.
195195
*/
196196
explicit observable_unique_ptr(T* value) :
197-
observable_unique_ptr(allocate_block_(), value) {}
197+
observable_unique_ptr(value != nullptr ? allocate_block_() : nullptr, value) {}
198198

199199
/// Explicit ownership capture of a raw pointer, with customer deleter.
200200
/** \param value The raw pointer to take ownership of
@@ -204,7 +204,7 @@ class observable_unique_ptr {
204204
* using make_observable_unique() instead of this constructor.
205205
*/
206206
explicit observable_unique_ptr(T* value, Deleter del) :
207-
observable_unique_ptr(allocate_block_(), value, std::move(del)) {}
207+
observable_unique_ptr(value != nullptr ? allocate_block_() : nullptr, value, std::move(del)) {}
208208

209209
/// Transfer ownership by implicit casting
210210
/** \param value The pointer to take ownership from

0 commit comments

Comments
 (0)