Skip to content

Commit 606690b

Browse files
dinordcopybara-github
authored andcommitted
internal/any_invocable: Implement invocation using if constexpr instead of SFINAE
`if constexpr` is much easier to understand and generates shorter mangled names. Update comment to explain the invoking function in terms of C++23's `std::invoke_r`, instead of the pseudo-macro. PiperOrigin-RevId: 726626068 Change-Id: Icf3e94f35f8c7ca581e8c8005f4537fea987389d
1 parent 84da38f commit 606690b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

absl/functional/internal/any_invocable.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,22 @@ template <class T>
113113
using RemoveCVRef =
114114
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
115115

116-
////////////////////////////////////////////////////////////////////////////////
117-
//
118-
// An implementation of the C++ standard INVOKE<R> pseudo-macro, operation is
119-
// equivalent to std::invoke except that it forces an implicit conversion to the
120-
// specified return type. If "R" is void, the function is executed and the
121-
// return value is simply ignored.
122-
template <class ReturnType, class F, class... P,
123-
typename = absl::enable_if_t<std::is_void<ReturnType>::value>>
124-
void InvokeR(F&& f, P&&... args) {
125-
std::invoke(std::forward<F>(f), std::forward<P>(args)...);
126-
}
127-
128-
template <class ReturnType, class F, class... P,
129-
absl::enable_if_t<!std::is_void<ReturnType>::value, int> = 0>
116+
// An implementation of std::invoke_r of C++23.
117+
template <class ReturnType, class F, class... P>
130118
ReturnType InvokeR(F&& f, P&&... args) {
131-
// GCC 12 has a false-positive -Wmaybe-uninitialized warning here.
119+
if constexpr (std::is_void_v<ReturnType>) {
120+
std::invoke(std::forward<F>(f), std::forward<P>(args)...);
121+
} else {
122+
// GCC 12 has a false-positive -Wmaybe-uninitialized warning here.
132123
#if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
133124
#pragma GCC diagnostic push
134125
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
135126
#endif
136-
return std::invoke(std::forward<F>(f), std::forward<P>(args)...);
127+
return std::invoke(std::forward<F>(f), std::forward<P>(args)...);
137128
#if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
138129
#pragma GCC diagnostic pop
139130
#endif
131+
}
140132
}
141133

142134
//

0 commit comments

Comments
 (0)