HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
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
14namespace hi::inline v1 {
15
16template<typename T>
17class task;
18
19template<typename T>
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
34template<>
36 void return_void() noexcept {}
37};
38
39template<typename T>
41 using value_type = T;
42 using handle_type = std::coroutine_handle<task_promise<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
70template<typename T = void>
71class task {
72public:
73 using value_type = T;
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
89private:
90 handle_type _coroutine;
91};
92
93} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Co-routine task.
Definition task.hpp:71
Definition task.hpp:20
Definition task.hpp:40