tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
coroutine_handle.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_COROUTINE_COROUTINE_HANDLE_HPP
4#define TETL_COROUTINE_COROUTINE_HANDLE_HPP
5
8
9#if defined(__cpp_coroutines)
10
11namespace etl {
12
14template <typename Promise = void>
16
18template <>
19struct coroutine_handle<void> {
20 constexpr coroutine_handle() noexcept = default;
21
22 constexpr coroutine_handle(nullptr_t handle) noexcept
23 : _handle(handle)
24 {
25 }
26
27 constexpr auto operator=(nullptr_t) noexcept -> coroutine_handle&
28 {
29 _handle = nullptr;
30 return *this;
31 }
32
33 [[nodiscard]] constexpr auto address() const noexcept -> void* { return _handle; }
34
35 [[nodiscard]] static constexpr auto from_address(void* addr) noexcept -> coroutine_handle
36 {
37 auto self = coroutine_handle{};
38 self._handle = addr;
39 return self;
40 }
41
42 [[nodiscard]] constexpr explicit operator bool() const noexcept { return _handle != nullptr; }
43
44 [[nodiscard]] auto done() const noexcept -> bool { return __builtin_coro_done(_handle); }
45
46 auto operator()() const -> void { resume(); }
47
48 auto resume() const -> void { __builtin_coro_resume(_handle); }
49
50 auto destroy() const -> void { __builtin_coro_destroy(_handle); }
51
52protected:
53 void* _handle{nullptr};
54};
55
58template <typename T>
60 [[nodiscard]] auto operator()(coroutine_handle<T> const& v) const noexcept -> size_t
61 {
62 return hash<void*>()(v.address());
63 }
64};
65
66} // namespace etl
67
68#endif // defined(__cpp_coroutines)
69
70#endif // TETL_COROUTINE_COROUTINE_HANDLE_HPP
Definition adjacent_find.hpp:8
decltype(nullptr) nullptr_t
etl::nullptr_t is the type of the null pointer literal, nullptr. It is a distinct type that is not it...
Definition nullptr_t.hpp:13
constexpr auto address() const noexcept -> void *
Definition coroutine_handle.hpp:33
constexpr coroutine_handle() noexcept=default
constexpr auto operator=(nullptr_t) noexcept -> coroutine_handle &
Definition coroutine_handle.hpp:27
auto operator()() const -> void
Definition coroutine_handle.hpp:46
static constexpr auto from_address(void *addr) noexcept -> coroutine_handle
Definition coroutine_handle.hpp:35
auto resume() const -> void
Definition coroutine_handle.hpp:48
auto destroy() const -> void
Definition coroutine_handle.hpp:50
void * _handle
Definition coroutine_handle.hpp:53
auto done() const noexcept -> bool
Definition coroutine_handle.hpp:44
Definition coroutine_handle.hpp:15
auto operator()(coroutine_handle< T > const &v) const noexcept -> size_t
Definition coroutine_handle.hpp:60
hash
Definition hash.hpp:14