[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
This commit is contained in:
Nikolas Klauser 2022-03-18 17:49:02 +01:00
parent fed96f31bb
commit 3c6bd176fb
11 changed files with 51 additions and 50 deletions

View File

@ -138,7 +138,7 @@ private:
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 @@ private:
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;

View File

@ -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())

View File

@ -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())

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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),

View File

@ -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>

View File

@ -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)