diff options
Diffstat (limited to 'absl/utility')
-rw-r--r-- | absl/utility/utility.h | 44 | ||||
-rw-r--r-- | absl/utility/utility_test.cc | 8 |
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)), |