Loading...
Searching...
No Matches
memory.hpp
/*
SPDX-License-Identifier: MIT
Copyright © 2023 Amebis
*/
#pragma once
#include "compat.hpp"
#include <memory>
namespace stdex
{
template <class T>
struct no_delete {
constexpr no_delete() noexcept = default;
template <class T2, std::enable_if_t<std::is_convertible_v<T2*, T*>, int> = 0>
inline no_delete(const no_delete<T2>&) noexcept {}
inline void operator()(T* p) const noexcept { _Unreferenced_(p); }
};
template <class T>
struct no_delete<T[]> {
constexpr no_delete() noexcept = default;
template <class _Uty, std::enable_if_t<std::is_convertible_v<_Uty(*)[], T(*)[]>, int> = 0>
inline no_delete(const no_delete<_Uty[]>&) noexcept {}
template <class _Uty, std::enable_if_t<std::is_convertible_v<_Uty(*)[], T(*)[]>, int> = 0>
inline void operator()(_Uty* p) const noexcept { p; }
};
template <class T>
inline std::shared_ptr<T> make_shared_no_delete(_In_ T* p)
{
return std::shared_ptr<T>(p, no_delete<T>{});
}
}
stdex::no_delete
Noop deleter.
Definition memory.hpp:17