From 7ab695fe570f842ebdff6b6cb80fa643f17a828b Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 16 May 2022 22:35:30 +0200 Subject: refactor: clean up factory & related internal components --- include/yacppdic/detail/factory-impl.hpp | 89 +++++++++----------- .../detail/internal/alloc_destructor-impl.hpp | 2 +- .../yacppdic/detail/internal/alloc_destructor.hpp | 7 +- .../yacppdic/detail/internal/compressed_pair.hpp | 12 +-- include/yacppdic/detail/internal/factory_base.hpp | 24 ------ .../detail/internal/functor/alloc_functor-impl.hpp | 51 ++++++------ .../detail/internal/functor/alloc_functor.hpp | 42 +++++----- .../internal/functor/copyable_functor-impl.hpp | 37 +++++---- .../detail/internal/functor/copyable_functor.hpp | 27 +++--- .../detail/internal/functor/value_functor-impl.hpp | 33 +++----- .../detail/internal/functor/value_functor.hpp | 28 +++---- .../internal/interfaces/copyable_functor.hpp | 26 +++--- .../yacppdic/detail/internal/strip_signature.hpp | 96 +++++++++++----------- include/yacppdic/factory.hpp | 84 +++++++++---------- include/yacppdic/type_traits.hpp | 6 +- 15 files changed, 254 insertions(+), 310 deletions(-) delete mode 100644 include/yacppdic/detail/internal/factory_base.hpp 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 -Factory::Factory(const Factory &factory) noexcept +template +Factory::Factory(std::nullptr_t) noexcept +{ +} + +template +Factory::Factory(const Factory &factory) noexcept : _functor(factory._functor) { } -template -Factory::Factory(Factory &&factory) noexcept +template +Factory::Factory(Factory &&factory) noexcept : _functor(std::move(factory._functor)) { } -template -auto Factory::operator=(Factory &&factory) noexcept - -> Factory & +template +auto Factory::operator=(Factory &&factory) noexcept + -> Factory & { _functor = std::move(factory._functor); return *this; } -template -auto Factory::operator=(std::nullptr_t) noexcept - -> Factory & +template +auto Factory::operator=(std::nullptr_t) noexcept + -> Factory & { _functor = nullptr; return *this; } -template -Factory::operator bool() const noexcept +template +Factory::operator bool() const noexcept { return static_cast(_functor); } -template -auto Factory::operator()(Args... args) const noexcept -> Return -{ - return _functor(std::forward(args)...); -} - -template -auto Factory::target_type() const noexcept -> const std::type_info & -{ - return _functor.target_type(); -} - -template -template -auto Factory::target() noexcept -> Tp * -{ - return static_cast(_functor.template target()); -} - -template -template -auto Factory::target() const noexcept -> const Tp * +template +auto Factory::operator()(Params... args) const noexcept -> Product { - return _functor.template target(); + return _functor(std::forward(args)...); } -template -inline auto operator==(const Factory &factory, std::nullptr_t) noexcept - -> bool +template +inline auto +operator==(const Factory &factory, std::nullptr_t) noexcept -> bool { return !factory; } -template -inline auto operator==(std::nullptr_t, const Factory &factory) noexcept - -> bool +template +inline auto +operator==(std::nullptr_t, const Factory &factory) noexcept -> bool { return !factory; } -template -inline auto operator!=(const Factory &factory, std::nullptr_t) noexcept - -> bool +template +inline auto +operator!=(const Factory &factory, std::nullptr_t) noexcept -> bool { return static_cast(factory); } -template -inline auto operator!=(std::nullptr_t, const Factory &factory) noexcept - -> bool +template +inline auto +operator!=(std::nullptr_t, const Factory &factory) noexcept -> bool { return static_cast(factory); } @@ -96,25 +81,25 @@ inline auto operator!=(std::nullptr_t, const Factory &factory) } // namespace yacppdic template -constexpr auto not_null(Function const & /*unused*/) -> bool +constexpr auto not_null(Function const & /*unused*/) noexcept -> bool { return true; } template -constexpr auto not_null(Function *function_ptr) -> bool +constexpr auto not_null(Function *function_ptr) noexcept -> bool { return function_ptr; } -template -constexpr auto not_null(Return Class::*method_ptr) -> bool +template +constexpr auto not_null(Product Class::*method_ptr) noexcept -> bool { return method_ptr; } template -constexpr auto not_null(yacppdic::Factory const &factory) -> bool +constexpr auto not_null(yacppdic::Factory const &factory) noexcept -> bool { return !!factory; } diff --git a/include/yacppdic/detail/internal/alloc_destructor-impl.hpp b/include/yacppdic/detail/internal/alloc_destructor-impl.hpp index abcabba..d7eb5eb 100644 --- a/include/yacppdic/detail/internal/alloc_destructor-impl.hpp +++ b/include/yacppdic/detail/internal/alloc_destructor-impl.hpp @@ -17,7 +17,7 @@ AllocDestructor::AllocDestructor( template void AllocDestructor::operator()(Pointer ptr) noexcept { - _alloc_traits::deallocate(_allocator, ptr, _size); + AllocTraits::deallocate(_allocator, ptr, _size); } } diff --git a/include/yacppdic/detail/internal/alloc_destructor.hpp b/include/yacppdic/detail/internal/alloc_destructor.hpp index 9160b8b..5462fa5 100644 --- a/include/yacppdic/detail/internal/alloc_destructor.hpp +++ b/include/yacppdic/detail/internal/alloc_destructor.hpp @@ -14,11 +14,12 @@ struct RebindAllocHelper template class AllocDestructor { - using _alloc_traits = std::allocator_traits; +private: + using AllocTraits = std::allocator_traits; public: - using Pointer = typename _alloc_traits::pointer; - using Size = typename _alloc_traits::size_type; + using Pointer = typename AllocTraits::pointer; + using Size = typename AllocTraits::size_type; using pointer = Pointer; using size = Size; diff --git a/include/yacppdic/detail/internal/compressed_pair.hpp b/include/yacppdic/detail/internal/compressed_pair.hpp index 7d98bbd..0ac6fa2 100644 --- a/include/yacppdic/detail/internal/compressed_pair.hpp +++ b/include/yacppdic/detail/internal/compressed_pair.hpp @@ -46,13 +46,13 @@ public: { } - template + template constexpr CompressedPairElement( std::piecewise_construct_t /*tag_type*/, - std::tuple args, + std::tuple args, TupleIndices /*tuple_indices*/ ) noexcept - : _value(std::forward(std::get(args))...) + : _value(std::forward(std::get(args))...) { } @@ -94,13 +94,13 @@ public: { } - template + template constexpr CompressedPairElement( std::piecewise_construct_t /*unused*/, - std::tuple args, + std::tuple args, TupleIndices /*unused*/ ) noexcept - : Value(std::forward(std::get(args))...) + : Value(std::forward(std::get(args))...) { } diff --git a/include/yacppdic/detail/internal/factory_base.hpp b/include/yacppdic/detail/internal/factory_base.hpp deleted file mode 100644 index 00c4e4f..0000000 --- a/include/yacppdic/detail/internal/factory_base.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -template -class MaybeDeriveFromUnaryFunction -{ -}; - -template -class MaybeDeriveFromUnaryFunction : public std::unary_function -{ -}; - -template -struct MaybeDeriveFromBinaryFunction -{ -}; - -template -struct MaybeDeriveFromBinaryFunction - : public std::binary_function -{ -}; diff --git a/include/yacppdic/detail/internal/functor/alloc_functor-impl.hpp b/include/yacppdic/detail/internal/functor/alloc_functor-impl.hpp index 55de548..31fe3c0 100644 --- a/include/yacppdic/detail/internal/functor/alloc_functor-impl.hpp +++ b/include/yacppdic/detail/internal/functor/alloc_functor-impl.hpp @@ -8,21 +8,21 @@ namespace yacppdic::internal { template -template -auto InvokeReturnWrapper::call(Args &&...args) -> Return +template +auto InvokeReturnWrapper::call(Params &&...args) noexcept -> Return { - return std::invoke(std::forward(args)...); + return std::invoke(std::forward(args)...); } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ALLOC_FUNCTOR_TEMPLATE \ - template + template // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define ALLOC_FUNCTOR AllocFunctor +#define ALLOC_FUNCTOR AllocFunctor ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(Target &&function) +ALLOC_FUNCTOR::AllocFunctor(Target &&function) noexcept : _function( std::piecewise_construct, std::forward_as_tuple(std::move(function)), @@ -32,7 +32,7 @@ ALLOC_FUNCTOR::AllocFunctor(Target &&function) } ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(const Target &function, const Alloc &allocator) +ALLOC_FUNCTOR::AllocFunctor(const Target &function, const Alloc &allocator) noexcept : _function( std::piecewise_construct, std::forward_as_tuple(function), @@ -42,7 +42,7 @@ ALLOC_FUNCTOR::AllocFunctor(const Target &function, const Alloc &allocator) } ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(const Target &function, Alloc &&allocator) +ALLOC_FUNCTOR::AllocFunctor(const Target &function, Alloc &&allocator) noexcept : _function( std::piecewise_construct, std::forward_as_tuple(function), @@ -52,7 +52,7 @@ ALLOC_FUNCTOR::AllocFunctor(const Target &function, Alloc &&allocator) } ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(Target &&function, Alloc &&allocator) +ALLOC_FUNCTOR::AllocFunctor(Target &&function, Alloc &&allocator) noexcept : _function( std::piecewise_construct, std::forward_as_tuple(std::move(function)), @@ -62,27 +62,27 @@ ALLOC_FUNCTOR::AllocFunctor(Target &&function, Alloc &&allocator) } ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::operator()(Args &&...args) -> Return +auto ALLOC_FUNCTOR::operator()(Params &&...args) noexcept -> Return { using Invoker = InvokeReturnWrapper; - return Invoker::call(_function.first(), std::forward(args)...); + return Invoker::call(_function.first(), std::forward(args)...); } ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::target() const -> const Target & +auto ALLOC_FUNCTOR::target() const noexcept -> const Target & { return _function.first(); } ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::get_allocator() const -> const Alloc & +auto ALLOC_FUNCTOR::get_allocator() const noexcept -> const Alloc & { return _function.second(); } ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::clone() const -> AllocFunctor * +auto ALLOC_FUNCTOR::clone() const noexcept -> AllocFunctor * { using AllocTraits = std::allocator_traits; @@ -110,7 +110,7 @@ void ALLOC_FUNCTOR::destroy() noexcept } ALLOC_FUNCTOR_TEMPLATE -void ALLOC_FUNCTOR::destroy_and_delete(AllocFunctor *functor) +void ALLOC_FUNCTOR::destroy_and_delete(AllocFunctor *functor) noexcept { using AllocTraits = std::allocator_traits; @@ -124,38 +124,39 @@ void ALLOC_FUNCTOR::destroy_and_delete(AllocFunctor *functor) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFAULT_ALLOC_FUNCTOR_TEMPLATE \ - template + template // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DEFAULT_ALLOC_FUNCTOR DefaultAllocFunctor +#define DEFAULT_ALLOC_FUNCTOR DefaultAllocFunctor DEFAULT_ALLOC_FUNCTOR_TEMPLATE -DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(Target &&function) +DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(Target &&function) noexcept : _function(std::move(function)) { } DEFAULT_ALLOC_FUNCTOR_TEMPLATE -DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(const Target &function) : _function(function) +DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(const Target &function) noexcept + : _function(function) { } DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::operator()(Args &&...args) -> Return +auto DEFAULT_ALLOC_FUNCTOR::operator()(Params &&...args) noexcept -> Return { using Invoker = InvokeReturnWrapper; - return Invoker::call(_function, std::forward(args)...); + return Invoker::call(_function, std::forward(args)...); } DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::target() const -> const Target & +auto DEFAULT_ALLOC_FUNCTOR::target() const noexcept -> const Target & { return _function; } DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::clone() const -> DefaultAllocFunctor * +auto DEFAULT_ALLOC_FUNCTOR::clone() const noexcept -> DefaultAllocFunctor * { std::allocator allocator; @@ -174,7 +175,7 @@ void DEFAULT_ALLOC_FUNCTOR::destroy() noexcept } DEFAULT_ALLOC_FUNCTOR_TEMPLATE -void DEFAULT_ALLOC_FUNCTOR::destroy_and_delete(DefaultAllocFunctor *function) +void DEFAULT_ALLOC_FUNCTOR::destroy_and_delete(DefaultAllocFunctor *function) noexcept { function->destroy(); @@ -183,4 +184,4 @@ void DEFAULT_ALLOC_FUNCTOR::destroy_and_delete(DefaultAllocFunctor *function) allocator.deallocate(function, 1); } -} +} // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/functor/alloc_functor.hpp b/include/yacppdic/detail/internal/functor/alloc_functor.hpp index 687f182..ac09f9f 100644 --- a/include/yacppdic/detail/internal/functor/alloc_functor.hpp +++ b/include/yacppdic/detail/internal/functor/alloc_functor.hpp @@ -13,8 +13,8 @@ namespace yacppdic::internal template struct InvokeReturnWrapper { - template - static auto call(Args &&...args) -> Return; + template + static auto call(Params &&...args) noexcept -> Return; }; /** @@ -23,32 +23,32 @@ struct InvokeReturnWrapper template class AllocFunctor; -template -class AllocFunctor +template +class AllocFunctor { public: using Target = Function; using Alloc = Allocator; - explicit AllocFunctor(Target &&function); + explicit AllocFunctor(Target &&function) noexcept; - explicit AllocFunctor(const Target &function, const Alloc &allocator); + explicit AllocFunctor(const Target &function, const Alloc &allocator) noexcept; - explicit AllocFunctor(const Target &function, Alloc &&allocator); + explicit AllocFunctor(const Target &function, Alloc &&allocator) noexcept; - explicit AllocFunctor(Target &&function, Alloc &&allocator); + explicit AllocFunctor(Target &&function, Alloc &&allocator) noexcept; - auto operator()(Args &&...args) -> Return; + auto operator()(Params &&...args) noexcept -> Return; - [[nodiscard]] auto target() const -> const Target &; + [[nodiscard]] auto target() const noexcept -> const Target &; - [[nodiscard]] auto get_allocator() const -> const Alloc &; + [[nodiscard]] auto get_allocator() const noexcept -> const Alloc &; - [[nodiscard]] auto clone() const -> AllocFunctor *; + [[nodiscard]] auto clone() const noexcept -> AllocFunctor *; void destroy() noexcept; - static void destroy_and_delete(AllocFunctor *functor); + static void destroy_and_delete(AllocFunctor *functor) noexcept; private: CompressedPair _function; @@ -60,25 +60,25 @@ private: template class DefaultAllocFunctor; -template -class DefaultAllocFunctor +template +class DefaultAllocFunctor { public: using Target = Function; - explicit DefaultAllocFunctor(Target &&function); + explicit DefaultAllocFunctor(Target &&function) noexcept; - explicit DefaultAllocFunctor(const Target &function); + explicit DefaultAllocFunctor(const Target &function) noexcept; - auto operator()(Args &&...args) -> Return; + auto operator()(Params &&...args) noexcept -> Return; - auto target() const -> const Target &; + auto target() const noexcept -> const Target &; - auto clone() const -> DefaultAllocFunctor *; + auto clone() const noexcept -> DefaultAllocFunctor *; void destroy() noexcept; - static void destroy_and_delete(DefaultAllocFunctor *function); + static void destroy_and_delete(DefaultAllocFunctor *function) noexcept; private: Function _function; diff --git a/include/yacppdic/detail/internal/functor/copyable_functor-impl.hpp b/include/yacppdic/detail/internal/functor/copyable_functor-impl.hpp index 9c51492..a25f2b3 100644 --- a/include/yacppdic/detail/internal/functor/copyable_functor-impl.hpp +++ b/include/yacppdic/detail/internal/functor/copyable_functor-impl.hpp @@ -10,40 +10,49 @@ namespace yacppdic::internal // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define COPYABLE_FUNCTOR_TEMPLATE \ - template + template // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define COPYABLE_FUNCTOR CopyableFunctor +#define COPYABLE_FUNCTOR CopyableFunctor COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(Function &&function) : _functor(std::move(function)) {} +COPYABLE_FUNCTOR::CopyableFunctor(Function &&function) noexcept + : _functor(std::move(function)) +{ +} COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(const Function &function, const Allocator &allocator) +COPYABLE_FUNCTOR::CopyableFunctor( + const Function &function, + const Allocator &allocator +) noexcept : _functor(function, allocator) { } COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(const Function &function, Allocator &&allocator) +COPYABLE_FUNCTOR::CopyableFunctor( + const Function &function, + Allocator &&allocator +) noexcept : _functor(function, std::move(allocator)) { } COPYABLE_FUNCTOR_TEMPLATE -COPYABLE_FUNCTOR::CopyableFunctor(Function &&function, Allocator &&allocator) +COPYABLE_FUNCTOR::CopyableFunctor(Function &&function, Allocator &&allocator) noexcept : _functor(std::move(function), std::move(allocator)) { } COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::operator()(Args &&...args) -> Return +auto COPYABLE_FUNCTOR::operator()(Params &&...args) noexcept -> Return { - return _functor(std::forward(args)...); + return _functor(std::forward(args)...); } COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor * +auto COPYABLE_FUNCTOR::clone() const noexcept -> ICopyableFunctor * { using AllocTraits = std::allocator_traits; @@ -65,7 +74,7 @@ auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor * } COPYABLE_FUNCTOR_TEMPLATE -void COPYABLE_FUNCTOR::clone(ICopyableFunctor *functor) const +void COPYABLE_FUNCTOR::clone(ICopyableFunctor *functor) const noexcept { ::new (static_cast(functor)) CopyableFunctor(_functor.target(), _functor.get_allocator()); @@ -103,10 +112,4 @@ auto COPYABLE_FUNCTOR::target(const std::type_info &type_info) const noexcept -> return nullptr; } -COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::target_type() const noexcept -> const std::type_info & -{ - return typeid(Function); -} - -} +} // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/functor/copyable_functor.hpp b/include/yacppdic/detail/internal/functor/copyable_functor.hpp index b305d38..3350781 100644 --- a/include/yacppdic/detail/internal/functor/copyable_functor.hpp +++ b/include/yacppdic/detail/internal/functor/copyable_functor.hpp @@ -15,24 +15,27 @@ namespace yacppdic::internal template class CopyableFunctor; -template -class CopyableFunctor - : public ICopyableFunctor +template +class CopyableFunctor + : public ICopyableFunctor { public: - explicit CopyableFunctor(Function &&function); + explicit CopyableFunctor(Function &&function) noexcept; - explicit CopyableFunctor(const Function &function, const Allocator &allocator); + explicit CopyableFunctor( + const Function &function, + const Allocator &allocator + ) noexcept; - explicit CopyableFunctor(const Function &function, Allocator &&allocator); + explicit CopyableFunctor(const Function &function, Allocator &&allocator) noexcept; - explicit CopyableFunctor(Function &&function, Allocator &&allocator); + explicit CopyableFunctor(Function &&function, Allocator &&allocator) noexcept; - auto operator()(Args &&...args) -> Return override; + auto operator()(Params &&...args) noexcept -> Return override; - auto clone() const -> ICopyableFunctor * override; + auto clone() const noexcept -> ICopyableFunctor * override; - void clone(ICopyableFunctor *functor) const override; + void clone(ICopyableFunctor *functor) const noexcept override; void destroy() noexcept override; @@ -41,10 +44,8 @@ public: [[nodiscard]] auto target(const std::type_info &type_info) const noexcept -> const void * override; - [[nodiscard]] auto target_type() const noexcept -> const std::type_info & override; - private: - AllocFunctor _functor; + AllocFunctor _functor; }; } // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/functor/value_functor-impl.hpp b/include/yacppdic/detail/internal/functor/value_functor-impl.hpp index c1030aa..50736da 100644 --- a/include/yacppdic/detail/internal/functor/value_functor-impl.hpp +++ b/include/yacppdic/detail/internal/functor/value_functor-impl.hpp @@ -6,22 +6,22 @@ namespace yacppdic::internal { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define VALUE_FUNCTOR_TEMPLATE template +#define VALUE_FUNCTOR_TEMPLATE template // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define VALUE_FUNCTOR ValueFunctor +#define VALUE_FUNCTOR ValueFunctor VALUE_FUNCTOR_TEMPLATE VALUE_FUNCTOR::ValueFunctor() noexcept : _functor(nullptr) {} VALUE_FUNCTOR_TEMPLATE template -VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) +VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) noexcept : _functor(nullptr) { using AllocTraits = std::allocator_traits; - using Functor = CopyableFunctor; + using Functor = CopyableFunctor; using FunctorAlloc = typename RebindAllocHelper::type; @@ -55,7 +55,7 @@ VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) } VALUE_FUNCTOR_TEMPLATE -VALUE_FUNCTOR::ValueFunctor(const ValueFunctor &val_functor) +VALUE_FUNCTOR::ValueFunctor(const ValueFunctor &val_functor) noexcept { if (val_functor._functor == nullptr) { @@ -92,7 +92,7 @@ VALUE_FUNCTOR::ValueFunctor(ValueFunctor &&val_functor) noexcept } VALUE_FUNCTOR_TEMPLATE -VALUE_FUNCTOR::~ValueFunctor() +VALUE_FUNCTOR::~ValueFunctor() noexcept { if (static_cast(_functor) == &_buf) { @@ -128,7 +128,7 @@ auto VALUE_FUNCTOR::operator=(ValueFunctor &&val_functor) noexcept -> ValueFunct } VALUE_FUNCTOR_TEMPLATE -auto VALUE_FUNCTOR::operator=(std::nullptr_t) -> ValueFunctor & +auto VALUE_FUNCTOR::operator=(std::nullptr_t) noexcept -> ValueFunctor & { TargetFunctor *old_functor = _functor; @@ -147,14 +147,14 @@ auto VALUE_FUNCTOR::operator=(std::nullptr_t) -> ValueFunctor & } VALUE_FUNCTOR_TEMPLATE -auto VALUE_FUNCTOR::operator()(Args &&...args) const -> Return +auto VALUE_FUNCTOR::operator()(Params &&...args) const noexcept -> Return { if (_functor == nullptr) { std::abort(); } - return (*_functor)(std::forward(args)...); + return (*_functor)(std::forward(args)...); } VALUE_FUNCTOR_TEMPLATE @@ -163,17 +163,6 @@ VALUE_FUNCTOR::operator bool() const noexcept return _functor != nullptr; } -VALUE_FUNCTOR_TEMPLATE -auto VALUE_FUNCTOR::target_type() const noexcept -> const std::type_info & -{ - if (_functor == nullptr) - { - return typeid(void); - } - - return _functor->target_type(); -} - VALUE_FUNCTOR_TEMPLATE template auto VALUE_FUNCTOR::target() const noexcept -> const Target * @@ -187,10 +176,10 @@ auto VALUE_FUNCTOR::target() const noexcept -> const Target * } VALUE_FUNCTOR_TEMPLATE -auto VALUE_FUNCTOR::_as_copyable_functor(void *function_ptr) -> TargetFunctor * +auto VALUE_FUNCTOR::_as_copyable_functor(void *function_ptr) noexcept -> TargetFunctor * { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return reinterpret_cast(function_ptr); } -} +} // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/functor/value_functor.hpp b/include/yacppdic/detail/internal/functor/value_functor.hpp index e5cde97..9ed2728 100644 --- a/include/yacppdic/detail/internal/functor/value_functor.hpp +++ b/include/yacppdic/detail/internal/functor/value_functor.hpp @@ -17,52 +17,52 @@ namespace yacppdic::internal template class ValueFunctor; -template -class ValueFunctor +template +class ValueFunctor { - using TargetFunctor = ICopyableFunctor; - public: ValueFunctor() noexcept; template requires NotSameAs, ValueFunctor> // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - explicit ValueFunctor(Function &&function) + explicit ValueFunctor(Function &&function) noexcept : ValueFunctor(std::forward(function), std::allocator()) { } template - ValueFunctor(Function &&function, const Allocator &allocator); + ValueFunctor(Function &&function, const Allocator &allocator) noexcept; - ValueFunctor(const ValueFunctor &val_functor); + ValueFunctor(const ValueFunctor &val_functor) noexcept; ValueFunctor(ValueFunctor &&val_functor) noexcept; - ~ValueFunctor(); + ~ValueFunctor() noexcept; auto operator=(const ValueFunctor &val_functor) noexcept = delete; auto operator=(ValueFunctor &&val_functor) noexcept -> ValueFunctor &; - auto operator=(std::nullptr_t) -> ValueFunctor &; + auto operator=(std::nullptr_t) noexcept -> ValueFunctor &; - auto operator()(Args &&...args) const -> Return; + auto operator()(Params &&...args) const noexcept -> Return; explicit operator bool() const noexcept; - [[nodiscard]] auto target_type() const noexcept -> const std::type_info &; - template auto target() const noexcept -> const Target *; private: - typename std::aligned_storage<3 * sizeof(void *)>::type _buf{}; + using Storage = typename std::aligned_storage<3U * sizeof(void *)>::type; + + using TargetFunctor = ICopyableFunctor; + + Storage _buf{}; TargetFunctor *_functor; - static auto _as_copyable_functor(void *function_ptr) -> TargetFunctor *; + static auto _as_copyable_functor(void *function_ptr) noexcept -> TargetFunctor *; }; } // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/interfaces/copyable_functor.hpp b/include/yacppdic/detail/internal/interfaces/copyable_functor.hpp index dadb214..0e80def 100644 --- a/include/yacppdic/detail/internal/interfaces/copyable_functor.hpp +++ b/include/yacppdic/detail/internal/interfaces/copyable_functor.hpp @@ -11,36 +11,34 @@ namespace yacppdic::internal template class ICopyableFunctor; -template -class ICopyableFunctor +template +class ICopyableFunctor { public: - ICopyableFunctor() = default; + ICopyableFunctor() noexcept = default; - ICopyableFunctor(const ICopyableFunctor &) = delete; + ICopyableFunctor(const ICopyableFunctor &) noexcept = delete; - ICopyableFunctor(ICopyableFunctor &&) = delete; + ICopyableFunctor(ICopyableFunctor &&) noexcept = delete; - virtual ~ICopyableFunctor() = default; + virtual ~ICopyableFunctor() noexcept = default; - [[nodiscard]] virtual auto clone() const -> ICopyableFunctor * = 0; + [[nodiscard]] virtual auto clone() const noexcept -> ICopyableFunctor * = 0; - virtual void clone(ICopyableFunctor *) const = 0; + virtual void clone(ICopyableFunctor *) const noexcept = 0; virtual void destroy() noexcept = 0; virtual void destroy_deallocate() noexcept = 0; - virtual auto operator()(Args &&...) -> Return = 0; + virtual auto operator()(Params &&...) noexcept -> Return = 0; - auto operator=(const ICopyableFunctor &) = delete; + auto operator=(const ICopyableFunctor &) noexcept = delete; - auto operator=(ICopyableFunctor &&) = delete; + auto operator=(ICopyableFunctor &&) noexcept = delete; [[nodiscard]] virtual auto target(const std::type_info &) const noexcept -> const void * = 0; - - [[nodiscard]] virtual auto target_type() const noexcept -> const std::type_info & = 0; }; -} +} // namespace yacppdic::internal diff --git a/include/yacppdic/detail/internal/strip_signature.hpp b/include/yacppdic/detail/internal/strip_signature.hpp index 30a2ad0..d770161 100644 --- a/include/yacppdic/detail/internal/strip_signature.hpp +++ b/include/yacppdic/detail/internal/strip_signature.hpp @@ -6,100 +6,100 @@ namespace yacppdic::internal template struct StripSignature; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; -template -struct StripSignature +template +struct StripSignature { - using type = Return(Args...); + using type = Return(Params...); }; template diff --git a/include/yacppdic/factory.hpp b/include/yacppdic/factory.hpp index 1eb2dc7..6599146 100644 --- a/include/yacppdic/factory.hpp +++ b/include/yacppdic/factory.hpp @@ -3,7 +3,6 @@ #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" @@ -20,106 +19,97 @@ namespace yacppdic template class Factory; -template +template concept Callable = !std::is_same_v< internal::UnConstVolatileReferenceT, - Factory> && - std::is_invocable_v && - internal::IsCoreConvertibleV, Return>; + Factory> && + std::is_invocable_v && + internal::IsCoreConvertibleV, Product>; -template -class Factory : public MaybeDeriveFromUnaryFunction, - public MaybeDeriveFromBinaryFunction +template +class Factory { public: - using Result = Return; + using Result = Product; Factory() noexcept = default; - explicit Factory(std::nullptr_t) noexcept {} + explicit Factory(std::nullptr_t) noexcept; Factory(const Factory &factory) noexcept; Factory(Factory &&factory) noexcept; template - requires Callable + requires Callable // NOLINTNEXTLINE(google-explicit-constructor) Factory(Function function) noexcept : _functor(std::move(function)) {} + ~Factory() noexcept = default; + auto operator=(const Factory &factory) noexcept = delete; auto operator=(Factory &&factory) noexcept -> Factory &; auto operator=(std::nullptr_t) noexcept -> Factory &; - ~Factory() noexcept = default; + auto operator()(Params... args) const noexcept -> Product; explicit operator bool() const noexcept; - // deleted overloads close possible hole in the type system - template - auto operator==(const Factory &) const noexcept + // Deleted overloads close possible hole in the type system + template + auto operator==(const Factory &) const noexcept -> bool = delete; - template - auto operator!=(const Factory &) const noexcept + template + auto operator!=(const Factory &) const noexcept -> bool = delete; - auto operator()(Args... args) const noexcept -> Return; - - [[nodiscard]] auto target_type() const noexcept -> const std::type_info &; - - template - auto target() noexcept -> Tp *; - - template - auto target() const noexcept -> const Tp *; - private: - using ValFunctor = internal::ValueFunctor; + using ValFunctor = internal::ValueFunctor; ValFunctor _functor; }; -template -Factory(Return (*)(Args...)) -> Factory; +template +Factory(Product (*)(Params...)) -> Factory; template < typename Function, typename Stripped = internal::StripSignatureT> Factory(Function) -> Factory; -template -inline auto operator==(const Factory &factory, std::nullptr_t) noexcept - -> bool; +template +inline auto +operator==(const Factory &factory, std::nullptr_t) noexcept -> bool; -template -inline auto operator==(std::nullptr_t, const Factory &factory) noexcept - -> bool; +template +inline auto +operator==(std::nullptr_t, const Factory &factory) noexcept -> bool; -template -inline auto operator!=(const Factory &factory, std::nullptr_t) noexcept - -> bool; +template +inline auto +operator!=(const Factory &factory, std::nullptr_t) noexcept -> bool; -template -inline auto operator!=(std::nullptr_t, const Factory &factory) noexcept - -> bool; +template +inline auto +operator!=(std::nullptr_t, const Factory &factory) noexcept -> bool; } // namespace yacppdic template -constexpr auto not_null(Function const & /*unused*/) -> bool; +constexpr auto not_null(Function const & /*unused*/) noexcept -> bool; template -constexpr auto not_null(Function *function_ptr) -> bool; +constexpr auto not_null(Function *function_ptr) noexcept -> bool; -template -constexpr auto not_null(Return Class::*method_ptr) -> bool; +template +constexpr auto not_null(Product Class::*method_ptr) noexcept -> bool; template -constexpr auto not_null(yacppdic::Factory const &factory) -> bool; +constexpr auto not_null(yacppdic::Factory const &factory) noexcept -> bool; #include "yacppdic/detail/factory-impl.hpp" diff --git a/include/yacppdic/type_traits.hpp b/include/yacppdic/type_traits.hpp index ab05caa..2c03e78 100644 --- a/include/yacppdic/type_traits.hpp +++ b/include/yacppdic/type_traits.hpp @@ -12,12 +12,12 @@ struct is_factory : public std::false_type // NOLINT(readability-identifier-nami { }; -template -struct is_factory> : public std::true_type +template +struct is_factory> : public std::true_type { }; template inline constexpr bool is_factory_v = is_factory::value; -} +} // namespace yacppdic -- cgit v1.2.3-18-g5258