mini-llvm 0.1.0
Loading...
Searching...
No Matches
Memory.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <memory>
6
7namespace mini_llvm {
8
9template <typename To, typename From>
10std::unique_ptr<To> cast(std::unique_ptr<From> from) noexcept {
11 return std::unique_ptr<To>(static_cast<To *>(from.release()));
12}
13
14template <typename To, typename From>
15std::shared_ptr<To> cast(std::shared_ptr<From> from) noexcept {
16 return std::static_pointer_cast<To>(from);
17}
18
19template <typename To, typename From>
20std::weak_ptr<To> cast(std::weak_ptr<From> from) noexcept {
21 return std::static_pointer_cast<To>(from.lock());
22}
23
24template <typename T>
25std::shared_ptr<T> share(T &value) {
26 return cast<T>(value.shared_from_this());
27}
28
29template <typename T>
30std::weak_ptr<T> weaken(T &value) {
31 return cast<T>(value.weak_from_this());
32}
33
34} // namespace mini_llvm
Definition GraphColoringAllocator.h:13
std::shared_ptr< T > share(T &value)
Definition Memory.h:25
std::weak_ptr< T > weaken(T &value)
Definition Memory.h:30
std::unique_ptr< To > cast(std::unique_ptr< From > from) noexcept
Definition Memory.h:10