Skip to content

Commit 173476e

Browse files
committed
[libc++] Add __decay_t and use it instead of decay<>::type
This avoids instantiating lots of types. Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D146984
1 parent 00701d3 commit 173476e

File tree

18 files changed

+60
-52
lines changed

18 files changed

+60
-52
lines changed

libcxx/include/__algorithm/make_projected.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ struct _ProjectedPred {
5757

5858
template <class _Pred,
5959
class _Proj,
60-
__enable_if_t<!(!is_member_pointer<typename decay<_Pred>::type>::value &&
61-
__is_identity<typename decay<_Proj>::type>::value),
60+
__enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value &&
61+
__is_identity<__decay_t<_Proj> >::value),
6262
int> = 0>
6363
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj>
6464
__make_projected(_Pred& __pred, _Proj& __proj) {
@@ -70,8 +70,8 @@ __make_projected(_Pred& __pred, _Proj& __proj) {
7070
// the call stack when the comparator is invoked, even in an unoptimized build.
7171
template <class _Pred,
7272
class _Proj,
73-
__enable_if_t<!is_member_pointer<typename decay<_Pred>::type>::value &&
74-
__is_identity<typename decay<_Proj>::type>::value,
73+
__enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value &&
74+
__is_identity<__decay_t<_Proj> >::value,
7575
int> = 0>
7676
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) {
7777
return __pred;

libcxx/include/__atomic/atomic_sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ template <class _Atp, class _Fn>
6565
_LIBCPP_AVAILABILITY_SYNC
6666
_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_wait(_Atp* __a, _Fn && __test_fn)
6767
{
68-
__libcpp_atomic_wait_backoff_impl<_Atp, typename decay<_Fn>::type> __backoff_fn = {__a, __test_fn};
68+
__libcpp_atomic_wait_backoff_impl<_Atp, __decay_t<_Fn> > __backoff_fn = {__a, __test_fn};
6969
return std::__libcpp_thread_poll_with_backoff(__test_fn, __backoff_fn);
7070
}
7171

libcxx/include/__exception/nested_exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct __throw_with_nested<_Tp, _Up, false> {
6767
template <class _Tp>
6868
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) {
6969
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
70-
typedef typename decay<_Tp>::type _Up;
70+
using _Up = __decay_t<_Tp>;
7171
static_assert(is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible");
7272
__throw_with_nested<_Tp,
7373
_Up,

libcxx/include/__filesystem/path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct __is_pathable_string<
144144
}
145145
};
146146

147-
template <class _Source, class _DS = typename decay<_Source>::type,
147+
template <class _Source, class _DS = __decay_t<_Source>,
148148
class _UnqualPtrType =
149149
__remove_const_t<__remove_pointer_t<_DS> >,
150150
bool _IsCharPtr = is_pointer<_DS>::value&&

libcxx/include/__functional/bind.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
263263
}
264264

265265
template<class _Fp, class ..._BoundArgs>
266-
class __bind : public __weak_result_type<typename decay<_Fp>::type>
266+
class __bind : public __weak_result_type<__decay_t<_Fp> >
267267
{
268268
protected:
269-
typedef typename decay<_Fp>::type _Fd;
270-
typedef tuple<typename decay<_BoundArgs>::type...> _Td;
269+
using _Fd = __decay_t<_Fp>;
270+
typedef tuple<__decay_t<_BoundArgs>...> _Td;
271271
private:
272272
_Fd __f_;
273273
_Td __bound_args_;

libcxx/include/__functional/function.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
430430
}
431431

432432
template <class _Fp,
433-
class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
433+
class = typename enable_if<!is_same<__decay_t<_Fp>, __value_func>::value>::type>
434434
_LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
435435
: __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
436436

@@ -773,7 +773,7 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
773773
}
774774
}
775775

