-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsuspend_never.cpp
More file actions
39 lines (35 loc) · 1.22 KB
/
suspend_never.cpp
File metadata and controls
39 lines (35 loc) · 1.22 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
#ifdef BEMAN_HAS_IMPORT_STD
import std;
#else
#include <coroutine>
#include <iostream>
#include <new>
#include <memory>
#endif
#include <beman/execution/execution.hpp>
namespace ex = beman::execution;
void* operator new(std::size_t n) {
auto p = std::malloc(n);
std::cout << "global new(" << n << ")->" << p << "\n";
return p;
}
void operator delete(void* ptr) noexcept {
std::cout << "global operator delete()" << ptr << "\n";
std::free(ptr);
}
int main() {
struct resource : std::pmr::memory_resource {
void* do_allocate(std::size_t n, std::size_t a) override {
auto p{std::malloc(n)};
std::cout << "resource::allocate(" << n << ", " << a << ") -> " << p << "\n";
return p;
}
void do_deallocate(void* p, std::size_t n, std::size_t a) override {
std::cout << "resource::deallocate(" << p << ", " << n << ", " << a << ")\n";
std::free(p);
}
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; }
} res{};
ex::sync_wait(ex::write_env(
std::suspend_never(), ex::env{ex::prop{ex::get_allocator, std::pmr::polymorphic_allocator<std::byte>(&res)}}));
}