Skip to content

Commit 60d29be

Browse files
dinordcopybara-github
authored andcommitted
absl: Replace base_internal::{invoke,invoke_result_t,is_invocable_r} with std equivalents
Now that Abseil only supports C++17 and beyond, these `base_internal` symbols [are just aliases](https://github.com/abseil/abseil-cpp/blob/05e72a328599d71d095e0ff591540e7ddec4f7a7/absl/base/internal/invoke.h#L42) in C++ >= 17. Replacing them in `Abseil`'s internals will allow us to delete `absl/base/internal/invoke.h`. PiperOrigin-RevId: 726051909 Change-Id: Ic571307c6e11d7b3e2a380255bd4c9be98e232f9
1 parent ae4b0c5 commit 60d29be

File tree

15 files changed

+39
-69
lines changed

15 files changed

+39
-69
lines changed

absl/base/call_once.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "absl/base/attributes.h"
3535
#include "absl/base/config.h"
36-
#include "absl/base/internal/invoke.h"
3736
#include "absl/base/internal/low_level_scheduling.h"
3837
#include "absl/base/internal/raw_logging.h"
3938
#include "absl/base/internal/scheduling_mode.h"
@@ -181,8 +180,7 @@ template <typename Callable, typename... Args>
181180
std::memory_order_relaxed) ||
182181
base_internal::SpinLockWait(control, ABSL_ARRAYSIZE(trans), trans,
183182
scheduling_mode) == kOnceInit) {
184-
base_internal::invoke(std::forward<Callable>(fn),
185-
std::forward<Args>(args)...);
183+
std::invoke(std::forward<Callable>(fn), std::forward<Args>(args)...);
186184
old_control =
187185
control->exchange(base_internal::kOnceDone, std::memory_order_release);
188186
if (old_control == base_internal::kOnceWaiter) {

absl/cleanup/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ cc_library(
3636
copts = ABSL_DEFAULT_COPTS,
3737
linkopts = ABSL_DEFAULT_LINKOPTS,
3838
deps = [
39-
"//absl/base:base_internal",
4039
"//absl/base:core_headers",
4140
"//absl/utility",
4241
],

absl/cleanup/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ absl_cc_library(
2121
COPTS
2222
${ABSL_DEFAULT_COPTS}
2323
DEPS
24-
absl::base_internal
2524
absl::core_headers
2625
absl::utility
2726
PUBLIC

absl/cleanup/internal/cleanup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <type_traits>
2020
#include <utility>
2121

22-
#include "absl/base/internal/invoke.h"
2322
#include "absl/base/macros.h"
2423
#include "absl/base/thread_annotations.h"
2524
#include "absl/utility/utility.h"
@@ -39,7 +38,7 @@ constexpr bool WasDeduced() {
3938

4039
template <typename Callback>
4140
constexpr bool ReturnsVoid() {
42-
return (std::is_same<base_internal::invoke_result_t<Callback>, void>::value);
41+
return (std::is_same<std::invoke_result_t<Callback>, void>::value);
4342
}
4443

4544
template <typename Callback>

absl/functional/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ cc_library(
3939
copts = ABSL_DEFAULT_COPTS,
4040
linkopts = ABSL_DEFAULT_LINKOPTS,
4141
deps = [
42-
"//absl/base:base_internal",
4342
"//absl/base:config",
4443
"//absl/base:core_headers",
4544
"//absl/meta:type_traits",
@@ -57,7 +56,6 @@ cc_test(
5756
linkopts = ABSL_DEFAULT_LINKOPTS,
5857
deps = [
5958
":any_invocable",
60-
"//absl/base:base_internal",
6159
"//absl/base:config",
6260
"//absl/base:core_headers",
6361
"//absl/meta:type_traits",
@@ -74,7 +72,6 @@ cc_library(
7472
copts = ABSL_DEFAULT_COPTS,
7573
linkopts = ABSL_DEFAULT_LINKOPTS,
7674
deps = [
77-
"//absl/base:base_internal",
7875
"//absl/container:compressed_tuple",
7976
"//absl/meta:type_traits",
8077
"//absl/utility",
@@ -102,7 +99,6 @@ cc_library(
10299
linkopts = ABSL_DEFAULT_LINKOPTS,
103100
deps = [
104101
":any_invocable",
105-
"//absl/base:base_internal",
106102
"//absl/base:core_headers",
107103
"//absl/meta:type_traits",
108104
],

absl/functional/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ absl_cc_library(
2424
COPTS
2525
${ABSL_DEFAULT_COPTS}
2626
DEPS
27-
absl::base_internal
2827
absl::config
2928
absl::core_headers
3029
absl::type_traits
@@ -42,7 +41,6 @@ absl_cc_test(
4241
${ABSL_TEST_COPTS}
4342
DEPS
4443
absl::any_invocable
45-
absl::base_internal
4644
absl::config
4745
absl::core_headers
4846
absl::type_traits
@@ -60,7 +58,6 @@ absl_cc_library(
6058
COPTS
6159
${ABSL_DEFAULT_COPTS}
6260
DEPS
63-
absl::base_internal
6461
absl::compressed_tuple
6562
PUBLIC
6663
)
@@ -88,7 +85,6 @@ absl_cc_library(
8885
COPTS
8986
${ABSL_DEFAULT_COPTS}
9087
DEPS
91-
absl::base_internal
9288
absl::core_headers
9389
absl::any_invocable
9490
absl::meta

absl/functional/function_ref.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class FunctionRef<R(Args...)> {
9191
private:
9292
// Used to disable constructors for objects that are not compatible with the
9393
// signature of this FunctionRef.
94-
template <typename F,
95-
typename FR = absl::base_internal::invoke_result_t<F, Args&&...>>
94+
template <typename F, typename FR = std::invoke_result_t<F, Args&&...>>
9695
using EnableIfCompatible =
9796
typename std::enable_if<std::is_void<R>::value ||
9897
std::is_convertible<FR, R>::value>::type;

absl/functional/internal/any_invocable.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
#include "absl/base/attributes.h"
6767
#include "absl/base/config.h"
68-
#include "absl/base/internal/invoke.h"
6968
#include "absl/base/macros.h"
7069
#include "absl/base/optimization.h"
7170
#include "absl/meta/type_traits.h"
@@ -123,7 +122,7 @@ using RemoveCVRef =
123122
template <class ReturnType, class F, class... P,
124123
typename = absl::enable_if_t<std::is_void<ReturnType>::value>>
125124
void InvokeR(F&& f, P&&... args) {
126-
absl::base_internal::invoke(std::forward<F>(f), std::forward<P>(args)...);
125+
std::invoke(std::forward<F>(f), std::forward<P>(args)...);
127126
}
128127

129128
template <class ReturnType, class F, class... P,
@@ -134,8 +133,7 @@ ReturnType InvokeR(F&& f, P&&... args) {
134133
#pragma GCC diagnostic push
135134
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
136135
#endif
137-
return absl::base_internal::invoke(std::forward<F>(f),
138-
std::forward<P>(args)...);
136+
return std::invoke(std::forward<F>(f), std::forward<P>(args)...);
139137
#if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
140138
#pragma GCC diagnostic pop
141139
#endif
@@ -714,7 +712,7 @@ using CanAssignReferenceWrapper = TrueAlias<
714712
UnwrapStdReferenceWrapper<absl::decay_t<F>> inv_quals, P...>, \
715713
std::is_same< \
716714
ReturnType, \
717-
absl::base_internal::invoke_result_t< \
715+
std::invoke_result_t< \
718716
UnwrapStdReferenceWrapper<absl::decay_t<F>> inv_quals, \
719717
P...>>>>::value>
720718

@@ -730,10 +728,10 @@ using CanAssignReferenceWrapper = TrueAlias<
730728
// noex is "true" if the function type is noexcept, or false if it is not.
731729
//
732730
// The CallIsValid condition is more complicated than simply using
733-
// absl::base_internal::is_invocable_r because we can't rely on it to give the
734-
// right result when ReturnType is non-moveable in toolchains that don't treat
735-
// non-moveable result types correctly. For example this was the case in libc++
736-
// before commit c3a24882 (2022-05).
731+
// std::is_invocable_r because we can't rely on it to give the right result
732+
// when ReturnType is non-moveable in toolchains that don't treat non-moveable
733+
// result types correctly. For example this was the case in libc++ before commit
734+
// c3a24882 (2022-05).
737735
#define ABSL_INTERNAL_ANY_INVOCABLE_IMPL_(cv, ref, inv_quals, noex) \
738736
template <class ReturnType, class... P> \
739737
class Impl<ReturnType(P...) cv ref noexcept(noex)> \
@@ -745,11 +743,10 @@ using CanAssignReferenceWrapper = TrueAlias<
745743
/*SFINAE constraint to check if F is invocable with the proper signature*/ \
746744
template <class F> \
747745
using CallIsValid = TrueAlias<absl::enable_if_t<absl::disjunction< \
748-
absl::base_internal::is_invocable_r<ReturnType, \
749-
absl::decay_t<F> inv_quals, P...>, \
750-
std::is_same<ReturnType, \
751-
absl::base_internal::invoke_result_t< \
752-
absl::decay_t<F> inv_quals, P...>>>::value>>; \
746+
std::is_invocable_r<ReturnType, absl::decay_t<F> inv_quals, P...>, \
747+
std::is_same< \
748+
ReturnType, \
749+
std::invoke_result_t<absl::decay_t<F> inv_quals, P...>>>::value>>; \
753750
\
754751
/*SFINAE constraint to check if F is nothrow-invocable when necessary*/ \
755752
template <class F> \

absl/functional/internal/front_binder.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <type_traits>
2222
#include <utility>
2323

24-
#include "absl/base/internal/invoke.h"
2524
#include "absl/container/internal/compressed_tuple.h"
2625
#include "absl/meta/type_traits.h"
2726
#include "absl/utility/utility.h"
@@ -33,9 +32,8 @@ namespace functional_internal {
3332
// Invoke the method, expanding the tuple of bound arguments.
3433
template <class R, class Tuple, size_t... Idx, class... Args>
3534
R Apply(Tuple&& bound, absl::index_sequence<Idx...>, Args&&... free) {
36-
return base_internal::invoke(
37-
std::forward<Tuple>(bound).template get<Idx>()...,
38-
std::forward<Args>(free)...);
35+
return std::invoke(std::forward<Tuple>(bound).template get<Idx>()...,
36+
std::forward<Args>(free)...);
3937
}
4038

4139
template <class F, class... BoundArgs>
@@ -50,23 +48,23 @@ class FrontBinder {
5048
constexpr explicit FrontBinder(absl::in_place_t, Ts&&... ts)
5149
: bound_args_(std::forward<Ts>(ts)...) {}
5250

53-
template <class... FreeArgs, class R = base_internal::invoke_result_t<
54-
F&, BoundArgs&..., FreeArgs&&...>>
51+
template <class... FreeArgs,
52+
class R = std::invoke_result_t<F&, BoundArgs&..., FreeArgs&&...>>
5553
R operator()(FreeArgs&&... free_args) & {
5654
return functional_internal::Apply<R>(bound_args_, Idx(),
5755
std::forward<FreeArgs>(free_args)...);
5856
}
5957

6058
template <class... FreeArgs,
61-
class R = base_internal::invoke_result_t<
62-
const F&, const BoundArgs&..., FreeArgs&&...>>
59+
class R = std::invoke_result_t<const F&, const BoundArgs&...,
60+
FreeArgs&&...>>
6361
R operator()(FreeArgs&&... free_args) const& {
6462
return functional_internal::Apply<R>(bound_args_, Idx(),
6563
std::forward<FreeArgs>(free_args)...);
6664
}
6765

68-
template <class... FreeArgs, class R = base_internal::invoke_result_t<
69-
F&&, BoundArgs&&..., FreeArgs&&...>>
66+
template <class... FreeArgs,
67+
class R = std::invoke_result_t<F&&, BoundArgs&&..., FreeArgs&&...>>
7068
R operator()(FreeArgs&&... free_args) && {
7169
// This overload is called when *this is an rvalue. If some of the bound
7270
// arguments are stored by value or rvalue reference, we move them.
@@ -75,8 +73,8 @@ class FrontBinder {
7573
}
7674

7775
template <class... FreeArgs,
78-
class R = base_internal::invoke_result_t<
79-
const F&&, const BoundArgs&&..., FreeArgs&&...>>
76+
class R = std::invoke_result_t<const F&&, const BoundArgs&&...,
77+
FreeArgs&&...>>
8078
R operator()(FreeArgs&&... free_args) const&& {
8179
// This overload is called when *this is an rvalue. If some of the bound
8280
// arguments are stored by value or rvalue reference, we move them.

absl/functional/internal/function_ref.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <functional>
2020
#include <type_traits>
2121

22-
#include "absl/base/internal/invoke.h"
2322
#include "absl/functional/any_invocable.h"
2423
#include "absl/meta/type_traits.h"
2524

@@ -74,15 +73,13 @@ using Invoker = R (*)(VoidPtr, typename ForwardT<Args>::type...);
7473
template <typename Obj, typename R, typename... Args>
7574
R InvokeObject(VoidPtr ptr, typename ForwardT<Args>::type... args) {
7675
auto o = static_cast<const Obj*>(ptr.obj);
77-
return static_cast<R>(
78-
absl::base_internal::invoke(*o, std::forward<Args>(args)...));
76+
return static_cast<R>(std::invoke(*o, std::forward<Args>(args)...));
7977
}
8078

8179
template <typename Fun, typename R, typename... Args>
8280
R InvokeFunction(VoidPtr ptr, typename ForwardT<Args>::type... args) {
8381
auto f = reinterpret_cast<Fun>(ptr.fun);
84-
return static_cast<R>(
85-
absl::base_internal::invoke(f, std::forward<Args>(args)...));
82+
return static_cast<R>(std::invoke(f, std::forward<Args>(args)...));
8683
}
8784

8885
template <typename Sig>

0 commit comments

Comments
 (0)