diff --git a/data/Data.cpp b/data/Data.cpp index 9c21c9ca..dee82804 100644 --- a/data/Data.cpp +++ b/data/Data.cpp @@ -7,7 +7,6 @@ using std::ofstream; using std::ifstream; using std::ios; using std::unique_ptr; -using std::make_unique; namespace bf = boost::filesystem; diff --git a/test/pointer_test.cpp b/test/pointer_test.cpp index b8ed110c..d31361ba 100644 --- a/test/pointer_test.cpp +++ b/test/pointer_test.cpp @@ -4,7 +4,6 @@ using namespace cpputils; using std::unique_ptr; -using std::make_unique; class Parent { public: diff --git a/unique_ref.h b/unique_ref.h index fe1e4915..559ee911 100644 --- a/unique_ref.h +++ b/unique_ref.h @@ -4,6 +4,7 @@ #include #include #include "macros.h" +#include "pointer.h" namespace cpputils { @@ -26,6 +27,8 @@ class unique_ref { public: unique_ref(unique_ref&& from): _target(std::move(from._target)) {} + // TODO Test this dynamic-cast-allowing move constructor + template unique_ref(unique_ref&& from): _target(std::move(from._target)) {} unique_ref& operator=(unique_ref&& from) { _target = std::move(from._target); @@ -52,6 +55,8 @@ private: unique_ref(std::unique_ptr target): _target(std::move(target)) {} template friend unique_ref make_unique_ref(Args&&... args); template friend boost::optional> nullcheck(std::unique_ptr ptr); + template friend unique_ref dynamic_pointer_move(unique_ref &source); + template friend class unique_ref; std::unique_ptr _target; @@ -71,6 +76,13 @@ inline boost::optional> nullcheck(std::unique_ptr ptr) { return boost::none; } +//TODO Write test cases for dynamic_pointer_move +//TODO Also allow passing a rvalue reference, otherwise dynamic_pointer_move(func()) won't work +template +inline unique_ref dynamic_pointer_move(unique_ref &source) { + return unique_ref(dynamic_pointer_move(source._target)); +} + template inline bool operator==(const unique_ref &lhs, const unique_ref &rhs) { return lhs.get() == rhs.get();