aboutsummaryrefslogtreecommitdiff
path: root/src/DI/factory.tpp
blob: 38b9c00f3883847183f7e7a4544a6f26108dda4f (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
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include "factory.hpp"

template <class Return, class... Args>
Factory<Return(Args...)>::Factory(const Factory &factory) : _functor(factory._functor)
{
}

template <class Return, class... Args>
Factory<Return(Args...)>::Factory(Factory &&factory) noexcept
	: _functor(std::move(factory._functor))
{
}

template <class Return, class... Args>
auto Factory<Return(Args...)>::operator=(Factory &&factory) noexcept
	-> Factory<Return(Args...)> &
{
	_functor = std::move(factory._functor);
	return *this;
}

template <class Return, class... Args>
auto Factory<Return(Args...)>::operator=(std::nullptr_t) noexcept
	-> Factory<Return(Args...)> &
{
	_functor = nullptr;
	return *this;
}

template <class Return, class... Args>
Factory<Return(Args...)>::~Factory() = default;

template <class Return, class... Args>
Factory<Return(Args...)>::operator bool() const noexcept
{
	return static_cast<bool>(_functor);
}

template <class Return, class... Args>
auto Factory<Return(Args...)>::operator()(Args... args) const -> Return
{
	return _functor(std::forward<Args>(args)...);
}

template <class Return, class... Args>
auto Factory<Return(Args...)>::target_type() const noexcept -> const std::type_info &
{
	return _functor.target_type();
}

template <class Return, class... Args>
template <typename Tp>
auto Factory<Return(Args...)>::target() noexcept -> Tp *
{
	return static_cast<Tp *>(_functor.template target<Tp>());
}

template <class Return, class... Args>
template <typename Tp>
auto Factory<Return(Args...)>::target() const noexcept -> const Tp *
{
	return _functor.template target<Tp>();
}