mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Deprecate and inline historical functions in Abseil
Migrates uses of absl:: symbols to std:: symbols PiperOrigin-RevId: 914475818 Change-Id: I35908b9d91b4fba465b9fe3e5b2c8f497f2f192b
This commit is contained in:
committed by
Copybara-Service
parent
bc5e9d0ce0
commit
d4aba0a323
@@ -41,6 +41,7 @@ cc_library(
|
||||
linkopts = ABSL_DEFAULT_LINKOPTS,
|
||||
deps = [
|
||||
"//absl/base:config",
|
||||
"//absl/base:core_headers",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ absl_cc_library(
|
||||
${ABSL_DEFAULT_COPTS}
|
||||
DEPS
|
||||
absl::config
|
||||
absl::core_headers
|
||||
PUBLIC
|
||||
)
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/macros.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
@@ -40,8 +41,39 @@ ABSL_NAMESPACE_BEGIN
|
||||
//
|
||||
// See the documentation for the STL <algorithm> header for more information:
|
||||
// https://en.cppreference.com/w/cpp/header/algorithm
|
||||
using std::equal;
|
||||
using std::rotate;
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) {
|
||||
return std::equal(first1, last1, first2);
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class BinaryPredicate>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2,
|
||||
BinaryPredicate p) {
|
||||
return std::equal(first1, last1, first2, p);
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2,
|
||||
InputIt2 last2) {
|
||||
return std::equal(first1, last1, first2, last2);
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class BinaryPredicate>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2,
|
||||
InputIt2 last2, BinaryPredicate p) {
|
||||
return std::equal(first1, last1, first2, last2, p);
|
||||
}
|
||||
|
||||
template <class ForwardIt>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr ForwardIt rotate(ForwardIt first, ForwardIt n_first, ForwardIt last) {
|
||||
return std::rotate(first, n_first, last);
|
||||
}
|
||||
|
||||
// linear_search()
|
||||
//
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
@@ -147,7 +148,7 @@ HashtablezInfo* SampleSlow(SamplingState& next_sample,
|
||||
size_t value_size, uint16_t soo_capacity) {
|
||||
if (ABSL_PREDICT_FALSE(ShouldForceSampling())) {
|
||||
next_sample.next_sample = 1;
|
||||
const int64_t old_stride = exchange(next_sample.sample_stride, 1);
|
||||
const int64_t old_stride = std::exchange(next_sample.sample_stride, 1);
|
||||
HashtablezInfo* result = GlobalHashtablezSampler().Register(
|
||||
old_stride, inline_element_size, key_size, value_size, soo_capacity);
|
||||
return result;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#define ABSL_TYPES_ANY_H_
|
||||
|
||||
#include <any> // IWYU pragma: export
|
||||
#include <initializer_list>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
|
||||
@@ -35,10 +36,30 @@
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
using any ABSL_DEPRECATE_AND_INLINE() = std::any;
|
||||
using std::any_cast;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::any_cast<T>(std::declval<Args>()...))
|
||||
any_cast(Args&&... args) {
|
||||
return std::any_cast<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
using bad_any_cast ABSL_DEPRECATE_AND_INLINE() = std::bad_any_cast;
|
||||
using std::make_any;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::make_any<T>(std::declval<Args>()...))
|
||||
make_any(Args&&... args) {
|
||||
return std::make_any<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::make_any<T>(
|
||||
std::declval<std::initializer_list<U>>(), std::declval<Args>()...))
|
||||
make_any(std::initializer_list<U> il, Args&&... args) {
|
||||
return std::make_any<T>(il, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
|
||||
@@ -37,9 +37,36 @@ ABSL_NAMESPACE_BEGIN
|
||||
using bad_variant_access ABSL_REFACTOR_INLINE
|
||||
= std::bad_variant_access;
|
||||
|
||||
using std::get;
|
||||
using std::get_if;
|
||||
using std::holds_alternative;
|
||||
template <size_t I, typename... Args>
|
||||
[[deprecated]] constexpr auto get(Args&&... args)
|
||||
-> decltype(std::get<I>(std::forward<Args>(args)...)) {
|
||||
return std::get<I>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::get<T>(std::declval<Args>()...)) get(
|
||||
Args&&... args) {
|
||||
return std::get<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <size_t I, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::get_if<I>(std::declval<Args>()...))
|
||||
get_if(Args&&... args) {
|
||||
return std::get_if<I>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::get_if<T>(std::declval<Args>()...))
|
||||
get_if(Args&&... args) {
|
||||
return std::get_if<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::holds_alternative<T>(
|
||||
std::declval<Args>()...))
|
||||
holds_alternative(Args&&... args) {
|
||||
return std::holds_alternative<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
using monostate ABSL_REFACTOR_INLINE
|
||||
= std::monostate;
|
||||
@@ -67,7 +94,11 @@ template <typename T>
|
||||
inline constexpr size_t variant_size_v ABSL_REFACTOR_INLINE
|
||||
= std::variant_size_v<T>;
|
||||
|
||||
using std::visit;
|
||||
template <typename... Args>
|
||||
[[deprecated]] constexpr decltype(std::visit(std::declval<Args>()...)) visit(
|
||||
Args&&... args) {
|
||||
return std::visit(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
namespace variant_internal {
|
||||
// Helper visitor for converting a variant<Ts...>` into another type (mostly
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/macros.h"
|
||||
|
||||
@@ -36,8 +38,27 @@ ABSL_NAMESPACE_BEGIN
|
||||
// platforms are no longer supported. New code should simply use the
|
||||
// the ones from std directly.
|
||||
using std::apply;
|
||||
using std::exchange;
|
||||
using std::forward;
|
||||
|
||||
template <class T1, class T2 = T1>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
constexpr T1 exchange(T1& obj, T2&& new_value) noexcept(
|
||||
noexcept(std::exchange(std::declval<T1&>(), std::declval<T2>()))) {
|
||||
return std::exchange(obj, std::forward<T2>(new_value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
[[deprecated("Use std::forward instead.")]] [[nodiscard]] constexpr T&& forward(
|
||||
std::remove_reference_t<T>& arg ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept {
|
||||
// NOLINTNEXTLINE: Avoid warnings about T not being the spelled type of arg.
|
||||
return std::forward<T>(arg);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
[[deprecated("Use std::forward instead.")]] [[nodiscard]] constexpr T&& forward(
|
||||
std::remove_reference_t<T>&& arg ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept {
|
||||
// NOLINTNEXTLINE: Avoid warnings about T not being the spelled type of arg.
|
||||
return std::forward<T>(arg);
|
||||
}
|
||||
|
||||
inline constexpr const std::in_place_t& in_place ABSL_DEPRECATE_AND_INLINE() =
|
||||
std::in_place;
|
||||
@@ -69,7 +90,13 @@ template <class... T>
|
||||
using index_sequence_for ABSL_DEPRECATE_AND_INLINE() =
|
||||
std::index_sequence_for<T...>;
|
||||
|
||||
using std::make_from_tuple;
|
||||
template <class T, class Tuple>
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
[[nodiscard]] constexpr decltype(std::make_from_tuple<T>(std::declval<Tuple>()))
|
||||
make_from_tuple(Tuple&& arg) noexcept(
|
||||
noexcept(std::make_from_tuple<T>(std::declval<Tuple>()))) {
|
||||
return std::make_from_tuple<T>(std::forward<Tuple>(arg));
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
using make_index_sequence ABSL_DEPRECATE_AND_INLINE() =
|
||||
|
||||
Reference in New Issue
Block a user