Commit 6a19ff47 by Lawrence Wolf-Sonkin Committed by Copybara-Service

[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
parent 1ac355bb
...@@ -90,7 +90,7 @@ ABSL_NAMESPACE_BEGIN ...@@ -90,7 +90,7 @@ ABSL_NAMESPACE_BEGIN
// //
// Such implicit cast chaining may be useful within template logic. // Such implicit cast chaining may be useful within template logic.
template <typename To> 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; return to;
} }
......
...@@ -22,13 +22,15 @@ namespace absl { ...@@ -22,13 +22,15 @@ namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace internal { namespace internal {
// This is a back-fill of C++20's `std::type_identity`.
template <typename T> template <typename T>
struct identity { struct type_identity {
typedef T type; typedef T type;
}; };
// This is a back-fill of C++20's `std::type_identity_t`.
template <typename T> template <typename T>
using identity_t = typename identity<T>::type; using type_identity_t = typename type_identity<T>::type;
} // namespace internal } // namespace internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
......
...@@ -63,12 +63,12 @@ ...@@ -63,12 +63,12 @@
// Bug: https://bugs.llvm.org/show_bug.cgi?id=35862 // Bug: https://bugs.llvm.org/show_bug.cgi?id=35862
// //
// Note: // 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 // appropriate place for pointer types, reference types, function pointer
// types, etc.. // types, etc..
#if defined(__clang__) #if defined(__clang__)
#define ABSL_INTERNAL_EXTERN_DECL(type, name) \ #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. #else // Otherwise, just define the macro to do nothing.
#define ABSL_INTERNAL_EXTERN_DECL(type, name) #define ABSL_INTERNAL_EXTERN_DECL(type, name)
#endif // defined(__clang__) #endif // defined(__clang__)
...@@ -76,30 +76,31 @@ ...@@ -76,30 +76,31 @@
// See above comment at top of file for details. // See above comment at top of file for details.
#define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \ #define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \
ABSL_INTERNAL_EXTERN_DECL(type, name) \ 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 #else
// See above comment at top of file for details. // See above comment at top of file for details.
// //
// Note: // 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 // appropriate place for pointer types, reference types, function pointer
// types, etc.. // types, etc..
#define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \ #define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \
template <class /*AbslInternalDummy*/ = void> \ template <class /*AbslInternalDummy*/ = void> \
struct AbslInternalInlineVariableHolder##name { \ struct AbslInternalInlineVariableHolder##name { \
static constexpr ::absl::internal::identity_t<var_type> kInstance = init; \ static constexpr ::absl::internal::type_identity_t<var_type> kInstance = \
}; \ init; \
\ }; \
template <class AbslInternalDummy> \ \
constexpr ::absl::internal::identity_t<var_type> \ template <class AbslInternalDummy> \
AbslInternalInlineVariableHolder##name<AbslInternalDummy>::kInstance; \ constexpr ::absl::internal::type_identity_t<var_type> \
\ AbslInternalInlineVariableHolder##name<AbslInternalDummy>::kInstance; \
static constexpr const ::absl::internal::identity_t<var_type>& \ \
name = /* NOLINT */ \ static constexpr const ::absl::internal::type_identity_t<var_type>& \
AbslInternalInlineVariableHolder##name<>::kInstance; \ name = /* NOLINT */ \
static_assert(sizeof(void (*)(decltype(name))) != 0, \ AbslInternalInlineVariableHolder##name<>::kInstance; \
static_assert(sizeof(void (*)(decltype(name))) != 0, \
"Silence unused variable warnings.") "Silence unused variable warnings.")
#endif // __cpp_inline_variables #endif // __cpp_inline_variables
......
...@@ -740,23 +740,25 @@ class Condition { ...@@ -740,23 +740,25 @@ class Condition {
// a function template is passed as `func`. Also, the dummy `typename = void` // a function template is passed as `func`. Also, the dummy `typename = void`
// template parameter exists just to work around a MSVC mangling bug. // template parameter exists just to work around a MSVC mangling bug.
template <typename T, typename = void> 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`. // Templated version for invoking a method that returns a `bool`.
// //
// `Condition(object, &Class::Method)` constructs a `Condition` that evaluates // `Condition(object, &Class::Method)` constructs a `Condition` that evaluates
// `object->Method()`. // `object->Method()`.
// //
// Implementation Note: `absl::internal::identity` is used to allow methods to // Implementation Note: `absl::internal::type_identity` is used to allow
// come from base classes. A simpler signature like // methods to come from base classes. A simpler signature like
// `Condition(T*, bool (T::*)())` does not suffice. // `Condition(T*, bool (T::*)())` does not suffice.
template <typename T> 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 // Same as above, for const members
template <typename T> template <typename T>
Condition(const T* object, 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` // A Condition that returns the value of `*cond`
explicit Condition(const bool* cond); explicit Condition(const bool* cond);
...@@ -1107,14 +1109,14 @@ inline Condition::Condition(bool (*func)(T*), T* arg) ...@@ -1107,14 +1109,14 @@ inline Condition::Condition(bool (*func)(T*), T* arg)
} }
template <typename T, typename> template <typename T, typename>
inline Condition::Condition(bool (*func)(T*), inline Condition::Condition(
typename absl::internal::identity<T>::type* arg) bool (*func)(T*), typename absl::internal::type_identity<T>::type* arg)
// Just delegate to the overload above. // Just delegate to the overload above.
: Condition(func, arg) {} : Condition(func, arg) {}
template <typename T> template <typename T>
inline Condition::Condition(T* object, inline Condition::Condition(
bool (absl::internal::identity<T>::type::*method)()) T* object, bool (absl::internal::type_identity<T>::type::*method)())
: eval_(&CastAndCallMethod<T, decltype(method)>), arg_(object) { : eval_(&CastAndCallMethod<T, decltype(method)>), arg_(object) {
static_assert(sizeof(&method) <= sizeof(callback_), static_assert(sizeof(&method) <= sizeof(callback_),
"An overlarge method pointer was passed to Condition."); "An overlarge method pointer was passed to Condition.");
...@@ -1122,9 +1124,9 @@ inline Condition::Condition(T* object, ...@@ -1122,9 +1124,9 @@ inline Condition::Condition(T* object,
} }
template <typename T> template <typename T>
inline Condition::Condition(const T* object, inline Condition::Condition(
bool (absl::internal::identity<T>::type::*method)() const T* object,
const) bool (absl::internal::type_identity<T>::type::*method)() const)
: eval_(&CastAndCallMethod<const T, decltype(method)>), : eval_(&CastAndCallMethod<const T, decltype(method)>),
arg_(reinterpret_cast<void*>(const_cast<T*>(object))) { arg_(reinterpret_cast<void*>(const_cast<T*>(object))) {
StoreCallback(method); StoreCallback(method);
......
...@@ -1047,11 +1047,11 @@ class VariantStateBase { ...@@ -1047,11 +1047,11 @@ class VariantStateBase {
std::size_t index_; std::size_t index_;
}; };
using absl::internal::identity; using absl::internal::type_identity;
// OverloadSet::Overload() is a unary function which is overloaded to // OverloadSet::Overload() is a unary function which is overloaded to
// take any of the element types of the variant, by reference-to-const. // 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. // can statically determine which overload was called.
// //
// Overload() is not defined, so it can only be called in unevaluated // Overload() is not defined, so it can only be called in unevaluated
...@@ -1062,7 +1062,7 @@ struct OverloadSet; ...@@ -1062,7 +1062,7 @@ struct OverloadSet;
template <typename T, typename... Ts> template <typename T, typename... Ts>
struct OverloadSet<T, Ts...> : OverloadSet<Ts...> { struct OverloadSet<T, Ts...> : OverloadSet<Ts...> {
using Base = OverloadSet<Ts...>; using Base = OverloadSet<Ts...>;
static identity<T> Overload(const T&); static type_identity<T> Overload(const T&);
using Base::Overload; using Base::Overload;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment