mini-llvm
0.1.0
Toggle main menu visibility
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
7
namespace
mini_llvm
{
8
9
template
<
typename
To,
typename
From>
10
std::unique_ptr<To>
cast
(std::unique_ptr<From> from)
noexcept
{
11
return
std::unique_ptr<To>(
static_cast<
To *
>
(from.release()));
12
}
13
14
template
<
typename
To,
typename
From>
15
std::shared_ptr<To>
cast
(std::shared_ptr<From> from)
noexcept
{
16
return
std::static_pointer_cast<To>(from);
17
}
18
19
template
<
typename
To,
typename
From>
20
std::weak_ptr<To>
cast
(std::weak_ptr<From> from)
noexcept
{
21
return
std::static_pointer_cast<To>(from.lock());
22
}
23
24
template
<
typename
T>
25
std::shared_ptr<T>
share
(T &value) {
26
return
cast<T>
(value.shared_from_this());
27
}
28
29
template
<
typename
T>
30
std::weak_ptr<T>
weaken
(T &value) {
31
return
cast<T>
(value.weak_from_this());
32
}
33
34
}
// namespace mini_llvm
mini_llvm
Definition
GraphColoringAllocator.h:13
mini_llvm::share
std::shared_ptr< T > share(T &value)
Definition
Memory.h:25
mini_llvm::weaken
std::weak_ptr< T > weaken(T &value)
Definition
Memory.h:30
mini_llvm::cast
std::unique_ptr< To > cast(std::unique_ptr< From > from) noexcept
Definition
Memory.h:10
include
mini-llvm
utils
Memory.h
Generated by
1.17.0