forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_includes.h
More file actions
149 lines (122 loc) · 3.24 KB
/
Copy pathbase_includes.h
File metadata and controls
149 lines (122 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <algorithm>
#include <array>
#include <atomic>
#include <charconv>
#include <chrono>
#include <cstddef>
#include <iterator>
#include <map>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string_view>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#if __has_include(<WindowsNumerics.impl.h>)
#define WINRT_IMPL_NUMERICS
#include <directxmath.h>
#endif
#ifndef __clang__
#include <experimental/coroutine>
#else
namespace std::experimental
{
template <typename R, typename...> struct coroutine_traits
{
using promise_type = typename R::promise_type;
};
template <typename Promise = void> struct coroutine_handle;
template <> struct coroutine_handle<void>
{
coroutine_handle(decltype(nullptr)) noexcept
{
}
coroutine_handle() noexcept
{
}
static coroutine_handle from_address(void* address) noexcept
{
coroutine_handle result;
result.ptr = address;
return result;
}
coroutine_handle& operator=(decltype(nullptr)) noexcept
{
ptr = nullptr;
return *this;
}
explicit operator bool() const noexcept
{
return ptr;
}
void* address() const noexcept
{
return ptr;
}
void operator()() const
{
resume();
}
void resume() const
{
__builtin_coro_resume(ptr);
}
void destroy() const
{
__builtin_coro_destroy(ptr);
}
bool done() const
{
return __builtin_coro_done(ptr);
}
protected:
void* ptr{};
};
template <typename Promise> struct coroutine_handle : coroutine_handle<>
{
using coroutine_handle<>::operator=;
static coroutine_handle from_address(void* address) noexcept
{
coroutine_handle result;
result.ptr = address;
return result;
}
Promise& promise() const
{
return *reinterpret_cast<Promise*>(__builtin_coro_promise(ptr, alignof(Promise), false));
}
static coroutine_handle from_promise(Promise& promise)
{
coroutine_handle result;
result.ptr = __builtin_coro_promise(&promise, alignof(Promise), true);
return result;
}
};
template <typename Promise>
bool operator==(coroutine_handle<Promise> const& left, coroutine_handle<Promise> const& right) noexcept
{
return left.address() == right.address();
}
template <typename Promise>
bool operator!=(coroutine_handle<Promise> const& left, coroutine_handle<Promise> const& right) noexcept
{
return !(left == right);
}
struct suspend_always
{
bool await_ready() noexcept { return false; }
void await_suspend(coroutine_handle<>) noexcept {}
void await_resume() noexcept {}
};
struct suspend_never
{
bool await_ready() noexcept { return true; }
void await_suspend(coroutine_handle<>) noexcept {}
void await_resume() noexcept {}
};
}
#endif