[libcxx-commits] [libcxx] 09fa1d0 - [libc++] Introduce __identity_t<T>. NFCI.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 3 19:24:01 PST 2021


Author: Arthur O'Dwyer
Date: 2021-03-03T22:23:14-05:00
New Revision: 09fa1d0e50a3d907e8596f6ea49780b7187b727e

URL: https://github.com/llvm/llvm-project/commit/09fa1d0e50a3d907e8596f6ea49780b7187b727e
DIFF: https://github.com/llvm/llvm-project/commit/09fa1d0e50a3d907e8596f6ea49780b7187b727e.diff

LOG: [libc++] Introduce __identity_t<T>. NFCI.

This is just a shorter synonym for `__identity<T>::type`.
Use it consistently throughout, where possible.

There is still some metaprogramming in <memory> and <variant>
where `__identity` is being used _without_ immediately calling
`::type` on it; but this is the unusual case, and it will become
even less usual as we start deliberately protecting certain types
against deduction (e.g. D97742).

Differential Revision: https://reviews.llvm.org/D97862

Added: 
    

Modified: 
    libcxx/include/map
    libcxx/include/set
    libcxx/include/type_traits
    libcxx/include/unordered_map
    libcxx/include/unordered_set

Removed: 
    


################################################################################
diff  --git a/libcxx/include/map b/libcxx/include/map
index a27002c279ec..6b2d41909579 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -904,8 +904,8 @@ public:
     typedef _Key                                     key_type;
     typedef _Tp                                      mapped_type;
     typedef pair<const key_type, mapped_type>        value_type;
-    typedef typename __identity<_Compare>::type      key_compare;
-    typedef typename __identity<_Allocator>::type    allocator_type;
+    typedef __identity_t<_Compare>                   key_compare;
+    typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
@@ -1674,8 +1674,8 @@ public:
     typedef _Key                                     key_type;
     typedef _Tp                                      mapped_type;
     typedef pair<const key_type, mapped_type>        value_type;
-    typedef typename __identity<_Compare>::type      key_compare;
-    typedef typename __identity<_Allocator>::type    allocator_type;
+    typedef __identity_t<_Compare>                   key_compare;
+    typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 

diff  --git a/libcxx/include/set b/libcxx/include/set
index d58455bfe219..3a83827711f1 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -450,7 +450,7 @@ public:
     typedef key_type                                 value_type;
     typedef _Compare                                 key_compare;
     typedef key_compare                              value_compare;
-    typedef typename __identity<_Allocator>::type    allocator_type;
+    typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
@@ -974,11 +974,11 @@ class _LIBCPP_TEMPLATE_VIS multiset
 {
 public:
     // types:
-    typedef _Key                                      key_type;
+    typedef _Key                                     key_type;
     typedef key_type                                 value_type;
-    typedef _Compare                                  key_compare;
+    typedef _Compare                                 key_compare;
     typedef key_compare                              value_compare;
-    typedef typename __identity<_Allocator>::type    allocator_type;
+    typedef __identity_t<_Allocator>                 allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 

diff  --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index cc88e38e497f..efc5c41c5f9b 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -525,6 +525,9 @@ struct __void_t { typedef void type; };
 template <class _Tp>
 struct __identity { typedef _Tp type; };
 
+template <class _Tp>
+using __identity_t _LIBCPP_NODEBUG_TYPE = typename __identity<_Tp>::type;
+
 template <class _Tp, bool>
 struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
 
@@ -4022,8 +4025,8 @@ struct __result_of_mp;
 
 template <class _MP, class _Tp>
 struct __result_of_mp<_MP, _Tp, true>
-    : public __identity<typename __member_pointer_traits<_MP>::_ReturnType>
 {
+    using type = typename __member_pointer_traits<_MP>::_ReturnType;
 };
 
 // member data pointer
@@ -4034,13 +4037,13 @@ struct __result_of_mdp;
 template <class _Rp, class _Class, class _Tp>
 struct __result_of_mdp<_Rp _Class::*, _Tp, false>
 {
-    typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
+    using type = typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type&;
 };
 
 template <class _Rp, class _Class, class _Tp>
 struct __result_of_mdp<_Rp _Class::*, _Tp, true>
 {
-    typedef typename __apply_cv<_Tp, _Rp>::type& type;
+    using type = typename __apply_cv<_Tp, _Rp>::type&;
 };
 
 template <class _Rp, class _Class, class _Tp>

diff  --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index d595302e633b..83a41148b681 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -920,9 +920,9 @@ public:
     // types
     typedef _Key                                           key_type;
     typedef _Tp                                            mapped_type;
-    typedef typename __identity<_Hash>::type               hasher;
-    typedef typename __identity<_Pred>::type               key_equal;
-    typedef typename __identity<_Alloc>::type              allocator_type;
+    typedef __identity_t<_Hash>                            hasher;
+    typedef __identity_t<_Pred>                            key_equal;
+    typedef __identity_t<_Alloc>                           allocator_type;
     typedef pair<const key_type, mapped_type>              value_type;
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
@@ -1857,9 +1857,9 @@ public:
     // types
     typedef _Key                                           key_type;
     typedef _Tp                                            mapped_type;
-    typedef typename __identity<_Hash>::type               hasher;
-    typedef typename __identity<_Pred>::type               key_equal;
-    typedef typename __identity<_Alloc>::type              allocator_type;
+    typedef __identity_t<_Hash>                            hasher;
+    typedef __identity_t<_Pred>                            key_equal;
+    typedef __identity_t<_Alloc>                           allocator_type;
     typedef pair<const key_type, mapped_type>              value_type;
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;

diff  --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index 80f460d7edaa..8a0f3aacbf30 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -411,9 +411,9 @@ public:
     // types
     typedef _Value                                                     key_type;
     typedef key_type                                                   value_type;
-    typedef typename __identity<_Hash>::type                           hasher;
-    typedef typename __identity<_Pred>::type                           key_equal;
-    typedef typename __identity<_Alloc>::type                          allocator_type;
+    typedef __identity_t<_Hash>                                        hasher;
+    typedef __identity_t<_Pred>                                        key_equal;
+    typedef __identity_t<_Alloc>                                       allocator_type;
     typedef value_type&                                                reference;
     typedef const value_type&                                          const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
@@ -1109,9 +1109,9 @@ public:
     // types
     typedef _Value                                                     key_type;
     typedef key_type                                                   value_type;
-    typedef typename __identity<_Hash>::type                           hasher;
-    typedef typename __identity<_Pred>::type                           key_equal;
-    typedef typename __identity<_Alloc>::type                          allocator_type;
+    typedef __identity_t<_Hash>                                        hasher;
+    typedef __identity_t<_Pred>                                        key_equal;
+    typedef __identity_t<_Alloc>                                       allocator_type;
     typedef value_type&                                                reference;
     typedef const value_type&                                          const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),


        


More information about the libcxx-commits mailing list