[libcxx-commits] [libcxx] 3c6bd17 - [libc++] Rename __identity to __type_identity
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 24 17:01:35 PDT 2022
Author: Nikolas Klauser
Date: 2022-03-25T01:01:28+01:00
New Revision: 3c6bd176fb898352aaa03facdd4626af9043884a
URL: https://github.com/llvm/llvm-project/commit/3c6bd176fb898352aaa03facdd4626af9043884a
DIFF: https://github.com/llvm/llvm-project/commit/3c6bd176fb898352aaa03facdd4626af9043884a.diff
LOG: [libc++] Rename __identity to __type_identity
In C++20 the type trait `type_identity` was introduced. For the same purpose there is `__identity` for pre-C++20 code. The name is confusing, because since C++20 there is also `identity`, which isn't a type trait.
Reviewed By: ldionne, Mordante, #libc
Spies: EricWF, libcxx-commits
Differential Revision: https://reviews.llvm.org/D122017
Added:
Modified:
libcxx/include/__memory/unique_ptr.h
libcxx/include/deque
libcxx/include/forward_list
libcxx/include/list
libcxx/include/map
libcxx/include/set
libcxx/include/type_traits
libcxx/include/unordered_map
libcxx/include/unordered_set
libcxx/include/variant
libcxx/include/vector
Removed:
################################################################################
diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index ff09726aceddf..4816ee731cac9 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -138,7 +138,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
template <bool _Dummy, class _Deleter = typename __dependent_type<
- __identity<deleter_type>, _Dummy>::type>
+ __type_identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
typename enable_if<is_default_constructible<_Deleter>::value &&
!is_pointer<_Deleter>::value>::type;
@@ -352,7 +352,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
template <bool _Dummy, class _Deleter = typename __dependent_type<
- __identity<deleter_type>, _Dummy>::type>
+ __type_identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
typename enable_if<is_default_constructible<_Deleter>::value &&
!is_pointer<_Deleter>::value>::type;
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 537a8ddcb5ea1..184bae0fd971b 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -1314,7 +1314,7 @@ public:
deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0);
deque(const deque& __c);
- deque(const deque& __c, const __identity_t<allocator_type>& __a);
+ deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
deque& operator=(const deque& __c);
@@ -1328,7 +1328,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
_LIBCPP_INLINE_VISIBILITY
- deque(deque&& __c, const __identity_t<allocator_type>& __a);
+ deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
deque& operator=(deque&& __c)
_NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
@@ -1650,7 +1650,7 @@ deque<_Tp, _Allocator>::deque(const deque& __c)
}
template <class _Tp, class _Allocator>
-deque<_Tp, _Allocator>::deque(const deque& __c, const __identity_t<allocator_type>& __a)
+deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a)
: __base(__a)
{
__append(__c.begin(), __c.end());
@@ -1693,7 +1693,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c)
template <class _Tp, class _Allocator>
inline
-deque<_Tp, _Allocator>::deque(deque&& __c, const __identity_t<allocator_type>& __a)
+deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a)
: __base(_VSTD::move(__c), __a)
{
if (__a != __c.__alloc())
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index e01a8e7189395..4b3f4e2ec8267 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -691,7 +691,7 @@ public:
__is_cpp17_input_iterator<_InputIterator>::value
>::type* = nullptr);
forward_list(const forward_list& __x);
- forward_list(const forward_list& __x, const __identity_t<allocator_type>& __a);
+ forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
forward_list& operator=(const forward_list& __x);
@@ -700,7 +700,7 @@ public:
forward_list(forward_list&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<base>::value)
: base(_VSTD::move(__x)) {}
- forward_list(forward_list&& __x, const __identity_t<allocator_type>& __a);
+ forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
forward_list(initializer_list<value_type> __il);
forward_list(initializer_list<value_type> __il, const allocator_type& __a);
@@ -983,7 +983,7 @@ forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
- const __identity_t<allocator_type>& __a)
+ const __type_identity_t<allocator_type>& __a)
: base(__a)
{
insert_after(cbefore_begin(), __x.begin(), __x.end());
@@ -1004,7 +1004,7 @@ forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
- const __identity_t<allocator_type>& __a)
+ const __type_identity_t<allocator_type>& __a)
: base(_VSTD::move(__x), __a)
{
if (base::__alloc() != __x.__alloc())
diff --git a/libcxx/include/list b/libcxx/include/list
index 58efc0426a538..31cacbc71d3ad 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -883,7 +883,7 @@ public:
typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
list(const list& __c);
- list(const list& __c, const __identity_t<allocator_type>& __a);
+ list(const list& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
list& operator=(const list& __c);
#ifndef _LIBCPP_CXX03_LANG
@@ -894,7 +894,7 @@ public:
list(list&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
_LIBCPP_INLINE_VISIBILITY
- list(list&& __c, const __identity_t<allocator_type>& __a);
+ list(list&& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
list& operator=(list&& __c)
_NOEXCEPT_(
@@ -1255,7 +1255,7 @@ list<_Tp, _Alloc>::list(const list& __c)
}
template <class _Tp, class _Alloc>
-list<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a)
+list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a)
: base(__a)
{
_VSTD::__debug_db_insert_c(this);
@@ -1294,7 +1294,7 @@ inline list<_Tp, _Alloc>::list(list&& __c)
template <class _Tp, class _Alloc>
inline
-list<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a)
+list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a)
: base(__a)
{
_VSTD::__debug_db_insert_c(this);
diff --git a/libcxx/include/map b/libcxx/include/map
index 2266e1abe9e5b..8d26cdba17bd4 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -958,8 +958,8 @@ public:
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
- typedef __identity_t<_Compare> key_compare;
- typedef __identity_t<_Allocator> allocator_type;
+ typedef __type_identity_t<_Compare> key_compare;
+ typedef __type_identity_t<_Allocator> allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
@@ -1743,8 +1743,8 @@ public:
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
- typedef __identity_t<_Compare> key_compare;
- typedef __identity_t<_Allocator> allocator_type;
+ typedef __type_identity_t<_Compare> key_compare;
+ typedef __type_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 be117d0b8fa81..1ac86a1b26fd3 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -503,9 +503,9 @@ public:
// types:
typedef _Key key_type;
typedef key_type value_type;
- typedef __identity_t<_Compare> key_compare;
+ typedef __type_identity_t<_Compare> key_compare;
typedef key_compare value_compare;
- typedef __identity_t<_Allocator> allocator_type;
+ typedef __type_identity_t<_Allocator> allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
@@ -1036,9 +1036,9 @@ public:
// types:
typedef _Key key_type;
typedef key_type value_type;
- typedef __identity_t<_Compare> key_compare;
+ typedef __type_identity_t<_Compare> key_compare;
typedef key_compare value_compare;
- typedef __identity_t<_Allocator> allocator_type;
+ typedef __type_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 2f9c2c7b83af5..6504040ec2021 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -529,12 +529,6 @@ using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _A
template <class>
struct __void_t { typedef void type; };
-template <class _Tp>
-struct __identity { typedef _Tp type; };
-
-template <class _Tp>
-using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
-
template <class _Tp, bool>
struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
@@ -1333,6 +1327,13 @@ template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
#endif
// type_identity
+
+template <class _Tp>
+struct __type_identity { typedef _Tp type; };
+
+template <class _Tp>
+using __type_identity_t _LIBCPP_NODEBUG = typename __type_identity<_Tp>::type;
+
#if _LIBCPP_STD_VER > 17
template<class _Tp> struct type_identity { typedef _Tp type; };
template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index c8545489507fd..c701e67b2ef46 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -1014,9 +1014,9 @@ public:
// types
typedef _Key key_type;
typedef _Tp mapped_type;
- typedef __identity_t<_Hash> hasher;
- typedef __identity_t<_Pred> key_equal;
- typedef __identity_t<_Alloc> allocator_type;
+ typedef __type_identity_t<_Hash> hasher;
+ typedef __type_identity_t<_Pred> key_equal;
+ typedef __type_identity_t<_Alloc> allocator_type;
typedef pair<const key_type, mapped_type> value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
@@ -1908,9 +1908,9 @@ public:
// types
typedef _Key key_type;
typedef _Tp mapped_type;
- typedef __identity_t<_Hash> hasher;
- typedef __identity_t<_Pred> key_equal;
- typedef __identity_t<_Alloc> allocator_type;
+ typedef __type_identity_t<_Hash> hasher;
+ typedef __type_identity_t<_Pred> key_equal;
+ typedef __type_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 4dd1b8c6a0943..0dd53a298ea63 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -490,9 +490,9 @@ public:
// types
typedef _Value key_type;
typedef key_type value_type;
- typedef __identity_t<_Hash> hasher;
- typedef __identity_t<_Pred> key_equal;
- typedef __identity_t<_Alloc> allocator_type;
+ typedef __type_identity_t<_Hash> hasher;
+ typedef __type_identity_t<_Pred> key_equal;
+ typedef __type_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),
@@ -1150,9 +1150,9 @@ public:
// types
typedef _Value key_type;
typedef key_type value_type;
- typedef __identity_t<_Hash> hasher;
- typedef __identity_t<_Pred> key_equal;
- typedef __identity_t<_Alloc> allocator_type;
+ typedef __type_identity_t<_Hash> hasher;
+ typedef __type_identity_t<_Pred> key_equal;
+ typedef __type_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),
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 15c4367404ff7..3c68ab2cbc2bf 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -562,7 +562,7 @@ private:
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fdiagonal_impl() {
return __make_dispatch<_Fp, _Vs...>(
- index_sequence<((void)__identity<_Vs>{}, _Ip)...>{});
+ index_sequence<((void)__type_identity<_Vs>{}, _Ip)...>{});
}
template <class _Fp, class... _Vs, size_t... _Is>
@@ -1202,12 +1202,12 @@ private:
struct __no_narrowing_check {
template <class _Dest, class _Source>
- using _Apply = __identity<_Dest>;
+ using _Apply = __type_identity<_Dest>;
};
struct __narrowing_check {
template <class _Dest>
- static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
+ static auto __test_impl(_Dest (&&)[1]) -> __type_identity<_Dest>;
template <class _Dest, class _Source>
using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
};
@@ -1233,7 +1233,7 @@ template <class _Tp, size_t>
struct __overload_bool {
template <class _Up, class _Ap = __uncvref_t<_Up>>
auto operator()(bool, _Up&&) const
- -> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>;
+ -> enable_if_t<is_same_v<_Ap, bool>, __type_identity<_Tp>>;
};
template <size_t _Idx>
diff --git a/libcxx/include/vector b/libcxx/include/vector
index 97a8524987445..ba4c1b4396719 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -423,7 +423,7 @@ public:
}
vector(const vector& __x);
- vector(const vector& __x, const __identity_t<allocator_type>& __a);
+ vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(const vector& __x);
@@ -443,7 +443,7 @@ public:
#endif
_LIBCPP_INLINE_VISIBILITY
- vector(vector&& __x, const __identity_t<allocator_type>& __a);
+ vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __x)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
@@ -1179,7 +1179,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
}
template <class _Tp, class _Allocator>
-vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
+vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
@@ -1215,7 +1215,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
-vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
+vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
: __end_cap_(nullptr, __a)
{
_VSTD::__debug_db_insert_c(this);
@@ -2148,7 +2148,7 @@ public:
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
- vector(vector&& __v, const __identity_t<allocator_type>& __a);
+ vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __v)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
@@ -2784,7 +2784,7 @@ inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
}
template <class _Allocator>
-vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
+vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __a)
More information about the libcxx-commits
mailing list