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
//
// 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;
}
......
......@@ -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
......
......@@ -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
......
......@@ -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);
......
......@@ -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;
};
......
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