summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Lawrence Wolf-Sonkin <lawrencews@google.com>2023-12-28 14:26:18 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-28 14:27:14 -0800
commit6a19ff47352a2112e953f4ab813d820e0ecfe1e3 (patch)
treed0b376cb1109364175b38d300069bafb618e5cdd /absl
parent1ac355bbb7e1e3c7916d812976127cf15c411bd3 (diff)
[absl] Rename `absl::internal::identity` to `absl::internal::type_identity`
* Also does this for `absl::internal::identity_t` which is now `absl::internal::type_identity_t` * This is clearer naming as this is a backfill of `std::type_identity` (the identity type), and not `std::identity` (the identity function) PiperOrigin-RevId: 594316002 Change-Id: I5fb8cf7e3d07c1bc736cbecd202e7d556b6ea33e
Diffstat (limited to 'absl')
-rw-r--r--absl/base/casts.h2
-rw-r--r--absl/base/internal/identity.h6
-rw-r--r--absl/base/internal/inline_variable.h37
-rw-r--r--absl/synchronization/mutex.h26
-rw-r--r--absl/types/internal/variant.h6
5 files changed, 41 insertions, 36 deletions
diff --git a/absl/base/casts.h b/absl/base/casts.h
index d1958885..e0b11bbe 100644
--- a/absl/base/casts.h
+++ b/absl/base/casts.h
@@ -90,7 +90,7 @@ ABSL_NAMESPACE_BEGIN
//
// Such implicit cast chaining may be useful within template logic.
template <typename To>
-constexpr To implicit_cast(typename absl::internal::identity_t<To> to) {
+constexpr To implicit_cast(typename absl::internal::type_identity_t<To> to) {
return to;
}
diff --git a/absl/base/internal/identity.h b/absl/base/internal/identity.h
index a3154ed7..365207b7 100644
--- a/absl/base/internal/identity.h
+++ b/absl/base/internal/identity.h
@@ -22,13 +22,15 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace internal {
+// This is a back-fill of C++20's `std::type_identity`.
template <typename T>
-struct identity {
+struct type_identity {
typedef T type;
};
+// This is a back-fill of C++20's `std::type_identity_t`.
template <typename T>
-using identity_t = typename identity<T>::type;
+using type_identity_t = typename type_identity<T>::type;
} // namespace internal
ABSL_NAMESPACE_END
diff --git a/absl/base/internal/inline_variable.h b/absl/base/internal/inline_variable.h
index df933faf..09daf0f5 100644
--- a/absl/base/internal/inline_variable.h
+++ b/absl/base/internal/inline_variable.h
@@ -63,12 +63,12 @@
// Bug: https://bugs.llvm.org/show_bug.cgi?id=35862
//
// Note:
-// identity_t is used here so that the const and name are in the
+// type_identity_t is used here so that the const and name are in the
// appropriate place for pointer types, reference types, function pointer
// types, etc..
#if defined(__clang__)
#define ABSL_INTERNAL_EXTERN_DECL(type, name) \
- extern const ::absl::internal::identity_t<type> name;
+ extern const ::absl::internal::type_identity_t<type> name;
#else // Otherwise, just define the macro to do nothing.
#define ABSL_INTERNAL_EXTERN_DECL(type, name)
#endif // defined(__clang__)
@@ -76,30 +76,31 @@
// See above comment at top of file for details.
#define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \
ABSL_INTERNAL_EXTERN_DECL(type, name) \
- inline constexpr ::absl::internal::identity_t<type> name = init
+ inline constexpr ::absl::internal::type_identity_t<type> name = init
#else
// See above comment at top of file for details.
//
// Note:
-// identity_t is used here so that the const and name are in the
+// type_identity_t is used here so that the const and name are in the
// appropriate place for pointer types, reference types, function pointer
// types, etc..
-#define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \
- template <class /*AbslInternalDummy*/ = void> \
- struct AbslInternalInlineVariableHolder##name { \
- static constexpr ::absl::internal::identity_t<var_type> kInstance = init; \
- }; \
- \
- template <class AbslInternalDummy> \
- constexpr ::absl::internal::identity_t<var_type> \
- AbslInternalInlineVariableHolder##name<AbslInternalDummy>::kInstance; \
- \
- static constexpr const ::absl::internal::identity_t<var_type>& \
- name = /* NOLINT */ \
- AbslInternalInlineVariableHolder##name<>::kInstance; \
- static_assert(sizeof(void (*)(decltype(name))) != 0, \
+#define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \
+ template <class /*AbslInternalDummy*/ = void> \
+ struct AbslInternalInlineVariableHolder##name { \
+ static constexpr ::absl::internal::type_identity_t<var_type> kInstance = \
+ init; \
+ }; \
+ \
+ template <class AbslInternalDummy> \
+ constexpr ::absl::internal::type_identity_t<var_type> \
+ AbslInternalInlineVariableHolder##name<AbslInternalDummy>::kInstance; \
+ \
+ static constexpr const ::absl::internal::type_identity_t<var_type>& \
+ name = /* NOLINT */ \
+ AbslInternalInlineVariableHolder##name<>::kInstance; \
+ static_assert(sizeof(void (*)(decltype(name))) != 0, \
"Silence unused variable warnings.")
#endif // __cpp_inline_variables
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index 85e8d0e0..d53a22bb 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -740,23 +740,25 @@ class Condition {
// a function template is passed as `func`. Also, the dummy `typename = void`
// template parameter exists just to work around a MSVC mangling bug.
template <typename T, typename = void>
- Condition(bool (*func)(T*), typename absl::internal::identity<T>::type* arg);
+ Condition(bool (*func)(T*),
+ typename absl::internal::type_identity<T>::type* arg);
// Templated version for invoking a method that returns a `bool`.
//
// `Condition(object, &Class::Method)` constructs a `Condition` that evaluates
// `object->Method()`.
//
- // Implementation Note: `absl::internal::identity` is used to allow methods to
- // come from base classes. A simpler signature like
+ // Implementation Note: `absl::internal::type_identity` is used to allow
+ // methods to come from base classes. A simpler signature like
// `Condition(T*, bool (T::*)())` does not suffice.
template <typename T>
- Condition(T* object, bool (absl::internal::identity<T>::type::*method)());
+ Condition(T* object,
+ bool (absl::internal::type_identity<T>::type::*method)());
// Same as above, for const members
template <typename T>
Condition(const T* object,
- bool (absl::internal::identity<T>::type::*method)() const);
+ bool (absl::internal::type_identity<T>::type::*method)() const);
// A Condition that returns the value of `*cond`
explicit Condition(const bool* cond);
@@ -1107,14 +1109,14 @@ inline Condition::Condition(bool (*func)(T*), T* arg)
}
template <typename T, typename>
-inline Condition::Condition(bool (*func)(T*),
- typename absl::internal::identity<T>::type* arg)
+inline Condition::Condition(
+ bool (*func)(T*), typename absl::internal::type_identity<T>::type* arg)
// Just delegate to the overload above.
: Condition(func, arg) {}
template <typename T>
-inline Condition::Condition(T* object,
- bool (absl::internal::identity<T>::type::*method)())
+inline Condition::Condition(
+ T* object, bool (absl::internal::type_identity<T>::type::*method)())
: eval_(&CastAndCallMethod<T, decltype(method)>), arg_(object) {
static_assert(sizeof(&method) <= sizeof(callback_),
"An overlarge method pointer was passed to Condition.");
@@ -1122,9 +1124,9 @@ inline Condition::Condition(T* object,
}
template <typename T>
-inline Condition::Condition(const T* object,
- bool (absl::internal::identity<T>::type::*method)()
- const)
+inline Condition::Condition(
+ const T* object,
+ bool (absl::internal::type_identity<T>::type::*method)() const)
: eval_(&CastAndCallMethod<const T, decltype(method)>),
arg_(reinterpret_cast<void*>(const_cast<T*>(object))) {
StoreCallback(method);
diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h
index fc8829e5..263d7b09 100644
--- a/absl/types/internal/variant.h
+++ b/absl/types/internal/variant.h
@@ -1047,11 +1047,11 @@ class VariantStateBase {
std::size_t index_;
};
-using absl::internal::identity;
+using absl::internal::type_identity;
// OverloadSet::Overload() is a unary function which is overloaded to
// take any of the element types of the variant, by reference-to-const.
-// The return type of the overload on T is identity<T>, so that you
+// The return type of the overload on T is type_identity<T>, so that you
// can statically determine which overload was called.
//
// Overload() is not defined, so it can only be called in unevaluated
@@ -1062,7 +1062,7 @@ struct OverloadSet;
template <typename T, typename... Ts>
struct OverloadSet<T, Ts...> : OverloadSet<Ts...> {
using Base = OverloadSet<Ts...>;
- static identity<T> Overload(const T&);
+ static type_identity<T> Overload(const T&);
using Base::Overload;
};