4#ifndef TETL_COROUTINE_COROUTINE_HANDLE_HPP
5#define TETL_COROUTINE_COROUTINE_HANDLE_HPP
7#include <etl/_cstddef/nullptr_t.hpp>
8#include <etl/_functional/hash.hpp>
10#if defined(__cpp_coroutines)
15template <
typename Promise =
void>
16struct coroutine_handle;
20struct coroutine_handle<
void> {
21 constexpr coroutine_handle()
noexcept =
default;
23 constexpr coroutine_handle(nullptr_t handle)
noexcept
28 constexpr auto operator=(nullptr_t)
noexcept -> coroutine_handle&
34 [[nodiscard]]
constexpr auto address()
const noexcept ->
void*
39 [[nodiscard]]
static constexpr auto from_address(
void* addr)
noexcept -> coroutine_handle
41 auto self = coroutine_handle{};
46 [[nodiscard]]
constexpr explicit operator
bool()
const noexcept
48 return _handle !=
nullptr;
51 [[nodiscard]]
auto done()
const noexcept ->
bool
53 return __builtin_coro_done(_handle);
56 auto operator()()
const ->
void
61 auto resume()
const ->
void
63 __builtin_coro_resume(_handle);
66 auto destroy()
const ->
void
68 __builtin_coro_destroy(_handle);
72 void* _handle{
nullptr};
78struct hash<coroutine_handle<T>> {
79 [[nodiscard]]
auto operator()(coroutine_handle<T>
const& v)
const noexcept -> size_t
81 return hash<
void*>()(v.address());