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
7namespace yaclib {
8namespace detail {
9
10template <template <typename...> typename Counter, typename ObjectT>
11class Helper final : public Counter<ObjectT, DefaultDeleter> {
12 public:
14
16 this->Add(1);
17 }
18
20 this->Sub(1);
21 }
22};
23
24} // namespace detail
25
26template <typename ObjectT, typename... Args>
27auto MakeUnique(Args&&... args) {
28 return IntrusivePtr{NoRefTag{}, new detail::Helper<detail::OneCounter, ObjectT>{0, std::forward<Args>(args)...}};
29}
30
31template <typename ObjectT, typename... Args>
32auto MakeShared(std::size_t n, Args&&... args) {
33 return IntrusivePtr{NoRefTag{}, new detail::Helper<detail::AtomicCounter, ObjectT>{n, std::forward<Args>(args)...}};
34}
35
36} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
void DecRef() noexcept final
Definition helper.hpp:19
void IncRef() noexcept final
Definition helper.hpp:15
auto MakeUnique(Args &&... args)
Definition helper.hpp:27
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
auto MakeShared(std::size_t n, Args &&... args)
Definition helper.hpp:32