diff options
Diffstat (limited to 'include/yacppdic/detail/factory-impl.hpp')
-rw-r--r-- | include/yacppdic/detail/factory-impl.hpp | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/include/yacppdic/detail/factory-impl.hpp b/include/yacppdic/detail/factory-impl.hpp index 3deede2..c6da207 100644 --- a/include/yacppdic/detail/factory-impl.hpp +++ b/include/yacppdic/detail/factory-impl.hpp @@ -5,18 +5,19 @@ namespace yacppdic { -template <class Return, class... Args> -Factory<Return(Args...)>::Factory(const Factory &factory) : _functor(factory._functor) +template <typename Return, typename... Args> +Factory<Return(Args...)>::Factory(const Factory &factory) noexcept + : _functor(factory._functor) { } -template <class Return, class... Args> +template <typename Return, typename... Args> Factory<Return(Args...)>::Factory(Factory &&factory) noexcept : _functor(std::move(factory._functor)) { } -template <class Return, class... Args> +template <typename Return, typename... Args> auto Factory<Return(Args...)>::operator=(Factory &&factory) noexcept -> Factory<Return(Args...)> & { @@ -24,7 +25,7 @@ auto Factory<Return(Args...)>::operator=(Factory &&factory) noexcept return *this; } -template <class Return, class... Args> +template <typename Return, typename... Args> auto Factory<Return(Args...)>::operator=(std::nullptr_t) noexcept -> Factory<Return(Args...)> & { @@ -32,39 +33,88 @@ auto Factory<Return(Args...)>::operator=(std::nullptr_t) noexcept return *this; } -template <class Return, class... Args> -Factory<Return(Args...)>::~Factory() = default; - -template <class Return, class... Args> +template <typename Return, typename... 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 +template <typename Return, typename... Args> +auto Factory<Return(Args...)>::operator()(Args... args) const noexcept -> Return { return _functor(std::forward<Args>(args)...); } -template <class Return, class... Args> +template <typename Return, typename... Args> auto Factory<Return(Args...)>::target_type() const noexcept -> const std::type_info & { return _functor.target_type(); } -template <class Return, class... Args> +template <typename Return, typename... 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 Return, typename... Args> template <typename Tp> auto Factory<Return(Args...)>::target() const noexcept -> const Tp * { return _functor.template target<Tp>(); } +template <typename Return, typename... Args> +inline auto operator==(const Factory<Return(Args...)> &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 +{ + return !factory; +} + +template <typename Return, typename... Args> +inline auto operator!=(const Factory<Return(Args...)> &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 +{ + return static_cast<bool>(factory); +} + +} // namespace yacppdic + +template <typename Function> +constexpr auto not_null(Function const & /*unused*/) -> bool +{ + return true; +} + +template <typename Function> +constexpr auto not_null(Function *function_ptr) -> bool +{ + return function_ptr; +} + +template <typename Return, typename Class> +constexpr auto not_null(Return Class::*method_ptr) -> bool +{ + return method_ptr; +} + +template <typename Function> +constexpr auto not_null(yacppdic::Factory<Function> const &factory) -> bool +{ + return !!factory; } |