Skip to content

Commit 7fa095b

Browse files
authored
Feature: injectable strict shared pointer (#14)
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 29244b7 commit 7fa095b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/qtils/strict_sptr.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#pragma once
8+
79
#include <memory>
810
#include <stdexcept>
911
#include <type_traits>
@@ -43,6 +45,13 @@ namespace qtils {
4345
}
4446
}
4547

48+
private:
49+
struct ForceInject{}; // Auxiliary arg appended to select ctor for DI
50+
51+
public:
52+
StrictSharedPtr(std::shared_ptr<T> sptr, ForceInject):
53+
StrictSharedPtr(std::move(sptr)) {}
54+
4655
// Copy constructor and assignment
4756
StrictSharedPtr(const StrictSharedPtr &) = default;
4857
StrictSharedPtr &operator=(const StrictSharedPtr &) = default;

0 commit comments

Comments
 (0)