IceShard
1
A personal game engine project, with development focused on 2D/2.5D games.
Toggle main menu visibility
Loading...
Searching...
No Matches
tasks
public
ice
task_promise.hxx
Go to the documentation of this file.
1
3
4
#pragma once
5
#include <
ice/assert.hxx
>
6
#include <
ice/task_promise_base.hxx
>
7
8
namespace
ice
9
{
10
11
template
<
typename
Value>
12
class
TaskPromise
:
public
ice::TaskPromiseBase
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>
40
class
TaskPromise
<T&> :
public
ice::TaskPromiseBase
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
assert.hxx
ICE_ASSERT
#define ICE_ASSERT(condition, message,...)
Definition
assert.hxx:29
ice::Task
Definition
task.hxx:12
ice::TaskPromise< T & >::get_return_object
auto get_return_object() noexcept -> ice::Task< T & >
ice::TaskPromise< T & >::result
auto result() const noexcept -> T &
Definition
task_promise.hxx:50
ice::TaskPromise< T & >::return_value
void return_value(T &value) noexcept
Definition
task_promise.hxx:45
ice::TaskPromise< void >::result
constexpr void result() const noexcept
Definition
task_promise.hxx:68
ice::TaskPromise< void >::return_void
constexpr void return_void() const noexcept
Definition
task_promise.hxx:66
ice::TaskPromise
Definition
task_promise.hxx:13
ice::TaskPromise::result
auto result() &noexcept -> Value &
Definition
task_promise.hxx:25
ice::TaskPromise::result
auto result() &&noexcept -> Value &&
Definition
task_promise.hxx:30
ice::TaskPromise< ValueType >::return_value
void return_value(Other &&value) noexcept
Definition
task_promise.hxx:19
ice::TaskPromise::get_return_object
auto get_return_object() noexcept -> ice::Task< Value >
Definition
task.hxx:144
ice
SPDX-License-Identifier: MIT.
Definition
array.hxx:12
ice::TaskPromiseBase
Definition
task_promise_base.hxx:13
task_promise_base.hxx
Generated by
1.18.0