diff options
Diffstat (limited to 'include/yacppdic/detail/factory-impl.hpp')
-rw-r--r-- | include/yacppdic/detail/factory-impl.hpp | 89 |
1 files changed, 37 insertions, 52 deletions
diff --git a/include/yacppdic/detail/factory-impl.hpp b/include/yacppdic/detail/factory-impl.hpp index c6da207..8ba1234 100644 --- a/include/yacppdic/detail/factory-impl.hpp +++ b/include/yacppdic/detail/factory-impl.hpp @@ -5,90 +5,75 @@ namespace yacppdic { -template <typename Return, typename... Args> -Factory<Return(Args...)>::Factory(const Factory &factory) noexcept +template <typename Product, typename... Params> +Factory<Product(Params...)>::Factory(std::nullptr_t) noexcept +{ +} + +template <typename Product, typename... Params> +Factory<Product(Params...)>::Factory(const Factory &factory) noexcept : _functor(factory._functor) { } -template <typename Return, typename... Args> -Factory<Return(Args...)>::Factory(Factory &&factory) noexcept +template <typename Product, typename... Params> +Factory<Product(Params...)>::Factory(Factory &&factory) noexcept : _functor(std::move(factory._functor)) { } -template <typename Return, typename... Args> -auto Factory<Return(Args...)>::operator=(Factory &&factory) noexcept - -> Factory<Return(Args...)> & +template <typename Product, typename... Params> +auto Factory<Product(Params...)>::operator=(Factory &&factory) noexcept + -> Factory<Product(Params...)> & { _functor = std::move(factory._functor); return *this; } -template <typename Return, typename... Args> -auto Factory<Return(Args...)>::operator=(std::nullptr_t) noexcept - -> Factory<Return(Args...)> & +template <typename Product, typename... Params> +auto Factory<Product(Params...)>::operator=(std::nullptr_t) noexcept + -> Factory<Product(Params...)> & { _functor = nullptr; return *this; } -template <typename Return, typename... Args> -Factory<Return(Args...)>::operator bool() const noexcept +template <typename Product, typename... Params> +Factory<Product(Params...)>::operator bool() const noexcept { return static_cast<bool>(_functor); } -template <typename Return, typename... Args> -auto Factory<Return(Args...)>::operator()(Args... args) const noexcept -> Return -{ - return _functor(std::forward<Args>(args)...); -} - -template <typename Return, typename... Args> -auto Factory<Return(Args...)>::target_type() const noexcept -> const std::type_info & -{ - return _functor.target_type(); -} - -template <typename Return, typename... Args> -template <typename Tp> -auto Factory<Return(Args...)>::target() noexcept -> Tp * -{ - return static_cast<Tp *>(_functor.template target<Tp>()); -} - -template <typename Return, typename... Args> -template <typename Tp> -auto Factory<Return(Args...)>::target() const noexcept -> const Tp * +template <typename Product, typename... Params> +auto Factory<Product(Params...)>::operator()(Params... args) const noexcept -> Product { - return _functor.template target<Tp>(); + return _functor(std::forward<Params>(args)...); } -template <typename Return, typename... Args> -inline auto operator==(const Factory<Return(Args...)> &factory, std::nullptr_t) noexcept - -> bool +template <typename Product, typename... Params> +inline auto +operator==(const Factory<Product(Params...)> &factory, std::nullptr_t) noexcept -> bool { return !factory; } -template <typename Return, typename... Args> -inline auto operator==(std::nullptr_t, const Factory<Return(Args...)> &factory) noexcept - -> bool +template <typename Product, typename... Params> +inline auto +operator==(std::nullptr_t, const Factory<Product(Params...)> &factory) noexcept -> bool { return !factory; } -template <typename Return, typename... Args> -inline auto operator!=(const Factory<Return(Args...)> &factory, std::nullptr_t) noexcept - -> bool +template <typename Product, typename... Params> +inline auto +operator!=(const Factory<Product(Params...)> &factory, std::nullptr_t) noexcept -> bool { return static_cast<bool>(factory); } -template <typename Return, typename... Args> -inline auto operator!=(std::nullptr_t, const Factory<Return(Args...)> &factory) noexcept - -> bool +template <typename Product, typename... Params> +inline auto +operator!=(std::nullptr_t, const Factory<Product(Params...)> &factory) noexcept -> bool { return static_cast<bool>(factory); } @@ -96,25 +81,25 @@ inline auto operator!=(std::nullptr_t, const Factory<Return(Args...)> &factory) } // namespace yacppdic template <typename Function> -constexpr auto not_null(Function const & /*unused*/) -> bool +constexpr auto not_null(Function const & /*unused*/) noexcept -> bool { return true; } template <typename Function> -constexpr auto not_null(Function *function_ptr) -> bool +constexpr auto not_null(Function *function_ptr) noexcept -> bool { return function_ptr; } -template <typename Return, typename Class> -constexpr auto not_null(Return Class::*method_ptr) -> bool +template <typename Product, typename Class> +constexpr auto not_null(Product Class::*method_ptr) noexcept -> bool { return method_ptr; } template <typename Function> -constexpr auto not_null(yacppdic::Factory<Function> const &factory) -> bool +constexpr auto not_null(yacppdic::Factory<Function> const &factory) noexcept -> bool { return !!factory; } |