YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
helper.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstddef>
8
9namespace yaclib {
10namespace detail {
11
12template <template <typename...> typename Counter, typename ObjectT>
13class Helper final : public Counter<ObjectT, DefaultDeleter> {
14 public:
16
18 this->Add(1);
19 }
20
22 this->Sub(1);
23 }
24
26 return this->Get();
27 }
28};
29
30} // namespace detail
31
32template <typename ObjectT, typename... Args>
33auto MakeUnique(Args&&... args) {
34 return IntrusivePtr{NoRefTag{}, new detail::Helper<detail::OneCounter, ObjectT>{0, std::forward<Args>(args)...}};
35}
36
37template <typename ObjectT, typename... Args>
38auto MakeShared(std::size_t n, Args&&... args) {
39 return IntrusivePtr{NoRefTag{}, new detail::Helper<detail::AtomicCounter, ObjectT>{n, std::forward<Args>(args)...}};
40}
41
42} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
size_t GetRef() noexcept final
Definition helper.hpp:25
void DecRef() noexcept final
Definition helper.hpp:21
void IncRef() noexcept final
Definition helper.hpp:17
auto MakeUnique(Args &&... args)
Definition helper.hpp:33
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
auto MakeShared(std::size_t n, Args &&... args)
Definition helper.hpp:38