diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/function.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/function.h')
-rw-r--r-- | util/generic/function.h | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/util/generic/function.h b/util/generic/function.h index 62fa84e0cb..3a90758741 100644 --- a/util/generic/function.h +++ b/util/generic/function.h @@ -1,26 +1,26 @@ -#pragma once - -#include "typetraits.h" -#include "typelist.h" - -#include <functional> - -namespace NPrivate { - template <class F> - struct TRemoveClassImpl { - using TSignature = F; - }; - - template <typename C, typename R, typename... Args> - struct TRemoveClassImpl<R (C::*)(Args...)> { - typedef R TSignature(Args...); - }; - - template <typename C, typename R, typename... Args> - struct TRemoveClassImpl<R (C::*)(Args...) const> { - typedef R TSignature(Args...); - }; - +#pragma once + +#include "typetraits.h" +#include "typelist.h" + +#include <functional> + +namespace NPrivate { + template <class F> + struct TRemoveClassImpl { + using TSignature = F; + }; + + template <typename C, typename R, typename... Args> + struct TRemoveClassImpl<R (C::*)(Args...)> { + typedef R TSignature(Args...); + }; + + template <typename C, typename R, typename... Args> + struct TRemoveClassImpl<R (C::*)(Args...) const> { + typedef R TSignature(Args...); + }; + template <class T> struct TRemoveNoExceptImpl { using Type = T; @@ -39,49 +39,49 @@ namespace NPrivate { template <class T> using TRemoveNoExcept = typename TRemoveNoExceptImpl<T>::Type; - template <class F> + template <class F> using TRemoveClass = typename TRemoveClassImpl<TRemoveNoExcept<F>>::TSignature; - - template <class C> - struct TFuncInfo { - using TSignature = TRemoveClass<decltype(&C::operator())>; - }; - - template <class R, typename... Args> - struct TFuncInfo<R(Args...)> { - using TResult = R; - typedef R TSignature(Args...); - }; -} - -template <class C> -using TFunctionSignature = typename ::NPrivate::TFuncInfo<::NPrivate::TRemoveClass<std::remove_reference_t<std::remove_pointer_t<C>>>>::TSignature; - -template <typename F> -struct TCallableTraits: public TCallableTraits<TFunctionSignature<F>> { -}; - -template <typename R, typename... Args> -struct TCallableTraits<R(Args...)> { - using TResult = R; - using TArgs = TTypeList<Args...>; - typedef R TSignature(Args...); -}; - -template <typename C> -using TFunctionResult = typename TCallableTraits<C>::TResult; - -template <typename C> -using TFunctionArgs = typename TCallableTraits<C>::TArgs; - -template <typename C, size_t N> -struct TFunctionArgImpl { - using TArgs = TFunctionArgs<C>; - using TResult = typename TArgs::template TGet<N>; -}; - -template <typename C, size_t N> -using TFunctionArg = typename TFunctionArgImpl<C, N>::TResult; + + template <class C> + struct TFuncInfo { + using TSignature = TRemoveClass<decltype(&C::operator())>; + }; + + template <class R, typename... Args> + struct TFuncInfo<R(Args...)> { + using TResult = R; + typedef R TSignature(Args...); + }; +} + +template <class C> +using TFunctionSignature = typename ::NPrivate::TFuncInfo<::NPrivate::TRemoveClass<std::remove_reference_t<std::remove_pointer_t<C>>>>::TSignature; + +template <typename F> +struct TCallableTraits: public TCallableTraits<TFunctionSignature<F>> { +}; + +template <typename R, typename... Args> +struct TCallableTraits<R(Args...)> { + using TResult = R; + using TArgs = TTypeList<Args...>; + typedef R TSignature(Args...); +}; + +template <typename C> +using TFunctionResult = typename TCallableTraits<C>::TResult; + +template <typename C> +using TFunctionArgs = typename TCallableTraits<C>::TArgs; + +template <typename C, size_t N> +struct TFunctionArgImpl { + using TArgs = TFunctionArgs<C>; + using TResult = typename TArgs::template TGet<N>; +}; + +template <typename C, size_t N> +using TFunctionArg = typename TFunctionArgImpl<C, N>::TResult; // temporary before std::apply appearance @@ -92,12 +92,12 @@ auto ApplyImpl(F&& f, Tuple&& t, std::index_sequence<I...>) { // change to std::apply after c++ 17 template <typename F, typename Tuple> -auto Apply(F&& f, Tuple&& t) { - return ApplyImpl(f, t, std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{}); +auto Apply(F&& f, Tuple&& t) { + return ApplyImpl(f, t, std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{}); } // change to std::apply after c++ 17 template <typename F> -auto Apply(F&& f, std::tuple<>) { +auto Apply(F&& f, std::tuple<>) { return f(); } |