Skip to content

Commit 3c6bd17

Browse files
committed
[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
1 parent fed96f3 commit 3c6bd17

File tree

11 files changed

+51
-50
lines changed

11 files changed

+51
-50
lines changed

libcxx/include/__memory/unique_ptr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
138138
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
139139

140140
template <bool _Dummy, class _Deleter = typename __dependent_type<
141-
__identity<deleter_type>, _Dummy>::type>
141+
__type_identity<deleter_type>, _Dummy>::type>
142142
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
143143
typename enable_if<is_default_constructible<_Deleter>::value &&
144144
!is_pointer<_Deleter>::value>::type;
@@ -352,7 +352,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
352352
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
353353

354354
template <bool _Dummy, class _Deleter = typename __dependent_type<
355-
__identity<deleter_type>, _Dummy>::type>
355+
__type_identity<deleter_type>, _Dummy>::type>
356356
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
357357
typename enable_if<is_default_constructible<_Deleter>::value &&
358358
!is_pointer<_Deleter>::value>::type;

libcxx/include/deque

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ public:
13141314
deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
13151315
typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0);
13161316
deque(const deque& __c);
1317-
deque(const deque& __c, const __identity_t<allocator_type>& __a);
1317+
deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
13181318

13191319
deque& operator=(const deque& __c);
13201320

@@ -1328,7 +1328,7 @@ public:
13281328
_LIBCPP_INLINE_VISIBILITY
13291329
deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
13301330
_LIBCPP_INLINE_VISIBILITY
1331-
deque(deque&& __c, const __identity_t<allocator_type>& __a);
1331+
deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
13321332
_LIBCPP_INLINE_VISIBILITY
13331333
deque& operator=(deque&& __c)
13341334
_NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
@@ -1650,7 +1650,7 @@ deque<_Tp, _Allocator>::deque(const deque& __c)
16501650
}
16511651

16521652
template <class _Tp, class _Allocator>
1653-
deque<_Tp, _Allocator>::deque(const deque& __c, const __identity_t<allocator_type>& __a)
1653+
deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a)
16541654
: __base(__a)
16551655
{
16561656
__append(__c.begin(), __c.end());
@@ -1693,7 +1693,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c)
16931693

16941694
template <class _Tp, class _Allocator>
16951695
inline
1696-
deque<_Tp, _Allocator>::deque(deque&& __c, const __identity_t<allocator_type>& __a)
1696+
deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a)
16971697
: __base(_VSTD::move(__c), __a)
16981698
{
16991699
if (__a != __c.__alloc())

libcxx/include/forward_list

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public:
691691
__is_cpp17_input_iterator<_InputIterator>::value
692692
>::type* = nullptr);
693693
forward_list(const forward_list& __x);
694-
forward_list(const forward_list& __x, const __identity_t<allocator_type>& __a);
694+
forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
695695

696696
forward_list& operator=(const forward_list& __x);
697697

@@ -700,7 +700,7 @@ public:
700700
forward_list(forward_list&& __x)
701701
_NOEXCEPT_(is_nothrow_move_constructible<base>::value)
702702
: base(_VSTD::move(__x)) {}
703-
forward_list(forward_list&& __x, const __identity_t<allocator_type>& __a);
703+
forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
704704

705705
forward_list(initializer_list<value_type> __il);
706706
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)
983983

984984
template <class _Tp, class _Alloc>
985985
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
986-
const __identity_t<allocator_type>& __a)
986+
const __type_identity_t<allocator_type>& __a)
987987
: base(__a)
988988
{
989989
insert_after(cbefore_begin(), __x.begin(), __x.end());
@@ -1004,7 +1004,7 @@ forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
10041004
#ifndef _LIBCPP_CXX03_LANG
10051005
template <class _Tp, class _Alloc>
10061006
forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
1007-
const __identity_t<allocator_type>& __a)
1007+
const __type_identity_t<allocator_type>& __a)
10081008
: base(_VSTD::move(__x), __a)
10091009
{
10101010
if (base::__alloc() != __x.__alloc())

libcxx/include/list

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ public:
883883
typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0);
884884

885885
list(const list& __c);
886-
list(const list& __c, const __identity_t<allocator_type>& __a);
886+
list(const list& __c, const __type_identity_t<allocator_type>& __a);
887887
_LIBCPP_INLINE_VISIBILITY
888888
list& operator=(const list& __c);
889889
#ifndef _LIBCPP_CXX03_LANG
@@ -894,7 +894,7 @@ public:
894894
list(list&& __c)
895895
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
896896
_LIBCPP_INLINE_VISIBILITY
897-
list(list&& __c, const __identity_t<allocator_type>& __a);
897+
list(list&& __c, const __type_identity_t<allocator_type>& __a);
898898
_LIBCPP_INLINE_VISIBILITY
899899
list& operator=(list&& __c)
900900
_NOEXCEPT_(
@@ -1255,7 +1255,7 @@ list<_Tp, _Alloc>::list(const list& __c)
12551255
}
12561256

