#pragma once #ifndef MESSMER_CPP_UTILS_POINTER_CAST_H_ #define MESSMER_CPP_UTILS_POINTER_CAST_H_ #include namespace cpputils { /** * dynamic_cast implementation for unique_ptr (moving unique_ptr into a unique_ptr of different type) */ //TODO Also allow passing a rvalue reference, otherwise dynamic_pointer_move(func()) won't work template inline std::unique_ptr dynamic_pointer_move(std::unique_ptr &source) { //TODO Deleter DST *casted = dynamic_cast(source.get()); if (casted != nullptr) { source.release(); } return std::unique_ptr(casted); } } #endif