diff options
author | HampusM <hampus@hampusmat.com> | 2022-04-30 16:28:13 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:58 +0200 |
commit | 40d02748924aa7c48b04cf948204d8dacdfbbc74 (patch) | |
tree | 4d07a3703207295799b02cef52618a8f0c820542 /src/DI/copyable_functor.tpp | |
parent | db6edcd473a684420e9a7611b24462df21165c1b (diff) |
refactor: replace DI files with the yacppdic library
Diffstat (limited to 'src/DI/copyable_functor.tpp')
-rw-r--r-- | src/DI/copyable_functor.tpp | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/src/DI/copyable_functor.tpp b/src/DI/copyable_functor.tpp deleted file mode 100644 index d8da3bb..0000000 --- a/src/DI/copyable_functor.tpp +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -#include "copyable_functor.hpp" - -#include <memory> -#include <utility> - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define COPYABLE_FUNCTOR_TEMPLATE \ - template <class Function, class Allocator, class Return, class... Args> - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define COPYABLE_FUNCTOR CopyableFunctor<Function, Allocator, Return(Args...)> - -COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(Function &&function) : _functor(std::move(function)) {} - -COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(const Function &function, const Allocator &allocator) - : _functor(function, allocator) -{ -} - -COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(const Function &function, Allocator &&allocator) - : _functor(function, std::move(allocator)) -{ -} - -COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(Function &&function, Allocator &&allocator) - : _functor(std::move(function), std::move(allocator)) -{ -} - -COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::operator()(Args &&...args) -> Return -{ - return _functor(std::forward<Args>(args)...); -} - -COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor<Return(Args...)> * -{ - using AllocTraits = std::allocator_traits<Allocator>; - - using AllocHelper = typename RebindAllocHelper<AllocTraits, CopyableFunctor>::type; - - auto alloc_helper = AllocHelper(_functor.get_allocator()); - - using Destructor = AllocDestructor<AllocHelper>; - - auto hold = std::unique_ptr<CopyableFunctor, Destructor>( - alloc_helper.allocate(1), - Destructor(alloc_helper, 1) - ); - - ::new (static_cast<void *>(hold.get())) - CopyableFunctor(_functor.target(), Allocator(alloc_helper)); - - return hold.release(); -} - -COPYABLE_FUNCTOR_TEMPLATE -void COPYABLE_FUNCTOR::clone(ICopyableFunctor<Return(Args...)> *functor) const -{ - ::new (static_cast<void *>(functor)) - CopyableFunctor(_functor.target(), _functor.get_allocator()); -} - -COPYABLE_FUNCTOR_TEMPLATE -void COPYABLE_FUNCTOR::destroy() noexcept -{ - _functor.destroy(); -} - -COPYABLE_FUNCTOR_TEMPLATE -void COPYABLE_FUNCTOR::destroy_deallocate() noexcept -{ - using AllocTraits = std::allocator_traits<Allocator>; - - using AllocHelper = typename RebindAllocHelper<AllocTraits, CopyableFunctor>::type; - - auto alloc_helper = AllocHelper(_functor.get_allocator()); - - _functor.destroy(); - - alloc_helper.deallocate(this, 1); -} - -COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::target(const std::type_info &type_info) const noexcept -> const - void * -{ - if (type_info == typeid(Function)) - { - return std::addressof(_functor.target()); - } - - return nullptr; -} - -COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::target_type() const noexcept -> const std::type_info & -{ - return typeid(Function); -} |