|
3 | 3 | #include <optional> |
4 | 4 | #include <coio/detail/concepts.h> |
5 | 5 | #include <coio/detail/execution.h> |
| 6 | +#include <coio/utils/new_object.h> |
6 | 7 | #include <coio/utils/retain_ptr.h> |
7 | 8 | #include <coio/utils/scope_exit.h> |
8 | 9 |
|
@@ -66,10 +67,7 @@ namespace coio { |
66 | 67 | } |
67 | 68 |
|
68 | 69 | auto delete_self() noexcept -> void override { |
69 | | - using alloc_t = std::allocator_traits<allocator_t>::template rebind_alloc<state_proxy>; |
70 | | - alloc_t al(std::move(alloc)); |
71 | | - std::allocator_traits<alloc_t>::destroy(al, this); |
72 | | - std::allocator_traits<alloc_t>::deallocate(al, this, 1); |
| 70 | + coio::delete_object(alloc, this); |
73 | 71 | } |
74 | 72 |
|
75 | 73 | allocator_t alloc; |
@@ -99,11 +97,7 @@ namespace coio { |
99 | 97 | } |
100 | 98 | else { |
101 | 99 | auto alloc = detail::get_suitable_allocator(execution::get_env(sndr)); |
102 | | - using alloc_t = std::allocator_traits<decltype(alloc)>::template rebind_alloc<state_proxy<Sndr, false>>; |
103 | | - alloc_t al(std::move(alloc)); |
104 | | - auto ptr = std::allocator_traits<alloc_t>::allocate(al, 1); |
105 | | - std::allocator_traits<alloc_t>::construct(al, ptr, std::move(sndr), std::move(rcvr)); |
106 | | - proxy = ptr; |
| 100 | + proxy = coio::new_object<state_proxy<Sndr, false>>(alloc, std::move(sndr), std::move(rcvr)); |
107 | 101 | } |
108 | 102 | } |
109 | 103 |
|
@@ -251,22 +245,17 @@ namespace coio { |
251 | 245 | explicit backend_for(Sched sched, Alloc alloc) noexcept : base(std::move(sched)), alloc(std::move(alloc)) {} |
252 | 246 |
|
253 | 247 | auto do_lose() noexcept -> void override { |
254 | | - using alloc_t = std::allocator_traits<Alloc>::template rebind_alloc<backend_for>; |
255 | | - alloc_t al(std::move(alloc)); |
256 | | - std::allocator_traits<alloc_t>::destroy(al, this); |
257 | | - std::allocator_traits<alloc_t>::deallocate(al, this, 1); |
| 248 | + coio::delete_object(alloc, this); |
258 | 249 | } |
259 | 250 |
|
260 | 251 | COIO_NO_UNIQUE_ADDRESS Alloc alloc; |
261 | 252 | }; |
262 | 253 |
|
263 | 254 | template<typename Sched, typename Alloc> |
264 | 255 | static auto create_backend(Sched sched, Alloc alloc) -> retain_ptr<backend> { |
265 | | - using alloc_t = std::allocator_traits<Alloc>::template rebind_alloc<backend_for<Sched, Alloc>>; |
266 | | - alloc_t al(alloc); |
267 | | - auto ptr = std::allocator_traits<alloc_t>::allocate(al, 1); |
268 | | - std::allocator_traits<alloc_t>::construct(al, ptr, std::move(sched), std::move(alloc)); |
269 | | - return retain_ptr<backend>(ptr); |
| 256 | + return retain_ptr<backend>{ |
| 257 | + coio::new_object<backend_for<Sched, Alloc>>(alloc, std::move(sched), std::move(alloc)) |
| 258 | + }; |
270 | 259 | } |
271 | 260 |
|
272 | 261 | public: |
|
0 commit comments