Skip to content

Commit 8e1f92a

Browse files
derekmaurocopybara-github
authored andcommitted
Remove the polyfills for absl::apply and absl::make_from_tuple,
which were only needed prior to C++17. It is recommended that clients simply use std::apply and std::make_from_tuple. PiperOrigin-RevId: 731348450 Change-Id: I7711487c869e229f86304da43272fbade9f7301a
1 parent 35d3560 commit 8e1f92a

File tree

4 files changed

+4
-376
lines changed

4 files changed

+4
-376
lines changed

absl/utility/BUILD.bazel

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ load(
1818
"//absl:copts/configure_copts.bzl",
1919
"ABSL_DEFAULT_COPTS",
2020
"ABSL_DEFAULT_LINKOPTS",
21-
"ABSL_TEST_COPTS",
2221
)
2322

2423
package(
@@ -40,23 +39,7 @@ cc_library(
4039
copts = ABSL_DEFAULT_COPTS,
4140
linkopts = ABSL_DEFAULT_LINKOPTS,
4241
deps = [
43-
"//absl/base:base_internal",
4442
"//absl/base:config",
4543
"//absl/meta:type_traits",
4644
],
4745
)
48-
49-
cc_test(
50-
name = "utility_test",
51-
srcs = ["utility_test.cc"],
52-
copts = ABSL_TEST_COPTS,
53-
linkopts = ABSL_DEFAULT_LINKOPTS,
54-
deps = [
55-
":utility",
56-
"//absl/base:core_headers",
57-
"//absl/memory",
58-
"//absl/strings",
59-
"@googletest//:gtest",
60-
"@googletest//:gtest_main",
61-
],
62-
)

absl/utility/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ absl_cc_library(
2222
COPTS
2323
${ABSL_DEFAULT_COPTS}
2424
DEPS
25-
absl::base_internal
2625
absl::config
2726
absl::type_traits
2827
PUBLIC
2928
)
30-
31-
absl_cc_test(
32-
NAME
33-
utility_test
34-
SRCS
35-
"utility_test.cc"
36-
COPTS
37-
${ABSL_TEST_COPTS}
38-
DEPS
39-
absl::utility
40-
absl::core_headers
41-
absl::memory
42-
absl::strings
43-
GTest::gmock_main
44-
)

absl/utility/utility.h

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
//
15-
// This header file contains C++14 versions of standard <utility> header
16-
// abstractions available within C++17, and are designed to be drop-in
17-
// replacement for code compliant with C++14 and C++17.
18-
//
19-
// The following abstractions are defined:
20-
//
21-
// * apply<Functor, Tuple> == std::apply<Functor, Tuple>
22-
// * exchange<T> == std::exchange<T>
23-
// * make_from_tuple<T> == std::make_from_tuple<T>
24-
//
25-
// References:
26-
//
27-
// https://en.cppreference.com/w/cpp/utility/apply
28-
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3658.html
2914

3015
#ifndef ABSL_UTILITY_UTILITY_H_
3116
#define ABSL_UTILITY_UTILITY_H_
@@ -36,6 +21,8 @@
3621
#include <utility>
3722

3823
#include "absl/base/config.h"
24+
25+
// TODO(b/290784225): Include what you use cleanup required.
3926
#include "absl/meta/type_traits.h"
4027

4128
namespace absl {
@@ -45,6 +32,7 @@ ABSL_NAMESPACE_BEGIN
4532
// abstractions for platforms that had not yet provided them. Those
4633
// platforms are no longer supported. New code should simply use the
4734
// the ones from std directly.
35+
using std::apply;
4836
using std::exchange;
4937
using std::forward;
5038
using std::in_place;
@@ -56,99 +44,11 @@ using std::in_place_type_t;
5644
using std::index_sequence;
5745
using std::index_sequence_for;
5846
using std::integer_sequence;
47+
using std::make_from_tuple;
5948
using std::make_index_sequence;
6049
using std::make_integer_sequence;
6150
using std::move;
6251

63-
namespace utility_internal {
64-
// Helper method for expanding tuple into a called method.
65-
template <typename Functor, typename Tuple, std::size_t... Indexes>
66-
auto apply_helper(Functor&& functor, Tuple&& t, index_sequence<Indexes...>)
67-
-> decltype(std::invoke(absl::forward<Functor>(functor),
68-
std::get<Indexes>(absl::forward<Tuple>(t))...)) {
69-
return std::invoke(absl::forward<Functor>(functor),
70-
std::get<Indexes>(absl::forward<Tuple>(t))...);
71-
}
72-
} // namespace utility_internal
73-
74-
// apply
75-
//
76-
// Invokes a Callable using elements of a tuple as its arguments.
77-
// Each element of the tuple corresponds to an argument of the call (in order).
78-
// Both the Callable argument and the tuple argument are perfect-forwarded.
79-
// For member-function Callables, the first tuple element acts as the `this`
80-
// pointer. `absl::apply` is designed to be a drop-in replacement for C++17's
81-
// `std::apply`. Unlike C++17's `std::apply`, this is not currently `constexpr`.
82-
//
83-
// Example:
84-
//
85-
// class Foo {
86-
// public:
87-
// void Bar(int);
88-
// };
89-
// void user_function1(int, std::string);
90-
// void user_function2(std::unique_ptr<Foo>);
91-
// auto user_lambda = [](int, int) {};
92-
//
93-
// int main()
94-
// {
95-
// std::tuple<int, std::string> tuple1(42, "bar");
96-
// // Invokes the first user function on int, std::string.
97-
// absl::apply(&user_function1, tuple1);
98-
//
99-
// std::tuple<std::unique_ptr<Foo>> tuple2(absl::make_unique<Foo>());
100-
// // Invokes the user function that takes ownership of the unique
101-
// // pointer.
102-
// absl::apply(&user_function2, std::move(tuple2));
103-
//
104-
// auto foo = absl::make_unique<Foo>();
105-
// std::tuple<Foo*, int> tuple3(foo.get(), 42);
106-
// // Invokes the method Bar on foo with one argument, 42.
107-
// absl::apply(&Foo::Bar, tuple3);
108-
//
109-
// std::tuple<int, int> tuple4(8, 9);
110-
// // Invokes a lambda.
111-
// absl::apply(user_lambda, tuple4);
112-
// }
113-
template <typename Functor, typename Tuple>
114-
auto apply(Functor&& functor, Tuple&& t)
115-
-> decltype(utility_internal::apply_helper(
116-
absl::forward<Functor>(functor), absl::forward<Tuple>(t),
117-
absl::make_index_sequence<std::tuple_size<
118-
typename std::remove_reference<Tuple>::type>::value>{})) {
119-
return utility_internal::apply_helper(
120-
absl::forward<Functor>(functor), absl::forward<Tuple>(t),
121-
absl::make_index_sequence<std::tuple_size<
122-
typename std::remove_reference<Tuple>::type>::value>{});
123-
}
124-
125-
namespace utility_internal {
126-
template <typename T, typename Tuple, size_t... I>
127-
T make_from_tuple_impl(Tuple&& tup, absl::index_sequence<I...>) {
128-
return T(std::get<I>(std::forward<Tuple>(tup))...);
129-
}
130-
} // namespace utility_internal
131-
132-
// make_from_tuple
133-
//
134-
// Given the template parameter type `T` and a tuple of arguments
135-
// `std::tuple(arg0, arg1, ..., argN)` constructs an object of type `T` as if by
136-
// calling `T(arg0, arg1, ..., argN)`.
137-
//
138-
// Example:
139-
//
140-
// std::tuple<const char*, size_t> args("hello world", 5);
141-
// auto s = absl::make_from_tuple<std::string>(args);
142-
// assert(s == "hello");
143-
//
144-
template <typename T, typename Tuple>
145-
constexpr T make_from_tuple(Tuple&& tup) {
146-
return utility_internal::make_from_tuple_impl<T>(
147-
std::forward<Tuple>(tup),
148-
absl::make_index_sequence<
149-
std::tuple_size<absl::decay_t<Tuple>>::value>{});
150-
}
151-
15252
ABSL_NAMESPACE_END
15353
} // namespace absl
15454

0 commit comments

Comments
 (0)