Skip to content

Commit

Permalink
[libc++] Rename __identity to __type_identity
Browse files Browse the repository at this point in the history
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
  • Loading branch information
philnik777 committed Mar 25, 2022
1 parent fed96f3 commit 3c6bd17
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions libcxx/include/__memory/unique_ptr.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/deque
Expand Up @@ -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);

Expand All @@ -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 &&
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/forward_list
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/list
Expand Up @@ -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
Expand All @@ -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_(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/map
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/set
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
13 changes: 7 additions & 6 deletions libcxx/include/type_traits
Expand Up @@ -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 {};

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions libcxx/include/unordered_map
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions libcxx/include/unordered_set
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/variant
Expand Up @@ -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>
Expand Down Expand Up @@ -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>()}));
};
Expand All @@ -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>
Expand Down
12 changes: 6 additions & 6 deletions libcxx/include/vector
Expand Up @@ -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);

Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3c6bd17

Please sign in to comment.