1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___TYPE_TRAITS_DECAY_H
10 #define _LIBCPP___TYPE_TRAITS_DECAY_H
11 
12 #include <__config>
13 #include <__type_traits/add_pointer.h>
14 #include <__type_traits/conditional.h>
15 #include <__type_traits/is_array.h>
16 #include <__type_traits/is_function.h>
17 #include <__type_traits/is_referenceable.h>
18 #include <__type_traits/remove_cv.h>
19 #include <__type_traits/remove_extent.h>
20 #include <__type_traits/remove_reference.h>
21 
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 #  pragma GCC system_header
24 #endif
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
28 #if __has_builtin(__decay)
29 template <class _Tp>
30 using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
31 
32 template <class _Tp>
33 struct decay {
34   using type _LIBCPP_NODEBUG = __decay_t<_Tp>;
35 };
36 
37 #else
38 template <class _Up, bool>
39 struct __decay {
40   typedef _LIBCPP_NODEBUG __remove_cv_t<_Up> type;
41 };
42 
43 template <class _Up>
44 struct __decay<_Up, true> {
45 public:
46   typedef _LIBCPP_NODEBUG typename conditional<
47       is_array<_Up>::value,
48       __add_pointer_t<__remove_extent_t<_Up> >,
49       typename conditional<is_function<_Up>::value, typename add_pointer<_Up>::type, __remove_cv_t<_Up> >::type >::type
50       type;
51 };
52 
53 template <class _Tp>
54 struct _LIBCPP_TEMPLATE_VIS decay {
55 private:
56   typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
57 
58 public:
59   typedef _LIBCPP_NODEBUG typename __decay<_Up, __libcpp_is_referenceable<_Up>::value>::type type;
60 };
61 
62 template <class _Tp>
63 using __decay_t = typename decay<_Tp>::type;
64 #endif // __has_builtin(__decay)
65 
66 #if _LIBCPP_STD_VER >= 14
67 template <class _Tp>
68 using decay_t = __decay_t<_Tp>;
69 #endif
70 
71 _LIBCPP_END_NAMESPACE_STD
72 
73 #endif // _LIBCPP___TYPE_TRAITS_DECAY_H
74