aboutsummaryrefslogtreecommitdiff
path: root/include/yacppdic/detail/internal/functor/copyable_functor.hpp
blob: 335078192c7f69c5c3f0200562de592f3275000b (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
48
49
50
51
52
53
#pragma once

#include "yacppdic/detail/internal/interfaces/copyable_functor.hpp"

#include "yacppdic/detail/internal/functor/alloc_functor.hpp"

#include <typeinfo>

namespace yacppdic::internal
{

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

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

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

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

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

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

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

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

	void destroy() noexcept override;

	void destroy_deallocate() noexcept override;

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

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

} // namespace yacppdic::internal

#include "copyable_functor-impl.hpp"