diff options
15 files changed, 254 insertions, 310 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; } 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<Allocator>::AllocDestructor( template <class Allocator> void AllocDestructor<Allocator>::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 Allocator> class AllocDestructor { - using _alloc_traits = std::allocator_traits<Allocator>; +private: + using AllocTraits = std::allocator_traits<Allocator>; 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 <typename... Args, std::size_t... Indices> + template <typename... Params, std::size_t... Indices> constexpr CompressedPairElement( std::piecewise_construct_t /*tag_type*/, - std::tuple<Args...> args, + std::tuple<Params...> args, TupleIndices<Indices...> /*tuple_indices*/ ) noexcept - : _value(std::forward<Args>(std::get<Indices>(args))...) + : _value(std::forward<Params>(std::get<Indices>(args))...) { } @@ -94,13 +94,13 @@ public: { } - template <typename... Args, std::size_t... Indices> + template <typename... Params, std::size_t... Indices> constexpr CompressedPairElement( std::piecewise_construct_t /*unused*/, - std::tuple<Args...> args, + std::tuple<Params...> args, TupleIndices<Indices...> /*unused*/ ) noexcept - : Value(std::forward<Args>(std::get<Indices>(args))...) + : Value(std::forward<Params>(std::get<Indices>(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 <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/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 <class Return> -template <class... Args> -auto InvokeReturnWrapper<Return>::call(Args &&...args) -> Return +template <class... Params> +auto InvokeReturnWrapper<Return>::call(Params &&...args) noexcept -> Return { - return std::invoke(std::forward<Args>(args)...); + return std::invoke(std::forward<Params>(args)...); } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ALLOC_FUNCTOR_TEMPLATE \ - template <class Function, class Allocator, class Return, class... Args> + template <class Function, class Allocator, class Return, class... Params> // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define ALLOC_FUNCTOR AllocFunctor<Function, Allocator, Return(Args...)> +#define ALLOC_FUNCTOR AllocFunctor<Function, Allocator, Return(Params...)> 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>; - return Invoker::call(_function.first(), std::forward<Args>(args)...); + return Invoker::call(_function.first(), std::forward<Params>(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<Alloc>; @@ -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<Alloc>; @@ -124,38 +124,39 @@ void ALLOC_FUNCTOR::destroy_and_delete(AllocFunctor *functor) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFAULT_ALLOC_FUNCTOR_TEMPLATE \ - template <class Function, class Return, class... Args> + template <class Function, class Return, class... Params> // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DEFAULT_ALLOC_FUNCTOR DefaultAllocFunctor<Function, Return(Args...)> +#define DEFAULT_ALLOC_FUNCTOR DefaultAllocFunctor<Function, Return(Params...)> 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>; - return Invoker::call(_function, std::forward<Args>(args)...); + return Invoker::call(_function, std::forward<Params>(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<DefaultAllocFunctor> 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 <typename Return> struct InvokeReturnWrapper { - template <typename... Args> - static auto call(Args &&...args) -> Return; + template <typename... Params> + static auto call(Params &&...args) noexcept -> Return; }; /** @@ -23,32 +23,32 @@ struct InvokeReturnWrapper template <class Function, class Allocator, class FunctionSignature> class AllocFunctor; -template <class Function, class Allocator, class Return, class... Args> -class AllocFunctor<Function, Allocator, Return(Args...)> +template <class Function, class Allocator, class Return, class... Params> +class AllocFunctor<Function, Allocator, Return(Params...)> { 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, Allocator> _function; @@ -60,25 +60,25 @@ private: template <class Function, class FB> class DefaultAllocFunctor; -template <class Function, class Return, class... Args> -class DefaultAllocFunctor<Function, Return(Args...)> +template <class Function, class Return, class... Params> +class DefaultAllocFunctor<Function, Return(Params...)> { 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 <class Function, class Allocator, class Return, class... Args> + template <class Function, class Allocator, class Return, class... Params> // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define COPYABLE_FUNCTOR CopyableFunctor<Function, Allocator, Return(Args...)> +#define COPYABLE_FUNCTOR CopyableFunctor<Function, Allocator, Return(Params...)> 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>(args)...); + return _functor(std::forward<Params>(args)...); } COPYABLE_FUNCTOR_TEMPLATE -auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor<Return(Args...)> * +auto COPYABLE_FUNCTOR::clone() const noexcept -> ICopyableFunctor<Return(Params...)> * { using AllocTraits = std::allocator_traits<Allocator>; @@ -65,7 +74,7 @@ auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor<Return(Args...)> * } COPYABLE_FUNCTOR_TEMPLATE -void COPYABLE_FUNCTOR::clone(ICopyableFunctor<Return(Args...)> *functor) const +void COPYABLE_FUNCTOR::clone(ICopyableFunctor<Return(Params...)> *functor) const noexcept { ::new (static_cast<void *>(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 Function, class Allocator, class FunctionSignature> class CopyableFunctor; -template <class Function, class Allocator, class Return, class... Args> -class CopyableFunctor<Function, Allocator, Return(Args...)> - : public ICopyableFunctor<Return(Args...)> +template <class Function, class Allocator, class Return, class... Params> +class CopyableFunctor<Function, Allocator, Return(Params...)> + : public ICopyableFunctor<Return(Params...)> { 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<Return(Args...)> * override; + auto clone() const noexcept -> ICopyableFunctor<Return(Params...)> * override; - void clone(ICopyableFunctor<Return(Args...)> *functor) const override; + void clone(ICopyableFunctor<Return(Params...)> *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<Function, Allocator, Return(Args...)> _functor; + AllocFunctor<Function, Allocator, Return(Params...)> _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 <class Return, class... Args> +#define VALUE_FUNCTOR_TEMPLATE template <class Return, class... Params> // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define VALUE_FUNCTOR ValueFunctor<Return(Args...)> +#define VALUE_FUNCTOR ValueFunctor<Return(Params...)> VALUE_FUNCTOR_TEMPLATE VALUE_FUNCTOR::ValueFunctor() noexcept : _functor(nullptr) {} VALUE_FUNCTOR_TEMPLATE template <class Function, class Allocator> -VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) +VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) noexcept : _functor(nullptr) { using AllocTraits = std::allocator_traits<Allocator>; - using Functor = CopyableFunctor<Function, Allocator, Return(Args...)>; + using Functor = CopyableFunctor<Function, Allocator, Return(Params...)>; using FunctorAlloc = typename RebindAllocHelper<AllocTraits, Functor>::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<void *>(_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>(args)...); + return (*_functor)(std::forward<Params>(args)...); } VALUE_FUNCTOR_TEMPLATE @@ -164,17 +164,6 @@ VALUE_FUNCTOR::operator bool() const noexcept } 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 <typename Target> 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<TargetFunctor *>(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 Function> class ValueFunctor; -template <class Return, class... Args> -class ValueFunctor<Return(Args...)> +template <class Return, class... Params> +class ValueFunctor<Return(Params...)> { - using TargetFunctor = ICopyableFunctor<Return(Args...)>; - public: ValueFunctor() noexcept; template <class Function> requires NotSameAs<std::decay_t<Function>, ValueFunctor> // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - explicit ValueFunctor(Function &&function) + explicit ValueFunctor(Function &&function) noexcept : ValueFunctor(std::forward<Function>(function), std::allocator<Function>()) { } template <class Function, class Allocator> - 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 <typename Target> 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<Return(Params...)>; + + 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 Function> class ICopyableFunctor; -template <class Return, class... Args> -class ICopyableFunctor<Return(Args...)> +template <class Return, class... Params> +class ICopyableFunctor<Return(Params...)> { 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 <class Function> struct StripSignature; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...)> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...)> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) volatile> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) volatile> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const volatile> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const volatile> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) &> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) &> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const &> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const &> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) volatile &> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) volatile &> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const volatile &> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const volatile &> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) volatile noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) volatile noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const volatile noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const volatile noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) &noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) &noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const &noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const &noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) volatile &noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) volatile &noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; -template <class Return, class Class, class... Args> -struct StripSignature<Return (Class::*)(Args...) const volatile &noexcept> +template <class Return, class Class, class... Params> +struct StripSignature<Return (Class::*)(Params...) const volatile &noexcept> { - using type = Return(Args...); + using type = Return(Params...); }; template <class Function> 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 <typename> class Factory; -template <typename Function, typename Return, typename... Args> +template <typename Function, typename Product, typename... Params> concept Callable = !std::is_same_v< internal::UnConstVolatileReferenceT<Function>, - Factory<Return(Args...)>> && - std::is_invocable_v<Function, Args...> && - internal::IsCoreConvertibleV<std::invoke_result_t<Function, Args...>, Return>; + Factory<Product(Params...)>> && + std::is_invocable_v<Function, Params...> && + internal::IsCoreConvertibleV<std::invoke_result_t<Function, Params...>, Product>; -template <typename Return, typename... Args> -class Factory<Return(Args...)> : public MaybeDeriveFromUnaryFunction<Return(Args...)>, - public MaybeDeriveFromBinaryFunction<Return(Args...)> +template <typename Product, typename... Params> +class Factory<Product(Params...)> { 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 <typename Function> - requires Callable<Function, Return, Args...> + requires Callable<Function, Product, Params...> // 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 <typename RhsReturn, typename... RhsArgs> - auto operator==(const Factory<RhsReturn(RhsArgs...)> &) const noexcept + // Deleted overloads close possible hole in the type system + template <typename RhsProduct, typename... RhsParams> + auto operator==(const Factory<RhsProduct(RhsParams...)> &) const noexcept -> bool = delete; - template <typename RhsReturn, typename... RhsArgs> - auto operator!=(const Factory<RhsReturn(RhsArgs...)> &) const noexcept + template <typename RhsProduct, typename... RhsParams> + auto operator!=(const Factory<RhsProduct(RhsParams...)> &) const noexcept -> bool = delete; - auto operator()(Args... args) const noexcept -> Return; - - [[nodiscard]] auto target_type() const noexcept -> const std::type_info &; - - template <typename Tp> - auto target() noexcept -> Tp *; - - template <typename Tp> - auto target() const noexcept -> const Tp *; - private: - using ValFunctor = internal::ValueFunctor<Return(Args...)>; + using ValFunctor = internal::ValueFunctor<Product(Params...)>; ValFunctor _functor; }; -template <typename Return, typename... Args> -Factory(Return (*)(Args...)) -> Factory<Return(Args...)>; +template <typename Product, typename... Params> +Factory(Product (*)(Params...)) -> Factory<Product(Params...)>; template < typename Function, typename Stripped = internal::StripSignatureT<decltype(&Function::operator())>> Factory(Function) -> Factory<Stripped>; -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; -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; -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; -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; } // namespace yacppdic template <typename Function> -constexpr auto not_null(Function const & /*unused*/) -> bool; +constexpr auto not_null(Function const & /*unused*/) noexcept -> bool; template <typename Function> -constexpr auto not_null(Function *function_ptr) -> bool; +constexpr auto not_null(Function *function_ptr) noexcept -> bool; -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; template <typename Function> -constexpr auto not_null(yacppdic::Factory<Function> const &factory) -> bool; +constexpr auto not_null(yacppdic::Factory<Function> 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 <typename Return, typename... Args> -struct is_factory<Factory<Return(Args...)>> : public std::true_type +template <typename Return, typename... Params> +struct is_factory<Factory<Return(Params...)>> : public std::true_type { }; template <typename PossiblyFunction> inline constexpr bool is_factory_v = is_factory<PossiblyFunction>::value; -} +} // namespace yacppdic |