35 #ifndef ABSL_BASE_INTERNAL_INVOKE_H_ 36 #define ABSL_BASE_INTERNAL_INVOKE_H_ 39 #include <type_traits> 46 namespace base_internal {
56 template <
typename Derived>
58 template <
typename... Args>
59 struct Accept : Derived::template AcceptImpl<typename std::remove_cv<
60 typename std::remove_reference<Args>::type>::type...> {};
67 template <
typename... Args>
70 template <
typename R,
typename C,
typename... Params,
typename Obj,
73 : std::is_base_of<C, Obj> {};
75 template <
typename R,
typename C,
typename... Params,
typename Obj,
77 struct AcceptImpl<R (C::*)(Params...) const, Obj, Args...>
78 : std::is_base_of<C, Obj> {};
80 template <
typename MemFun,
typename Obj,
typename... Args>
81 static decltype((std::declval<Obj>().*
82 std::declval<MemFun>())(std::declval<Args>()...))
83 Invoke(MemFun&& mem_fun, Obj&& obj, Args&&... args) {
84 return (std::forward<Obj>(obj).*
85 std::forward<MemFun>(mem_fun))(std::forward<Args>(args)...);
92 template <
typename... Args>
95 template <
typename R,
typename C,
typename... Params,
typename Ptr,
98 : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {};
100 template <
typename R,
typename C,
typename... Params,
typename Ptr,
103 : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {};
105 template <
typename MemFun,
typename Ptr,
typename... Args>
106 static decltype(((*std::declval<Ptr>()).*
107 std::declval<MemFun>())(std::declval<Args>()...))
109 return ((*std::forward<Ptr>(ptr)).*
110 std::forward<MemFun>(mem_fun))(std::forward<Args>(args)...);
118 template <
typename... Args>
121 template <
typename R,
typename C,
typename Obj>
124 template <
typename DataMem,
typename Ref>
125 static decltype(std::declval<Ref>().*std::declval<DataMem>())
Invoke(
126 DataMem&& data_mem, Ref&& ref) {
127 return std::forward<Ref>(ref).*std::forward<DataMem>(data_mem);
134 template <
typename... Args>
137 template <
typename R,
typename C,
typename Ptr>
139 : std::integral_constant<bool, !std::is_base_of<C, Ptr>::value> {};
141 template <
typename DataMem,
typename Ptr>
142 static decltype((*std::declval<Ptr>()).*std::declval<DataMem>())
Invoke(
143 DataMem&& data_mem, Ptr&&
ptr) {
144 return (*std::forward<Ptr>(ptr)).*std::forward<DataMem>(data_mem);
152 template <
typename F,
typename... Args>
153 static decltype(std::declval<F>()(std::declval<Args>()...))
Invoke(
154 F&& f, Args&&... args) {
155 return std::forward<F>(f)(std::forward<Args>(args)...);
160 template <
typename... Args>
162 typedef typename std::conditional<
164 typename std::conditional<
166 typename std::conditional<
168 typename std::conditional<DataMemAndPtr::Accept<Args...>
::value,
174 template <
typename F,
typename... Args>
176 std::declval<F>(), std::declval<Args>()...));
180 template <
typename F,
typename... Args>
181 InvokeT<F, Args...>
Invoke(F&& f, Args&&... args) {
183 std::forward<Args>(args)...);
188 #endif // ABSL_BASE_INTERNAL_INVOKE_H_
std::conditional< MemFunAndRef::Accept< Args... >::value, MemFunAndRef, typename std::conditional< MemFunAndPtr::Accept< Args... >::value, MemFunAndPtr, typename std::conditional< DataMemAndRef::Accept< Args... >::value, DataMemAndRef, typename std::conditional< DataMemAndPtr::Accept< Args... >::value, DataMemAndPtr, Callable >::type >::type >::type >::type type
InvokeT< F, Args... > Invoke(F &&f, Args &&... args)
decltype(Invoker< F, Args... >::type::Invoke(std::declval< F >(), std::declval< Args >()...)) InvokeT