summaryrefslogtreecommitdiff
path: root/absl/utility
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2024-04-04 08:04:25 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-04-04 08:05:38 -0700
commit377de9d710c69a8bd6fdfc67ab3aa71d5f987251 (patch)
tree2acd4085735851114aae958dd242c9bd2ea0c955 /absl/utility
parentd5e426097680beafbf72d6c88f50a680736ec770 (diff)
Deprecate `absl::exchange`, `absl::forward` and `absl::move`, which
were only useful before C++14. Callers should use `std::exchange`, `std::forward` and `std::move` instead. One thing to note is that some compilers issue warnings about pessimizing and redundant moves. Some compilers were able to apply this analysis to std::move but not absl::move. If you get a warning about one of these issues now that absl::move is an alias for std::move, you should remove this use of move. See https://developers.redhat.com/blog/2019/04/12/understanding-when-not-to-stdmove-in-c PiperOrigin-RevId: 621861324 Change-Id: I60f98b59be5ff425bd17fbce43d9218c361720c2
Diffstat (limited to 'absl/utility')
-rw-r--r--absl/utility/utility.h44
-rw-r--r--absl/utility/utility_test.cc8
2 files changed, 3 insertions, 49 deletions
diff --git a/absl/utility/utility.h b/absl/utility/utility.h
index fc0d1f65..ebbb49b7 100644
--- a/absl/utility/utility.h
+++ b/absl/utility/utility.h
@@ -51,11 +51,14 @@ ABSL_NAMESPACE_BEGIN
// abstractions for platforms that had not yet provided them. Those
// platforms are no longer supported. New code should simply use the
// the ones from std directly.
+using std::exchange;
+using std::forward;
using std::index_sequence;
using std::index_sequence_for;
using std::integer_sequence;
using std::make_index_sequence;
using std::make_integer_sequence;
+using std::move;
namespace utility_internal {
@@ -129,27 +132,6 @@ template <size_t I>
void in_place_index(utility_internal::InPlaceIndexTag<I>) {}
#endif // ABSL_USES_STD_VARIANT
-// Constexpr move and forward
-
-// move()
-//
-// A constexpr version of `std::move()`, designed to be a drop-in replacement
-// for C++14's `std::move()`.
-template <typename T>
-constexpr absl::remove_reference_t<T>&& move(T&& t) noexcept {
- return static_cast<absl::remove_reference_t<T>&&>(t);
-}
-
-// forward()
-//
-// A constexpr version of `std::forward()`, designed to be a drop-in replacement
-// for C++14's `std::forward()`.
-template <typename T>
-constexpr T&& forward(
- absl::remove_reference_t<T>& t) noexcept { // NOLINT(runtime/references)
- return static_cast<T&&>(t);
-}
-
namespace utility_internal {
// Helper method for expanding tuple into a called method.
template <typename Functor, typename Tuple, std::size_t... Indexes>
@@ -215,26 +197,6 @@ auto apply(Functor&& functor, Tuple&& t)
typename std::remove_reference<Tuple>::type>::value>{});
}
-// exchange
-//
-// Replaces the value of `obj` with `new_value` and returns the old value of
-// `obj`. `absl::exchange` is designed to be a drop-in replacement for C++14's
-// `std::exchange`.
-//
-// Example:
-//
-// Foo& operator=(Foo&& other) {
-// ptr1_ = absl::exchange(other.ptr1_, nullptr);
-// int1_ = absl::exchange(other.int1_, -1);
-// return *this;
-// }
-template <typename T, typename U = T>
-T exchange(T& obj, U&& new_value) {
- T old_value = absl::move(obj);
- obj = absl::forward<U>(new_value);
- return old_value;
-}
-
namespace utility_internal {
template <typename T, typename Tuple, size_t... I>
T make_from_tuple_impl(Tuple&& tup, absl::index_sequence<I...>) {
diff --git a/absl/utility/utility_test.cc b/absl/utility/utility_test.cc
index 1af68136..c540b22f 100644
--- a/absl/utility/utility_test.cc
+++ b/absl/utility/utility_test.cc
@@ -205,14 +205,6 @@ TEST(ApplyTest, FlipFlop) {
EXPECT_EQ(42, absl::apply(&FlipFlop::member, std::make_tuple(obj)));
}
-TEST(ExchangeTest, MoveOnly) {
- auto a = Factory(1);
- EXPECT_EQ(1, *a);
- auto b = absl::exchange(a, Factory(2));
- EXPECT_EQ(2, *a);
- EXPECT_EQ(1, *b);
-}
-
TEST(MakeFromTupleTest, String) {
EXPECT_EQ(
absl::make_from_tuple<std::string>(std::make_tuple("hello world", 5)),