From 2c92bdc7c2f8e65198af61a0611d90a55312ee82 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 11 Jun 2020 09:56:29 -0700 Subject: Export of internal Abseil changes -- e21e960918678629abf89ad1b694b7d4a456b434 by Greg Falcon : Roll back invoke() change due to large increases in compiler memory usage. PiperOrigin-RevId: 315919455 -- f95872e1e1d7afdefbac94f42ea228d42d80eb6e by Greg Falcon : Rollback of invoke() changes due to compiler memory usage growth PiperOrigin-RevId: 315911585 -- 6c6c6ba6892016a2ce4703042800254fb9b15727 by Laramie Leavitt : Move some of the common mocking code into MockHelpers. Use MockHelpers to do mock signature detection and improve the dispatch mechansim. PiperOrigin-RevId: 315825988 -- 5e9380367d280c7fa6dbd4d0f48c31ade7f1d419 by Greg Falcon : Rename the internal implementation details Invoke and InvokeT to `invoke` and `invoke_result_t`, since these are re-implementations of C++17 library entites of the same names. PiperOrigin-RevId: 315790467 GitOrigin-RevId: e21e960918678629abf89ad1b694b7d4a456b434 Change-Id: Ia75011f94cb033c1c9a4cb64cf14d283b91426ac --- absl/base/internal/invoke.h | 131 +++++++++++--------------------------------- 1 file changed, 32 insertions(+), 99 deletions(-) (limited to 'absl/base/internal/invoke.h') diff --git a/absl/base/internal/invoke.h b/absl/base/internal/invoke.h index ab5ad910..c4eceebd 100644 --- a/absl/base/internal/invoke.h +++ b/absl/base/internal/invoke.h @@ -18,19 +18,16 @@ // [func.require] // Define INVOKE (f, t1, t2, ..., tN) as follows: // 1. (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T -// and is_base_of_v> is true; -// 2. (t1.get().*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and remove_cvref_t is a specialization of -// reference_wrapper; -// 3. ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and t1 does not satisfy the previous two items; -// 4. t1.*f when N == 1 and f is a pointer to data member of a class T and -// is_base_of_v> is true; -// 5. t1.get().*f when N == 1 and f is a pointer to data member of a class T and -// remove_cvref_t is a specialization of reference_wrapper; -// 6. (*t1).*f when N == 1 and f is a pointer to data member of a class T and t1 -// does not satisfy the previous two items; -// 7. f(t1, t2, ..., tN) in all other cases. +// and t1 is an object of type T or a reference to an object of type T or a +// reference to an object of a type derived from T; +// 2. ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a +// class T and t1 is not one of the types described in the previous item; +// 3. t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is +// an object of type T or a reference to an object of type T or a reference +// to an object of a type derived from T; +// 4. (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 +// is not one of the types described in the previous item; +// 5. f(t1, t2, ..., tN) in all other cases. // // The implementation is SFINAE-friendly: substitution failure within Invoke() // isn't an error. @@ -51,16 +48,7 @@ namespace absl { ABSL_NAMESPACE_BEGIN namespace base_internal { -template -struct IsReferenceWrapper : std::false_type {}; -template -struct IsReferenceWrapper> : std::true_type {}; - -template -using RemoveCvrefT = - typename std::remove_cv::type>::type; - -// The seven classes below each implement one of the clauses from the definition +// The five classes below each implement one of the clauses from the definition // of INVOKE. The inner class template Accept checks whether the // clause is applicable; static function template Invoke(f, args...) does the // invocation. @@ -84,10 +72,9 @@ struct MemFunAndRef : StrippedAccept { template struct AcceptImpl - : std::integral_constant< - bool, std::is_base_of< - C, typename std::remove_reference::type>::value && - absl::is_function::value> {}; + : std::integral_constant::value && + absl::is_function::value> { + }; template static decltype((std::declval().* @@ -98,41 +85,17 @@ struct MemFunAndRef : StrippedAccept { } }; -// (t1.get().*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and remove_cvref_t is a specialization of -// reference_wrapper; -struct MemFunAndRefWrap : StrippedAccept { - template - struct AcceptImpl : std::false_type {}; - - template - struct AcceptImpl - : std::integral_constant< - bool, IsReferenceWrapper>::value && - absl::is_function::value> {}; - - template - static decltype((std::declval().get().* - std::declval())(std::declval()...)) - Invoke(MemFun&& mem_fun, RefWrap&& ref_wrap, Args&&... args) { - return (std::forward(ref_wrap).get().* - std::forward(mem_fun))(std::forward(args)...); - } -}; - // ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a -// class T and t1 does not satisfy the previous two items; +// class T and t1 is not one of the types described in the previous item. struct MemFunAndPtr : StrippedAccept { template struct AcceptImpl : std::false_type {}; template struct AcceptImpl - : std::integral_constant< - bool, !std::is_base_of< - C, typename std::remove_reference::type>::value && - !IsReferenceWrapper>::value && - absl::is_function::value> {}; + : std::integral_constant::value && + absl::is_function::value> { + }; template static decltype(((*std::declval()).* @@ -143,18 +106,17 @@ struct MemFunAndPtr : StrippedAccept { } }; -// t1.*f when N == 1 and f is a pointer to data member of a class T and -// is_base_of_v> is true; +// t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is +// an object of type T or a reference to an object of type T or a reference +// to an object of a type derived from T. struct DataMemAndRef : StrippedAccept { template struct AcceptImpl : std::false_type {}; template struct AcceptImpl - : std::integral_constant< - bool, std::is_base_of< - C, typename std::remove_reference::type>::value && - !absl::is_function::value> {}; + : std::integral_constant::value && + !absl::is_function::value> {}; template static decltype(std::declval().*std::declval()) Invoke( @@ -163,39 +125,16 @@ struct DataMemAndRef : StrippedAccept { } }; -// t1.get().*f when N == 1 and f is a pointer to data member of a class T and -// remove_cvref_t is a specialization of reference_wrapper; -struct DataMemAndRefWrap : StrippedAccept { - template - struct AcceptImpl : std::false_type {}; - - template - struct AcceptImpl - : std::integral_constant< - bool, IsReferenceWrapper>::value && - !absl::is_function::value> {}; - - template - static decltype(std::declval().get().*std::declval()) - Invoke(DataMem&& data_mem, RefWrap&& ref_wrap) { - return std::forward(ref_wrap).get().* - std::forward(data_mem); - } -}; - -// (*t1).*f when N == 1 and f is a pointer to data member of a class T and t1 -// does not satisfy the previous two items; +// (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 +// is not one of the types described in the previous item. struct DataMemAndPtr : StrippedAccept { template struct AcceptImpl : std::false_type {}; template struct AcceptImpl - : std::integral_constant< - bool, !std::is_base_of< - C, typename std::remove_reference::type>::value && - !IsReferenceWrapper>::value && - !absl::is_function::value> {}; + : std::integral_constant::value && + !absl::is_function::value> {}; template static decltype((*std::declval()).*std::declval()) Invoke( @@ -221,18 +160,12 @@ struct Invoker { typedef typename std::conditional< MemFunAndRef::Accept::value, MemFunAndRef, typename std::conditional< - MemFunAndRefWrap::Accept::value, MemFunAndRefWrap, + MemFunAndPtr::Accept::value, MemFunAndPtr, typename std::conditional< - MemFunAndPtr::Accept::value, MemFunAndPtr, - typename std::conditional< - DataMemAndRef::Accept::value, DataMemAndRef, - typename std::conditional< - DataMemAndRefWrap::Accept::value, - DataMemAndRefWrap, - typename std::conditional< - DataMemAndPtr::Accept::value, DataMemAndPtr, - Callable>::type>::type>::type>::type>::type>::type - type; + DataMemAndRef::Accept::value, DataMemAndRef, + typename std::conditional::value, + DataMemAndPtr, Callable>::type>::type>:: + type>::type type; }; // The result type of Invoke. -- cgit v1.2.3