aboutsummaryrefslogtreecommitdiff
path: root/src/DI/copyable_functor.hpp
blob: 905da034262297f22b3951de4eb8613160ca7284 (plain)
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
40
41
42
43
44
45
46
47
#pragma once

#include "DI/interfaces/copyable_functor.hpp"

#include "DI/alloc_functor.hpp"

#include <typeinfo>

/**
 * A copyable function object.
 */
template <class Function, class Allocator, class FunctionSignature>
class CopyableFunctor;

template <class Function, class Allocator, class Return, class... Args>
class CopyableFunctor<Function, Allocator, Return(Args...)>
	: public ICopyableFunctor<Return(Args...)>
{
public:
	explicit CopyableFunctor(Function &&function);

	explicit CopyableFunctor(const Function &function, const Allocator &allocator);

	explicit CopyableFunctor(const Function &function, Allocator &&allocator);

	explicit CopyableFunctor(Function &&function, Allocator &&allocator);

	auto operator()(Args &&...args) -> Return override;

	auto clone() const -> ICopyableFunctor<Return(Args...)> * override;

	void clone(ICopyableFunctor<Return(Args...)> *functor) const override;

	void destroy() noexcept override;

	void destroy_deallocate() noexcept override;

	[[nodiscard]] auto target(const std::type_info &type_info) const noexcept -> const
		void * override;

	[[nodiscard]] auto target_type() const noexcept -> const std::type_info & override;

private:
	AllocFunctor<Function, Allocator, Return(Args...)> _functor;
};

#include "copyable_functor.tpp"