#ifndef TATAMI_WRAP_SHARED_PTR_HPP #define TATAMI_WRAP_SHARED_PTR_HPP #include #include "../base/Matrix.hpp" namespace tatami { /** * Wrap a raw pointer inside a `shared_ptr`, typically to enable use of a raw `tatami::Matrix` pointer with delayed operation wrappers. * This enables use of delayed operations inside functions that accept a raw pointer to an externally owned `tatami::Matrix`. * * @param ptr A pointer to a `tatami::Matrix` instance. * * @return A shared pointer to the same object addressed by `ptr`. * The assumption is that `ptr` will always outlive the returned pointer. */ template std::shared_ptr > wrap_shared_ptr(const Matrix* ptr) { // Using a no-op deleter in a shared pointer to get it to work with, e.g., // delayed operations without actually taking ownership of 'ptr'. This // shared pointer should only be used as long as 'ptr' is alive. return std::shared_ptr >(ptr, [](const Matrix*){}); } } #endif