-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathhash_coroutine_handle.cpp
More file actions
65 lines (46 loc) · 1.38 KB
/
hash_coroutine_handle.cpp
File metadata and controls
65 lines (46 loc) · 1.38 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
// Copyright 2023 Christian Mazakas.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/config.hpp>
#if defined(BOOST_NO_CXX20_HDR_COROUTINE)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE(
"hash_coroutine_handle test requires C++20 and <coroutine> support")
int main() {}
#else
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <coroutine>
struct promise;
struct task : std::coroutine_handle<promise> {
using promise_type = ::promise;
};
struct promise {
task get_return_object() { return {task::from_promise(*this)}; }
void return_void() {}
void unhandled_exception() {}
std::suspend_always initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
};
task make_task() { co_return; }
namespace {
void coroutine_handle_tests() {
task t = make_task();
void *p = t.address();
{
auto h = boost::hash<std::coroutine_handle<promise>>()(t);
BOOST_TEST_EQ(h, boost::hash<void *>()(p));
}
std::coroutine_handle<> t2 = t;
{
auto h = boost::hash<std::coroutine_handle<>>()(t2);
BOOST_TEST_EQ(h, boost::hash<void *>()(p));
}
t.destroy();
}
} // namespace
int main() {
coroutine_handle_tests();
return boost::report_errors();
}
#endif