IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_promise.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/assert.hxx>
7
8namespace ice
9{
10
11 template<typename Value>
13 {
14 public:
15 inline auto get_return_object() noexcept -> ice::Task<Value>;
16
17 template<typename Other = Value>
18 requires std::is_nothrow_move_assignable_v<Value> && std::is_nothrow_convertible_v<Other&&, Value>
19 inline void return_value(Other&& value) noexcept
20 {
21 static_assert(std::is_nothrow_move_assignable_v<Value>, "We enforce noexcept everywhere.");
22 _value = std::forward<Other>(value);
23 }
24
25 inline auto result() & noexcept -> Value&
26 {
27 return _value;
28 }
29
30 inline auto result() && noexcept -> Value&&
31 {
32 return std::move(_value);
33 }
34
35 private:
36 Value _value;
37 };
38
39 template<typename T>
41 {
42 public:
43 inline auto get_return_object() noexcept -> ice::Task<T&>;
44
45 inline void return_value(T& value) noexcept
46 {
47 _value = ice::addressof(value);
48 }
49
50 inline auto result() const noexcept -> T&
51 {
52 ICE_ASSERT(_value != nullptr, "Trying to access result from unfinished task!");
53 return *_value;
54 }
55
56 private:
57 T* _value = nullptr;
58 };
59
60 template<>
61 class TaskPromise<void> : public ice::TaskPromiseBase
62 {
63 public:
64 inline auto get_return_object() noexcept -> ice::Task<void>;
65
66 constexpr void return_void() const noexcept { }
67
68 constexpr void result() const noexcept { }
69 };
70
71} // namespace ice
#define ICE_ASSERT(condition, message,...)
Definition assert.hxx:29
Definition task.hxx:12
auto get_return_object() noexcept -> ice::Task< T & >
auto result() const noexcept -> T &
Definition task_promise.hxx:50
void return_value(T &value) noexcept
Definition task_promise.hxx:45
constexpr void result() const noexcept
Definition task_promise.hxx:68
constexpr void return_void() const noexcept
Definition task_promise.hxx:66
Definition task_promise.hxx:13
auto result() &noexcept -> Value &
Definition task_promise.hxx:25
auto result() &&noexcept -> Value &&
Definition task_promise.hxx:30
void return_value(Other &&value) noexcept
Definition task_promise.hxx:19
auto get_return_object() noexcept -> ice::Task< Value >
Definition task.hxx:144
SPDX-License-Identifier: MIT.
Definition array.hxx:12
Definition task_promise_base.hxx:13