diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-03 20:07:20 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-03 20:07:20 +0200 |
commit | b83e94a05efd4dc4d0836bbb59cb500d0c0b219a (patch) | |
tree | ff202daf99578a623559d2f37bc308232e559167 | |
parent | 376ef270b255256b4154eafaea3530ab01e7ccc5 (diff) |
refactor: clean up factory & compressed pair
-rw-r--r-- | include/yacppdic/detail/factory-impl.hpp | 78 | ||||
-rw-r--r-- | include/yacppdic/detail/internal/compressed_pair-impl.hpp | 98 | ||||
-rw-r--r-- | include/yacppdic/detail/internal/compressed_pair.hpp | 148 | ||||
-rw-r--r-- | include/yacppdic/detail/internal/factory_base.hpp | 24 | ||||
-rw-r--r-- | include/yacppdic/detail/internal/tuple_indices.hpp | 39 | ||||
-rw-r--r-- | include/yacppdic/factory.hpp | 133 |
6 files changed, 297 insertions, 223 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; } diff --git a/include/yacppdic/detail/internal/compressed_pair-impl.hpp b/include/yacppdic/detail/internal/compressed_pair-impl.hpp index 0e2a322..9a458e4 100644 --- a/include/yacppdic/detail/internal/compressed_pair-impl.hpp +++ b/include/yacppdic/detail/internal/compressed_pair-impl.hpp @@ -5,42 +5,94 @@ namespace yacppdic::internal { -template <class Value, int Idx> -constexpr CompressedPairElement<Value, Idx>::CompressedPairElement( - DefaultInitTag /*default_init_tag*/ -) +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +template <typename> +requires std::default_initializable<ValueOne> && std::default_initializable<ValueTwo> +constexpr CompressedPair<ValueOne, ValueTwo>::CompressedPair() noexcept + : BaseOne(ValueInitTag()), BaseTwo(ValueInitTag()) { } -template <class Value, int Idx> -constexpr CompressedPairElement<Value, Idx>::CompressedPairElement( - ValueInitTag /*value_init_tag*/ -) - : _value() +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +template <typename FirstValue, typename SecondValue> +constexpr CompressedPair<ValueOne, ValueTwo>::CompressedPair( + FirstValue &&first_value, + SecondValue &&second_value +) noexcept + : BaseOne(std::forward<FirstValue>(first_value)), + BaseTwo(std::forward<SecondValue>(second_value)) { } -template <class Value, int Idx> -template <class... Args, size_t... Indices> -constexpr CompressedPairElement<Value, Idx>::CompressedPairElement( - std::piecewise_construct_t /*tag_types*/, - std::tuple<Args...> args, - TupleIndices<Indices...> /*indices*/ -) - : _value(std::forward<Args>(std::get<Indices>(args))...) +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +template <typename... ArgsOne, typename... ArgsTwo> +constexpr CompressedPair<ValueOne, ValueTwo>::CompressedPair( + std::piecewise_construct_t piecewise_construct, + std::tuple<ArgsOne...> first_args, + std::tuple<ArgsTwo...> second_args +) noexcept + : BaseOne( + piecewise_construct, + std::move(first_args), + typename MakeTupleIndices<sizeof...(ArgsOne)>::type() + ), + BaseTwo( + piecewise_construct, + std::move(second_args), + typename MakeTupleIndices<sizeof...(ArgsTwo)>::type() + ) { } -template <class Value, int Idx> -auto CompressedPairElement<Value, Idx>::get() noexcept -> ValueReference +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +auto CompressedPair<ValueOne, ValueTwo>::first() noexcept -> + typename BaseOne::ValueReference { - return _value; + return static_cast<BaseOne &>(*this).get(); } -template <class Value, int Idx> -auto CompressedPairElement<Value, Idx>::get() const noexcept -> ConstValueReference +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +auto CompressedPair<ValueOne, ValueTwo>::first() const noexcept -> + typename BaseOne::ConstValueReference { - return _value; + return static_cast<BaseOne const &>(*this).get(); +} + +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +auto CompressedPair<ValueOne, ValueTwo>::second() noexcept -> + typename BaseTwo::ValueReference +{ + return static_cast<BaseTwo &>(*this).get(); +} + +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +auto CompressedPair<ValueOne, ValueTwo>::second() const noexcept -> + typename BaseTwo::ConstValueReference +{ + return static_cast<BaseTwo const &>(*this).get(); +} + +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +constexpr auto CompressedPair<ValueOne, ValueTwo>::get_first_base(CompressedPair *pair +) noexcept -> BaseOne * +{ + return static_cast<BaseOne *>(pair); +} + +template <typename ValueOne, typename ValueTwo> +requires NotSameAs<ValueOne, ValueTwo> +constexpr auto CompressedPair<ValueOne, ValueTwo>::get_second_base(CompressedPair *pair +) noexcept -> BaseTwo * +{ + return static_cast<BaseTwo *>(pair); } } // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/compressed_pair.hpp b/include/yacppdic/detail/internal/compressed_pair.hpp index 3c832c5..7d98bbd 100644 --- a/include/yacppdic/detail/internal/compressed_pair.hpp +++ b/include/yacppdic/detail/internal/compressed_pair.hpp @@ -1,6 +1,7 @@ #pragma once #include "yacppdic/detail/internal/misc_concepts.hpp" +#include "yacppdic/detail/internal/tuple_indices.hpp" #include <concepts> #include <tuple> @@ -11,104 +12,94 @@ namespace yacppdic::internal { // Tag used to default initialize one or both of the pair's elements. -struct DefaultInitTag +class DefaultInitTag { }; -struct ValueInitTag +class ValueInitTag { }; -template <size_t...> -struct TupleIndices -{ -}; - -template <class IdxType, IdxType... Values> -struct IntegerSequence -{ - template <template <class OIdxType, OIdxType...> class ToIndexSeq, class ToIndexType> - using Convert = ToIndexSeq<ToIndexType, Values...>; - - template <size_t Sp> - using ToTupleIndices = TupleIndices<(Values + Sp)...>; -}; - -template <size_t SizeOne, size_t SizeTwo> -using MakeIndices = - typename __make_integer_seq<IntegerSequence, size_t, SizeOne - SizeTwo>:: - template ToTupleIndices<SizeTwo>; - -template <size_t SizeOne, size_t SizeTwo = 0> -requires(SizeTwo <= SizeOne) struct MakeTupleIndices -{ - using type = MakeIndices<SizeOne, SizeTwo>; -}; - template <typename Value> concept ValueCanBeEmptyBase = std::is_empty_v<Value> && !std::is_final_v<Value>; -template <class Value, int Idx> +template <typename Value, int Idx> class CompressedPairElement { public: using ValueReference = Value &; using ConstValueReference = const Value &; - constexpr explicit CompressedPairElement(DefaultInitTag default_init_tag); + constexpr explicit CompressedPairElement(DefaultInitTag /*default_init_tag*/ + ) noexcept {}; - constexpr explicit CompressedPairElement(ValueInitTag value_init_tag); + constexpr explicit CompressedPairElement(ValueInitTag /*value_init_tag*/) noexcept + : _value() + { + } - template <class ElementValue> + template <typename ElementValue> requires std::same_as<CompressedPairElement, std::decay_t<ElementValue>> // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - constexpr explicit CompressedPairElement(ElementValue &&value) + constexpr explicit CompressedPairElement(ElementValue &&value) noexcept : _value(std::forward<ElementValue>(value)) { } - template <class... Args, size_t... Indices> + template <typename... Args, std::size_t... Indices> constexpr CompressedPairElement( - std::piecewise_construct_t tag_type, + std::piecewise_construct_t /*tag_type*/, std::tuple<Args...> args, - TupleIndices<Indices...> tuple_indices - ); + TupleIndices<Indices...> /*tuple_indices*/ + ) noexcept + : _value(std::forward<Args>(std::get<Indices>(args))...) + { + } - auto get() noexcept -> ValueReference; + auto get() noexcept -> ValueReference + { + return _value; + } - [[nodiscard]] auto get() const noexcept -> ConstValueReference; + [[nodiscard]] auto get() const noexcept -> ConstValueReference + { + return _value; + } private: Value _value; }; -template <class Value, int Idx> +template <typename Value, int Idx> requires ValueCanBeEmptyBase<Value> -struct CompressedPairElement<Value, Idx> : private Value +class CompressedPairElement<Value, Idx> : private Value { +public: using ValueReference = Value &; using ConstValueReference = const Value &; - constexpr CompressedPairElement() = default; + constexpr CompressedPairElement() noexcept = default; - constexpr explicit CompressedPairElement(DefaultInitTag /*unused*/) {} + constexpr explicit CompressedPairElement(DefaultInitTag /*unused*/) noexcept {} - constexpr explicit CompressedPairElement(ValueInitTag /*unused*/) : Value() {} + constexpr explicit CompressedPairElement(ValueInitTag /*unused*/) noexcept : Value() + { + } - template <class ElementValue> + template <typename ElementValue> requires std::same_as<CompressedPairElement, typename std::decay<ElementValue>::type> // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - constexpr explicit CompressedPairElement(ElementValue &&value) + constexpr explicit CompressedPairElement(ElementValue &&value) noexcept : Value(std::forward<ElementValue>(value)) { } - template <class... Args, size_t... Indices> + template <typename... Args, std::size_t... Indices> constexpr CompressedPairElement( std::piecewise_construct_t /*unused*/, std::tuple<Args...> args, TupleIndices<Indices...> /*unused*/ - ) + ) noexcept : Value(std::forward<Args>(std::get<Indices>(args))...) { } @@ -124,7 +115,7 @@ struct CompressedPairElement<Value, Idx> : private Value } }; -template <class ValueOne, class ValueTwo> +template <typename ValueOne, typename ValueTwo> requires NotSameAs<ValueOne, ValueTwo> class CompressedPair : private CompressedPairElement<ValueOne, 0>, private CompressedPairElement<ValueTwo, 1> @@ -135,63 +126,32 @@ public: template <typename> requires std::default_initializable<ValueOne> && std::default_initializable<ValueTwo> - constexpr CompressedPair() : BaseOne(ValueInitTag()), BaseTwo(ValueInitTag()) {} + constexpr CompressedPair() noexcept; - template <class FirstValue, class SecondValue> - constexpr CompressedPair(FirstValue &&first_value, SecondValue &&second_value) - : BaseOne(std::forward<FirstValue>(first_value)), - BaseTwo(std::forward<SecondValue>(second_value)) - { - } + template <typename FirstValue, typename SecondValue> + constexpr CompressedPair( + FirstValue &&first_value, + SecondValue &&second_value + ) noexcept; - template <class... ArgsOne, class... ArgsTwo> + template <typename... ArgsOne, typename... ArgsTwo> constexpr CompressedPair( std::piecewise_construct_t piecewise_construct, std::tuple<ArgsOne...> first_args, std::tuple<ArgsTwo...> second_args - ) - : BaseOne( - piecewise_construct, - std::move(first_args), - typename MakeTupleIndices<sizeof...(ArgsOne)>::type() - ), - BaseTwo( - piecewise_construct, - std::move(second_args), - typename MakeTupleIndices<sizeof...(ArgsTwo)>::type() - ) - { - } + ) noexcept; - auto first() noexcept -> typename BaseOne::ValueReference - { - return static_cast<BaseOne &>(*this).get(); - } + auto first() noexcept -> typename BaseOne::ValueReference; - [[nodiscard]] auto first() const noexcept -> typename BaseOne::ConstValueReference - { - return static_cast<BaseOne const &>(*this).get(); - } + [[nodiscard]] auto first() const noexcept -> typename BaseOne::ConstValueReference; - auto second() noexcept -> typename BaseTwo::ValueReference - { - return static_cast<BaseTwo &>(*this).get(); - } + auto second() noexcept -> typename BaseTwo::ValueReference; - [[nodiscard]] auto second() const noexcept -> typename BaseTwo::ConstValueReference - { - return static_cast<BaseTwo const &>(*this).get(); - } + [[nodiscard]] auto second() const noexcept -> typename BaseTwo::ConstValueReference; - constexpr static auto get_first_base(CompressedPair *pair) noexcept -> BaseOne * - { - return static_cast<BaseOne *>(pair); - } + constexpr static auto get_first_base(CompressedPair *pair) noexcept -> BaseOne *; - constexpr static auto get_second_base(CompressedPair *pair) noexcept -> BaseTwo * - { - return static_cast<BaseTwo *>(pair); - } + constexpr static auto get_second_base(CompressedPair *pair) noexcept -> BaseTwo *; }; } // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/factory_base.hpp b/include/yacppdic/detail/internal/factory_base.hpp new file mode 100644 index 0000000..00c4e4f --- /dev/null +++ b/include/yacppdic/detail/internal/factory_base.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <functional> + +template <class Return> +class MaybeDeriveFromUnaryFunction +{ +}; + +template <class Return, class Arg> +class MaybeDeriveFromUnaryFunction<Return(Arg)> : public std::unary_function<Arg, Return> +{ +}; + +template <class Return> +struct MaybeDeriveFromBinaryFunction +{ +}; + +template <class Return, class ArgOne, class ArgTwo> +struct MaybeDeriveFromBinaryFunction<Return(ArgOne, ArgTwo)> + : public std::binary_function<ArgOne, ArgTwo, Return> +{ +}; diff --git a/include/yacppdic/detail/internal/tuple_indices.hpp b/include/yacppdic/detail/internal/tuple_indices.hpp new file mode 100644 index 0000000..3a367b6 --- /dev/null +++ b/include/yacppdic/detail/internal/tuple_indices.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include <cstddef> + +namespace yacppdic::internal +{ + +template <std::size_t...> +class TupleIndices +{ +}; + +template <typename IdxType, IdxType... Values> +class IntegerSequence +{ +public: + template < + template <typename OIdxType, OIdxType...> + typename ToIndexSeq, + typename ToIndexType> + using Convert = ToIndexSeq<ToIndexType, Values...>; + + template <std::size_t Sp> + using ToTupleIndices = TupleIndices<(Values + Sp)...>; +}; + +template <std::size_t SizeOne, std::size_t SizeTwo> +using MakeIndices = + typename __make_integer_seq<IntegerSequence, std::size_t, SizeOne - SizeTwo>:: + template ToTupleIndices<SizeTwo>; + +template <std::size_t SizeOne, std::size_t SizeTwo = 0> +requires(SizeTwo <= SizeOne) class MakeTupleIndices +{ +public: + using type = MakeIndices<SizeOne, SizeTwo>; +}; + +} // namespace yacppdic::internal diff --git a/include/yacppdic/factory.hpp b/include/yacppdic/factory.hpp index 6de47d8..1eb2dc7 100644 --- a/include/yacppdic/factory.hpp +++ b/include/yacppdic/factory.hpp @@ -3,6 +3,7 @@ #include "yacppdic/detail/internal/interfaces/copyable_functor.hpp" #include "yacppdic/detail/internal/alloc_destructor.hpp" +#include "yacppdic/detail/internal/factory_base.hpp" #include "yacppdic/detail/internal/functor/alloc_functor.hpp" #include "yacppdic/detail/internal/functor/copyable_functor.hpp" #include "yacppdic/detail/internal/functor/value_functor.hpp" @@ -16,62 +17,9 @@ namespace yacppdic { -template <class> +template <typename> class Factory; -} - -template <class Function> -auto not_null(Function const & /*unused*/) -> bool -{ - return true; -} - -template <class Function> -auto not_null(Function *function_ptr) -> bool -{ - return function_ptr; -} - -template <class Return, class Class> -auto not_null(Return Class::*method_ptr) -> bool -{ - return method_ptr; -} - -template <class Function> -auto not_null(yacppdic::Factory<Function> const &factory) -> bool -{ - return !!factory; -} - -namespace yacppdic -{ - -template <class Return> -// NOLINTNEXTLINE(readability-identifier-naming) -struct maybe_derive_from_unary_function -{ -}; - -template <class Return, class Arg> -struct maybe_derive_from_unary_function<Return(Arg)> - : public std::unary_function<Arg, Return> -{ -}; - -template <class Return> -// NOLINTNEXTLINE(readability-identifier-naming) -struct maybe_derive_from_binary_function -{ -}; - -template <class Return, class ArgOne, class ArgTwo> -struct maybe_derive_from_binary_function<Return(ArgOne, ArgTwo)> - : public std::binary_function<ArgOne, ArgTwo, Return> -{ -}; - template <typename Function, typename Return, typename... Args> concept Callable = !std::is_same_v< @@ -80,9 +28,9 @@ concept Callable = std::is_invocable_v<Function, Args...> && internal::IsCoreConvertibleV<std::invoke_result_t<Function, Args...>, Return>; -template <class Return, class... Args> -class Factory<Return(Args...)> : public maybe_derive_from_unary_function<Return(Args...)>, - public maybe_derive_from_binary_function<Return(Args...)> +template <typename Return, typename... Args> +class Factory<Return(Args...)> : public MaybeDeriveFromUnaryFunction<Return(Args...)>, + public MaybeDeriveFromBinaryFunction<Return(Args...)> { public: using Result = Return; @@ -91,35 +39,36 @@ public: explicit Factory(std::nullptr_t) noexcept {} - Factory(const Factory &factory); + Factory(const Factory &factory) noexcept; Factory(Factory &&factory) noexcept; - template <class Function> + template <typename Function> requires Callable<Function, Return, Args...> // NOLINTNEXTLINE(google-explicit-constructor) - Factory(Function function) : _functor(std::move(function)) - { - } + Factory(Function function) + noexcept : _functor(std::move(function)) {} - auto operator=(const Factory &factory) = delete; + auto operator=(const Factory &factory) noexcept = delete; auto operator=(Factory &&factory) noexcept -> Factory &; auto operator=(std::nullptr_t) noexcept -> Factory &; - ~Factory(); + ~Factory() noexcept = default; explicit operator bool() const noexcept; // deleted overloads close possible hole in the type system - template <class RhsReturn, class... RhsArgs> - auto operator==(const Factory<RhsReturn(RhsArgs...)> &) const -> bool = delete; + template <typename RhsReturn, typename... RhsArgs> + auto operator==(const Factory<RhsReturn(RhsArgs...)> &) const noexcept + -> bool = delete; - template <class RhsReturn, class... RhsArgs> - auto operator!=(const Factory<RhsReturn(RhsArgs...)> &) const -> bool = delete; + template <typename RhsReturn, typename... RhsArgs> + auto operator!=(const Factory<RhsReturn(RhsArgs...)> &) const noexcept + -> bool = delete; - auto operator()(Args... args) const -> Return; + auto operator()(Args... args) const noexcept -> Return; [[nodiscard]] auto target_type() const noexcept -> const std::type_info &; @@ -135,42 +84,42 @@ private: ValFunctor _functor; }; -template <class Return, class... Args> +template <typename Return, typename... Args> Factory(Return (*)(Args...)) -> Factory<Return(Args...)>; template < - class Function, - class Stripped = internal::StripSignatureT<decltype(&Function::operator())>> + typename Function, + typename Stripped = internal::StripSignatureT<decltype(&Function::operator())>> Factory(Function) -> Factory<Stripped>; -template <class Return, class... Args> +template <typename Return, typename... Args> inline auto operator==(const Factory<Return(Args...)> &factory, std::nullptr_t) noexcept - -> bool -{ - return !factory; -} + -> bool; -template <class Return, class... Args> +template <typename Return, typename... Args> inline auto operator==(std::nullptr_t, const Factory<Return(Args...)> &factory) noexcept - -> bool -{ - return !factory; -} + -> bool; -template <class Return, class... Args> +template <typename Return, typename... Args> inline auto operator!=(const Factory<Return(Args...)> &factory, std::nullptr_t) noexcept - -> bool -{ - return static_cast<bool>(factory); -} + -> bool; -template <class Return, class... Args> +template <typename Return, typename... Args> inline auto operator!=(std::nullptr_t, const Factory<Return(Args...)> &factory) noexcept - -> bool -{ - return static_cast<bool>(factory); -} + -> bool; } // namespace yacppdic +template <typename Function> +constexpr auto not_null(Function const & /*unused*/) -> bool; + +template <typename Function> +constexpr auto not_null(Function *function_ptr) -> bool; + +template <typename Return, typename Class> +constexpr auto not_null(Return Class::*method_ptr) -> bool; + +template <typename Function> +constexpr auto not_null(yacppdic::Factory<Function> const &factory) -> bool; + #include "yacppdic/detail/factory-impl.hpp" |