HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
coroutine
task.hpp
1
// Copyright Take Vos 2022.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
#pragma once
6
7
#include "../utility/utility.hpp"
8
#include "../macros.hpp"
9
#include <coroutine>
10
#include <type_traits>
11
12
13
14
namespace
hi::inline
v1
{
15
16
template
<
typename
T>
17
class
task;
18
19
template
<
typename
T>
20
struct
task_promise_base
{
21
T _value;
22
23
void
return_void()
noexcept
24
{
25
hi_no_default();
26
}
27
28
void
return_value(std::convertible_to<T>
auto
&&value)
noexcept
29
{
30
_value = hi_forward(value);
31
}
32
};
33
34
template
<>
35
struct
task_promise_base
<
void
> {
36
void
return_void()
noexcept
{}
37
};
38
39
template
<
typename
T>
40
struct
task_promise
:
task_promise_base
<T> {
41
using
value_type = T;
42
using
handle_type = std::coroutine_handle<task_promise<value_type>>;
43
using
task_type
=
task<value_type>
;
44
45
static
void
unhandled_exception()
46
{
47
throw
;
48
}
49
50
task<value_type>
get_return_object()
51
{
52
return
task_type
{handle_type::from_promise(*
this
)};
53
}
54
55
static
std::suspend_never initial_suspend()
noexcept
56
{
57
return
{};
58
}
59
60
static
std::suspend_never final_suspend()
noexcept
61
{
62
return
{};
63
}
64
};
65
70
template
<
typename
T =
void
>
71
class
task
{
72
public
:
73
using
value_type = T;
74
using
promise_type
=
task_promise<value_type>
;
75
using
handle_type = std::coroutine_handle<promise_type>;
76
77
explicit
task
(handle_type coroutine) : _coroutine(coroutine) {}
78
79
task
() =
default
;
80
~task
()
81
{
82
}
83
84
task
(
task
const
&) =
delete
;
85
task
(
task
&&) =
delete
;
86
task
&operator=(
task
const
&) =
delete
;
87
task
&operator=(
task
&&) =
delete
;
88
89
private
:
90
handle_type _coroutine;
91
};
92
93
}
// namespace hi::inline v1
v1
DOXYGEN BUG.
Definition
algorithm.hpp:16
hi::v1::narrow_cast
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition
cast.hpp:377
v1::task
Co-routine task.
Definition
task.hpp:71
v1::task_promise_base
Definition
task.hpp:20
v1::task_promise
Definition
task.hpp:40
Generated on Mon Apr 22 2024 12:53:10 for HikoGUI by
1.10.0