12571257
template <class _Tp, class _Alloc>
1258-
list<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a)
1258+
list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a)
12591259
: base(__a)
12601260
{
12611261
_VSTD::__debug_db_insert_c(this);
@@ -1294,7 +1294,7 @@ inline list<_Tp, _Alloc>::list(list&& __c)
12941294

12951295
template <class _Tp, class _Alloc>
12961296
inline
1297-
list<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a)
1297+
list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a)
12981298
: base(__a)
12991299
{
13001300
_VSTD::__debug_db_insert_c(this);

libcxx/include/map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,8 @@ public:
958958
typedef _Key key_type;
959959
typedef _Tp mapped_type;
960960
typedef pair<const key_type, mapped_type> value_type;
961-
typedef __identity_t<_Compare> key_compare;
962-
typedef __identity_t<_Allocator> allocator_type;
961+
typedef __type_identity_t<_Compare> key_compare;
962+
typedef __type_identity_t<_Allocator> allocator_type;
963963
typedef value_type& reference;
964964
typedef const value_type& const_reference;
965965

@@ -1743,8 +1743,8 @@ public:
17431743
typedef _Key key_type;
17441744
typedef _Tp mapped_type;
17451745
typedef pair<const key_type, mapped_type> value_type;
1746-
typedef __identity_t<_Compare> key_compare;
1747-
typedef __identity_t<_Allocator> allocator_type;
1746+
typedef __type_identity_t<_Compare> key_compare;
1747+
typedef __type_identity_t<_Allocator> allocator_type;
17481748
typedef value_type& reference;
17491749
typedef const value_type& const_reference;
17501750

libcxx/include/set

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ public:
503503
// types:
504504
typedef _Key key_type;
505505
typedef key_type value_type;
506-
typedef __identity_t<_Compare> key_compare;
506+
typedef __type_identity_t<_Compare> key_compare;
507507
typedef key_compare value_compare;
508-
typedef __identity_t<_Allocator> allocator_type;
508+
typedef __type_identity_t<_Allocator> allocator_type;
509509
typedef value_type& reference;
510510
typedef const value_type& const_reference;
511511

@@ -1036,9 +1036,9 @@ public:
10361036
// types:
10371037
typedef _Key key_type;
10381038
typedef key_type value_type;
1039-
typedef __identity_t<_Compare> key_compare;
1039+
typedef __type_identity_t<_Compare> key_compare;
10401040
typedef key_compare value_compare;
1041-
typedef __identity_t<_Allocator> allocator_type;
1041+
typedef __type_identity_t<_Allocator> allocator_type;
10421042
typedef value_type& reference;
10431043
typedef const value_type& const_reference;
10441044

libcxx/include/type_traits

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,6 @@ using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _A
529529
template <class>
530530
struct __void_t { typedef void type; };
531531

532-
template <class _Tp>
533-
struct __identity { typedef _Tp type; };
534-
535-
template <class _Tp>
536-
using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
537-
538532
template <class _Tp, bool>
539533
struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
540534

@@ -1333,6 +1327,13 @@ template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
13331327
#endif
13341328

13351329
// type_identity
1330+
1331+
template <class _Tp>
1332+
struct __type_identity { typedef _Tp type; };
1333+
1334+
template <class _Tp>
1335+
using __type_identity_t _LIBCPP_NODEBUG = typename __type_identity<_Tp>::type;
1336+
13361337
#if _LIBCPP_STD_VER > 17
13371338
template<class _Tp> struct type_identity { typedef _Tp type; };
13381339
template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;

libcxx/include/unordered_map

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,9 @@ public:
10141014
// types
10151015
typedef _Key key_type;
10161016
typedef _Tp mapped_type;
1017-
typedef __identity_t<_Hash> hasher;
1018-
typedef __identity_t<_Pred> key_equal;
1019-
typedef __identity_t<_Alloc> allocator_type;
1017+
typedef __type_identity_t<_Hash> hasher;
1018+
typedef __type_identity_t<_Pred> key_equal;
1019+
typedef __type_identity_t<_Alloc> allocator_type;
10201020
typedef pair<const key_type, mapped_type> value_type;
10211021
typedef value_type& reference;
10221022
typedef const value_type& const_reference;
@@ -1908,9 +1908,9 @@ public:
19081908
// types
19091909
typedef _Key key_type;
19101910
typedef _Tp mapped_type;
1911-
typedef __identity_t<_Hash> hasher;
1912-
typedef __identity_t<_Pred> key_equal;
1913-
typedef __identity_t<_Alloc> allocator_type;
1911+
typedef __type_identity_t<_Hash> hasher;
1912+
typedef __type_identity_t<_Pred> key_equal;
1913+
typedef __type_identity_t<_Alloc> allocator_type;
19141914
typedef pair<const key_type, mapped_type> value_type;
19151915
typedef value_type& reference;
19161916
typedef const value_type& const_reference;

libcxx/include/unordered_set

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ public:
490490
// types
491491
typedef _Value key_type;
492492
typedef key_type value_type;
493-
typedef __identity_t<_Hash> hasher;
494-
typedef __identity_t<_Pred> key_equal;
495-
typedef __identity_t<_Alloc> allocator_type;
493+
typedef __type_identity_t<_Hash> hasher;
494+
typedef __type_identity_t<_Pred> key_equal;
495+
typedef __type_identity_t<_Alloc> allocator_type;
496496
typedef value_type& reference;
497497
typedef const value_type& const_reference;
498498
static_assert((is_same<value_type, typename allocator_type::value_type>::value),
@@ -1150,9 +1150,9 @@ public:
11501150
// types
11511151
typedef _Value key_type;
11521152
typedef key_type value_type;
1153-
typedef __identity_t<_Hash> hasher;
1154-
typedef __identity_t<_Pred> key_equal;
1155-
typedef __identity_t<_Alloc> allocator_type;
1153+
typedef __type_identity_t<_Hash> hasher;
1154+
typedef __type_identity_t<_Pred> key_equal;
1155+
typedef __type_identity_t<_Alloc> allocator_type;
11561156
typedef value_type& reference;
11571157
typedef const value_type& const_reference;
11581158
static_assert((is_same<value_type, typename allocator_type::value_type>::value),

libcxx/include/variant

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private:
562562
inline _LIBCPP_INLINE_VISIBILITY
563563
static constexpr auto __make_fdiagonal_impl() {
564564
return __make_dispatch<_Fp, _Vs...>(
565-
index_sequence<((void)__identity<_Vs>{}, _Ip)...>{});
565+
index_sequence<((void)__type_identity<_Vs>{}, _Ip)...>{});
566566
}
567567

568568
template <class _Fp, class... _Vs, size_t... _Is>
@@ -1202,12 +1202,12 @@ private:
12021202

12031203
struct __no_narrowing_check {
12041204
template <class _Dest, class _Source>
1205-
using _Apply = __identity<_Dest>;
1205+
using _Apply = __type_identity<_Dest>;
12061206
};
12071207

12081208
struct __narrowing_check {
12091209
template <class _Dest>
1210-
static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
1210+
static auto __test_impl(_Dest (&&)[1]) -> __type_identity<_Dest>;
12111211
template <class _Dest, class _Source>
12121212
using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({declval<_Source>()}));
12131213
};
@@ -1233,7 +1233,7 @@ template <class _Tp, size_t>
12331233
struct __overload_bool {
12341234
template <class _Up, class _Ap = __uncvref_t<_Up>>
12351235
auto operator()(bool, _Up&&) const
1236-
-> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>;
1236+
-> enable_if_t<is_same_v<_Ap, bool>, __type_identity<_Tp>>;
12371237
};
12381238

12391239
template <size_t _Idx>

libcxx/include/vector

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public:
423423
}
424424

