aboutsummaryrefslogtreecommitdiff
path: root/src/DI/factory.tpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DI/factory.tpp')
-rw-r--r--src/DI/factory.tpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/DI/factory.tpp b/src/DI/factory.tpp
new file mode 100644
index 0000000..38b9c00
--- /dev/null
+++ b/src/DI/factory.tpp
@@ -0,0 +1,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>();
+}