librf

promise.h
1 #pragma once
2
3 #pragma push_macro("new")
4 #undef new
5
6 #ifndef DOXYGEN_SKIP_PROPERTY
7 namespace resumef
8 {
9 struct suspend_on_initial;
10 struct suspend_on_final;
11
12 template <typename _Ty>
13 struct promise_impl_t
14 {
15 using value_type = _Ty;
16 using state_type = state_t<value_type>;
17 using promise_type = promise_t<value_type>;
18 using future_type = future_t<value_type>;
19
20 promise_impl_t() noexcept {}
21 promise_impl_t(promise_impl_t&& _Right) noexcept = default;
22 promise_impl_t& operator = (promise_impl_t&& _Right) noexcept = default;
23 promise_impl_t(const promise_impl_t&) = delete;
24 promise_impl_t& operator = (const promise_impl_t&) = delete;
25
26 auto get_state() noexcept->state_type*;
27
28 suspend_on_initial initial_suspend() noexcept;
29 suspend_on_final final_suspend() noexcept;
30 template <typename _Uty>
31 _Uty&& await_transform(_Uty&& _Whatever) noexcept;
32 void set_exception(std::exception_ptr e);
33 #if defined(__clang__) || defined(__GNUC__)
34 void unhandled_exception(); //If the coroutine ends with an uncaught exception, it performs the following:
35 #endif
36 future_type get_return_object() noexcept;
37 void cancellation_requested() noexcept;
38
39 using _Alloc_char = std::allocator<char>;
40 void* operator new(size_t _Size);
41 void operator delete(void* _Ptr, size_t _Size);
42 #if !RESUMEF_INLINE_STATE
43 private:
44 counted_ptr<state_type> _state = state_future_t::_Alloc_state<state_type>(false);
45 #endif
46 };
47
48 template<class _Ty>
49 struct promise_t final : public promise_impl_t<_Ty>
50 {
51 using typename promise_impl_t<_Ty>::value_type;
52 using promise_impl_t<_Ty>::get_return_object;
53
54 template<class U>
55 void return_value(U&& val); //co_return val
56 template<class U>
57 suspend_always yield_value(U&& val);
58 };
59
60 template<class _Ty>
61 struct promise_t<_Ty&> final : public promise_impl_t<_Ty&>
62 {
63 using typename promise_impl_t<_Ty&>::value_type;
64 using promise_impl_t<_Ty&>::get_return_object;
65
66 void return_value(_Ty& val); //co_return val
67 suspend_always yield_value(_Ty& val);
68 };
69
70 template<>
71 struct promise_t<void> final : public promise_impl_t<void>
72 {
73 using promise_impl_t<void>::get_return_object;
74
75 void return_void(); //co_return;
76 suspend_always yield_value();
77 };
78 #endif //DOXYGEN_SKIP_PROPERTY
79 }
80
81 #pragma pop_macro("new")