425425
vector(const vector& __x);
426-
vector(const vector& __x, const __identity_t<allocator_type>& __a);
426+
vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
427427
_LIBCPP_INLINE_VISIBILITY
428428
vector& operator=(const vector& __x);
429429

@@ -443,7 +443,7 @@ public:
443443
#endif
444444

445445
_LIBCPP_INLINE_VISIBILITY
446-
vector(vector&& __x, const __identity_t<allocator_type>& __a);
446+
vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
447447
_LIBCPP_INLINE_VISIBILITY
448448
vector& operator=(vector&& __x)
449449
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
@@ -1179,7 +1179,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
11791179
}
11801180

11811181
template <class _Tp, class _Allocator>
1182-
vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
1182+
vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
11831183
: __end_cap_(nullptr, __a)
11841184
{
11851185
_VSTD::__debug_db_insert_c(this);
@@ -1215,7 +1215,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
12151215

12161216
template <class _Tp, class _Allocator>
12171217
inline _LIBCPP_INLINE_VISIBILITY
1218-
vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
1218+
vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
12191219
: __end_cap_(nullptr, __a)
12201220
{
12211221
_VSTD::__debug_db_insert_c(this);
@@ -2148,7 +2148,7 @@ public:
21482148
#else
21492149
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
21502150
#endif
2151-
vector(vector&& __v, const __identity_t<allocator_type>& __a);
2151+
vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
21522152
_LIBCPP_INLINE_VISIBILITY
21532153
vector& operator=(vector&& __v)
21542154
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
@@ -2784,7 +2784,7 @@ inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
27842784
}
27852785

27862786
template <class _Allocator>
2787-
vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
2787+
vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
27882788
: __begin_(nullptr),
27892789
__size_(0),
27902790
__cap_alloc_(0, __a)

0 commit comments

Comments
 (0)