776-
template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
776+
template <class _Fp, class = typename enable_if<!is_same<__decay_t<_Fp>, __policy_func>::value>::type>
777777
_LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
778778
: __policy_(__policy::__create_empty()) {
779779
typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
@@ -1029,7 +1029,7 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
10291029
function& operator=(const function&);
10301030
function& operator=(function&&) _NOEXCEPT;
10311031
function& operator=(nullptr_t) _NOEXCEPT;
1032-
template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
1032+
template<class _Fp, class = _EnableIfLValueCallable<__decay_t<_Fp>>>
10331033
function& operator=(_Fp&&);
10341034

10351035
~function();

libcxx/include/__functional/invoke.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ struct __member_pointer_class_type<_Ret _ClassType::*> {
266266
};
267267

268268
template <class _Fp, class _A0,
269-
class _DecayFp = typename decay<_Fp>::type,
270-
class _DecayA0 = typename decay<_A0>::type,
269+
class _DecayFp = __decay_t<_Fp>,
270+
class _DecayA0 = __decay_t<_A0>,
271271
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
272272
using __enable_if_bullet1 = typename enable_if
273273
<
@@ -276,17 +276,17 @@ using __enable_if_bullet1 = typename enable_if
276276
>::type;
277277

278278
template <class _Fp, class _A0,
279-
class _DecayFp = typename decay<_Fp>::type,
280-
class _DecayA0 = typename decay<_A0>::type>
279+
class _DecayFp = __decay_t<_Fp>,
280+
class _DecayA0 = __decay_t<_A0> >
281281
using __enable_if_bullet2 = typename enable_if
282282
<
283283
is_member_function_pointer<_DecayFp>::value
284284
&& __is_reference_wrapper<_DecayA0>::value
285285
>::type;
286286

287287
template <class _Fp, class _A0,
288-
class _DecayFp = typename decay<_Fp>::type,
289-
class _DecayA0 = typename decay<_A0>::type,
288+
class _DecayFp = __decay_t<_Fp>,
289+
class _DecayA0 = __decay_t<_A0>,
290290
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
291291
using __enable_if_bullet3 = typename enable_if
292292
<
@@ -296,8 +296,8 @@ using __enable_if_bullet3 = typename enable_if
296296
>::type;
297297

298298
template <class _Fp, class _A0,
299-
class _DecayFp = typename decay<_Fp>::type,
300-
class _DecayA0 = typename decay<_A0>::type,
299+
class _DecayFp = __decay_t<_Fp>,
300+
class _DecayA0 = __decay_t<_A0>,
301301
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
302302
using __enable_if_bullet4 = typename enable_if
303303
<
@@ -306,17 +306,17 @@ using __enable_if_bullet4 = typename enable_if
306306
>::type;
307307

308308
template <class _Fp, class _A0,
309-
class _DecayFp = typename decay<_Fp>::type,
310-
class _DecayA0 = typename decay<_A0>::type>
309+
class _DecayFp = __decay_t<_Fp>,
310+
class _DecayA0 = __decay_t<_A0> >
311311
using __enable_if_bullet5 = typename enable_if
312312
<
313313
is_member_object_pointer<_DecayFp>::value
314314
&& __is_reference_wrapper<_DecayA0>::value
315315
>::type;
316316

317317
template <class _Fp, class _A0,
318-
class _DecayFp = typename decay<_Fp>::type,
319-
class _DecayA0 = typename decay<_A0>::type,
318+
class _DecayFp = __decay_t<_Fp>,
319+
class _DecayA0 = __decay_t<_A0>,
320320
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
321321
using __enable_if_bullet6 = typename enable_if
322322
<

libcxx/include/__functional/unwrap_ref.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ template <class _Tp>
3838
using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3939

4040
template <class _Tp>
41-
struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { };
41+
struct unwrap_ref_decay : unwrap_reference<__decay_t<_Tp> > { };
4242

4343
template <class _Tp>
4444
using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
@@ -49,7 +49,7 @@ struct __unwrap_ref_decay
4949
#if _LIBCPP_STD_VER >= 20
5050
: unwrap_ref_decay<_Tp>
5151
#else
52-
: __unwrap_reference<typename decay<_Tp>::type>
52+
: __unwrap_reference<__decay_t<_Tp> >
5353
#endif
5454
{ };
5555

libcxx/include/__memory/compressed_pair.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct __compressed_pair_elem {
4646
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
4747
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {}
4848

49-
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
49+
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value> >
5050
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
5151
explicit __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {}
5252

@@ -75,7 +75,7 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
7575
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
7676
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {}
7777

78-
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
78+
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value> >
7979
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
8080
explicit __compressed_pair_elem(_Up&& __u) : __value_type(std::forward<_Up>(__u)) {}
8181

libcxx/include/__memory/pointer_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ template <class _Pointer, class = __enable_if_t<
200200
_And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value
201201
> >
202202
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
203-
typename decay<decltype(__to_address_helper<_Pointer>::__call(std::declval<const _Pointer&>()))>::type
203+
__decay_t<decltype(__to_address_helper<_Pointer>::__call(std::declval<const _Pointer&>()))>
204204
__to_address(const _Pointer& __p) _NOEXCEPT {
205205
return __to_address_helper<_Pointer>::__call(__p);
206206
}

0 commit comments

Comments
 (0)