Go to the documentation of this file.
17 #ifndef ABSL_FUNCTIONAL_INTERNAL_ANY_INVOCABLE_H_
18 #define ABSL_FUNCTIONAL_INTERNAL_ANY_INVOCABLE_H_
60 #include <initializer_list>
63 #include <type_traits>
66 #include "absl/base/config.h"
67 #include "absl/base/internal/invoke.h"
68 #include "absl/base/macros.h"
69 #include "absl/meta/type_traits.h"
70 #include "absl/utility/utility.h"
78 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
79 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex) noexcept(noex)
81 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex)
88 namespace internal_any_invocable {
127 template <
class ReturnType,
class F,
class...
P,
133 template <
class ReturnType,
class F,
class...
P,
137 std::forward<P>(
args)...);
152 template <
typename T>
155 template <
typename T>
162 using type = decltype((
163 ForwardImpl<T>)(std::integral_constant<
bool,
198 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
199 return *std::launder(
reinterpret_cast<T*
>(&
state->storage));
200 #elif ABSL_HAVE_BUILTIN(__builtin_launder)
201 return *__builtin_launder(
reinterpret_cast<T*
>(&
state->storage));
207 #if !defined(__clang__) && defined(__GNUC__)
208 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
209 #pragma GCC diagnostic push
211 return *
reinterpret_cast<T*
>(&
state->storage);
212 #if !defined(__clang__) && defined(__GNUC__)
213 #pragma GCC diagnostic pop
224 TypeErasedState* , TypeErasedState* )
229 template <
bool SigIsNoexcept, class ReturnType, class...
P>
269 "Local storage must only be used for supported types.");
271 "Locally stored types must be trivially copyable.");
273 T& from_object = (ObjectInLocalStorage<T>)(
from);
290 template <
bool SigIsNoexcept,
class ReturnType,
class QualTRef,
class...
P>
297 "Target object must be in local storage in order to be invoked from it.");
299 auto& f = (ObjectInLocalStorage<RawT>)(
state);
300 return (InvokeR<ReturnType>)(
static_cast<QualTRef
>(f),
312 to->remote =
from->remote;
315 #if defined(__cpp_sized_deallocation)
316 ::operator
delete(
from->remote.target,
from->remote.size);
317 #else // __cpp_sized_deallocation
318 ::operator
delete(
from->remote.target);
319 #endif // __cpp_sized_deallocation
332 "Remote storage must only be used for types that do not "
333 "qualify for local storage.");
338 to->remote.target =
from->remote.target;
348 template <
bool SigIsNoexcept,
class ReturnType,
class QualTRef,
class...
P>
354 "Target object must be in remote storage in order to be "
357 auto& f = *
static_cast<RawT*
>(
state->remote.target);
358 return (InvokeR<ReturnType>)(
static_cast<QualTRef
>(f),
378 template <
class QualDecayedTRef>
393 #if defined(__cpp_sized_deallocation)
405 #else // __cpp_sized_deallocation
412 #endif // __cpp_sized_deallocation
414 template <
bool SigIsNoexcept,
class ReturnType,
class...
P>
418 template <
bool NoExceptSrc,
bool NoExceptDest,
class...
T>
421 return !NoExceptDest || NoExceptSrc;
426 template <
bool SigIsNoexcept,
class ReturnType,
class...
P>
443 template <
class QualDecayedTRef,
class F>
459 Initialize<static_cast<int>(kTargetType), QualDecayedTRef>(
466 template <
class QualTRef,
class...
Args>
468 InitializeStorage<QualTRef>(std::forward<Args>(
args)...);
476 other.invoker_ =
nullptr;
494 other.invoker_ =
nullptr;
511 template <
int target_type,
class QualDecayedTRef,
class F,
519 #if !defined(__clang__) && defined(__GNUC__)
520 #pragma GCC diagnostic ignored "-Wpragmas"
521 #pragma GCC diagnostic ignored "-Waddress"
522 #pragma GCC diagnostic ignored "-Wnonnull-compare"
523 #pragma GCC diagnostic push
526 #if !defined(__clang__) && defined(__GNUC__)
527 #pragma GCC diagnostic pop
533 InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
536 template <
int target_type,
class QualDecayedTRef,
class F,
545 f.invoker_ =
nullptr;
548 template <
int target_type,
class QualDecayedTRef,
class F,
552 InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
559 template <
int target_type,
class QualDecayedTRef,
class F,
562 InitializeStorage<QualDecayedTRef>(std::forward<F>(f));
566 template <
class QualTRef,
class...
Args,
572 RawT(std::forward<Args>(
args)...);
576 InitializeLocalManager<RawT>();
580 template <
class QualTRef,
class...
Args,
584 InitializeRemoteManager<RemoveCVRef<QualTRef>>(std::forward<Args>(
args)...);
599 manager_ = LocalManagerNontrivial<T>;
608 template <
class T,
class...
Args,
612 std::unique_ptr<void, TrivialDeleter> uninitialized_target(
614 ::new (uninitialized_target.get())
T(std::forward<Args>(
args)...);
620 template <
class T,
class...
Args,
624 manager_ = RemoteManagerNontrivial<T>;
634 template <
typename Other>
636 static constexpr
bool value =
false;
639 template <
typename Sig>
685 template <
class...
T>
690 template <
class Sig,
class F,
701 template <
class Sig,
class F,
class...
Args>
709 template <
class Sig,
class F,
719 template <
class Sig,
class F>
734 #define ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT(inv_quals, noex) \
735 ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT_##noex(inv_quals)
741 #define ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT_true(inv_quals) \
742 absl::enable_if_t<absl::disjunction< \
743 std::is_nothrow_invocable_r< \
744 ReturnType, UnwrapStdReferenceWrapper<absl::decay_t<F>> inv_quals, \
747 std::is_nothrow_invocable< \
748 UnwrapStdReferenceWrapper<absl::decay_t<F>> inv_quals, P...>, \
751 absl::base_internal::invoke_result_t< \
752 UnwrapStdReferenceWrapper<absl::decay_t<F>> inv_quals, \
755 #define ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT_false(inv_quals)
771 #define ABSL_INTERNAL_ANY_INVOCABLE_IMPL_(cv, ref, inv_quals, noex) \
772 template <class ReturnType, class... P> \
773 class Impl<ReturnType(P...) cv ref ABSL_INTERNAL_NOEXCEPT_SPEC(noex)> \
774 : public CoreImpl<noex, ReturnType, P...> { \
777 using Core = CoreImpl<noex, ReturnType, P...>; \
781 using CallIsValid = True<absl::enable_if_t<absl::disjunction< \
782 absl::base_internal::is_invocable_r<ReturnType, \
783 absl::decay_t<F> inv_quals, P...>, \
784 std::is_same<ReturnType, \
785 absl::base_internal::invoke_result_t< \
786 absl::decay_t<F> inv_quals, P...>>>::value>>; \
790 using CallIsNoexceptIfSigIsNoexcept = \
791 True<ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT(inv_quals, \
801 explicit Impl(ConversionConstruct, F&& f) \
802 : Core(TypedConversionConstruct< \
803 typename std::decay<F>::type inv_quals>(), \
804 std::forward<F>(f)) {} \
807 template <class T, class... Args> \
808 explicit Impl(absl::in_place_type_t<T>, Args&&... args) \
809 : Core(absl::in_place_type<absl::decay_t<T> inv_quals>, \
810 std::forward<Args>(args)...) {} \
813 ReturnType operator()(P... args) cv ref noexcept(noex) { \
814 assert(this->invoker_ != nullptr); \
815 return this->invoker_(const_cast<TypeErasedState*>(&this->state_), \
816 static_cast<ForwardedParameterType<P>>(args)...); \
822 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
825 #define ABSL_INTERNAL_ANY_INVOCABLE_IMPL(cv, ref, inv_quals) \
826 ABSL_INTERNAL_ANY_INVOCABLE_IMPL_(cv, ref, inv_quals, false); \
827 ABSL_INTERNAL_ANY_INVOCABLE_IMPL_(cv, ref, inv_quals, true)
829 #define ABSL_INTERNAL_ANY_INVOCABLE_IMPL(cv, ref, inv_quals) \
830 ABSL_INTERNAL_ANY_INVOCABLE_IMPL_(cv, ref, inv_quals, false)
846 #undef ABSL_INTERNAL_ANY_INVOCABLE_IMPL
847 #undef ABSL_INTERNAL_ANY_INVOCABLE_IMPL_
848 #undef ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT_false
849 #undef ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT_true
850 #undef ABSL_INTERNAL_ANY_INVOCABLE_NOEXCEPT_CONSTRAINT
851 #undef ABSL_INTERNAL_NOEXCEPT_SPEC
857 #endif // ABSL_FUNCTIONAL_INTERNAL_ANY_INVOCABLE_H_
CoreImpl(TypedConversionConstruct< QualDecayedTRef >, F &&f)
std::integral_constant< bool, sizeof(absl::void_t< T... > *) !=0 > True
void(*)(utility_internal::InPlaceTypeTag< T >) in_place_type_t
decltype((ForwardImpl< T >)(std::integral_constant< bool, std::is_scalar< T >::value >())) type
ABSL_INTERNAL_ANY_INVOCABLE_IMPL(,, &)
void InitializeLocalManager()
static constexpr bool value
integral_constant< bool, true > true_type
integral_constant< bool, false > false_type
struct absl::internal_any_invocable::TypeErasedState::@68 remote
CoreImpl & operator=(CoreImpl &&other) noexcept
@ kIncompatibleAnyInvocable
typename std::enable_if< B, T >::type enable_if_t
void(FunctionToCall, TypeErasedState *, TypeErasedState *) ABSL_INTERNAL_NOEXCEPT_SPEC(true) ManagerType
True< absl::enable_if_t<!IsInPlaceType< RemoveCVRef< F > >::value >, absl::enable_if_t< Impl< Sig >::template CallIsValid< F >::value >, absl::enable_if_t< Impl< Sig >::template CallIsNoexceptIfSigIsNoexcept< F >::value >, absl::enable_if_t< std::is_constructible< absl::decay_t< F >, F >::value > > CanConvert
typename ForwardedParameter< T >::type ForwardedParameterType
#define ABSL_NAMESPACE_END
void RemoteManagerTrivial(FunctionToCall operation, TypeErasedState *const from, TypeErasedState *const to) noexcept
#define T(upbtypeconst, upbtype, ctype, default_value)
constexpr bool IsCompatibleConversion(void *, void *)
void LocalManagerNontrivial(FunctionToCall operation, TypeErasedState *const from, TypeErasedState *const to) noexcept
void operator()(void *target) const
#define ABSL_NAMESPACE_BEGIN
True< absl::enable_if_t< Impl< Sig >::template CallIsValid< F >::value >, absl::enable_if_t< Impl< Sig >::template CallIsNoexceptIfSigIsNoexcept< F >::value >, absl::enable_if_t< std::is_constructible< absl::decay_t< F >, Args... >::value > > CanEmplace
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
void InitializeStorage(Args &&... args)
InvokerType< SigIsNoexcept, ReturnType, P... > * invoker_
CoreImpl(CoreImpl &&other) noexcept
void RemoteManagerNontrivial(FunctionToCall operation, TypeErasedState *const from, TypeErasedState *const to) noexcept
TrivialDeleter(std::size_t)
True< absl::enable_if_t< Impl< Sig >::template CallIsValid< F >::value >, absl::enable_if_t< Impl< Sig >::template CallIsNoexceptIfSigIsNoexcept< F >::value >, absl::enable_if_t< std::is_constructible< absl::decay_t< F >, F >::value > > CanAssign
T ForwardImpl(std::true_type)
void InvokeR(F &&f, P &&... args)
ReturnType RemoteInvoker(TypeErasedState *const state, ForwardedParameterType< P >... args) noexcept(SigIsNoexcept)
T & ObjectInLocalStorage(TypeErasedState *const state)
True< absl::enable_if_t< Impl< Sig >::template CallIsValid< std::reference_wrapper< F > >::value >, absl::enable_if_t< Impl< Sig >::template CallIsNoexceptIfSigIsNoexcept< std::reference_wrapper< F > >::value > > CanAssignReferenceWrapper
void InitializeRemoteManager(Args &&... args)
std::integral_constant< bool, std::is_trivially_destructible< T >::value &&alignof(T)<=ABSL_INTERNAL_DEFAULT_NEW_ALIGNMENT > HasTrivialRemoteStorage
typename type_traits_internal::VoidTImpl< Ts... >::type void_t
void LocalManagerTrivial(FunctionToCall, TypeErasedState *const from, TypeErasedState *const to) noexcept
typename std::remove_cv< typename std::remove_reference< T >::type >::type RemoveCVRef
#define ABSL_INTERNAL_UNREACHABLE
char storage[kStorageSize]
CoreImpl(absl::in_place_type_t< QualTRef >, Args &&... args)
#define ABSL_INTERNAL_NOEXCEPT_SPEC(noex)
ReturnType LocalInvoker(TypeErasedState *const state, ForwardedParameterType< P >... args) noexcept(SigIsNoexcept)
std::integral_constant< bool, sizeof(T)<=kStorageSize &&alignof(T)<=kAlignment &&kAlignment % alignof(T)==0 &&std::is_nothrow_move_constructible< T >::value > IsStoredLocally
void EmptyManager(FunctionToCall, TypeErasedState *, TypeErasedState *) noexcept
typename UnwrapStdReferenceWrapperImpl< T >::type UnwrapStdReferenceWrapper
ReturnType(TypeErasedState *, ForwardedParameterType< P >...) ABSL_INTERNAL_NOEXCEPT_SPEC(SigIsNoexcept) InvokerType
#define ABSL_FALLTHROUGH_INTENDED
std::function< Poll< absl::StatusOr< T > >()> P
@ kCompatibleAnyInvocable
invoke_result_t< F, Args... > invoke(F &&f, Args &&... args)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:41