• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                      <
48                          is_array<_Up>::value,
49                          __add_pointer_t<__remove_extent_t<_Up> >,
50                          typename conditional
51                          <
52                               is_function<_Up>::value,
53                               typename add_pointer<_Up>::type,
54                               __remove_cv_t<_Up>
55                          >::type
56                      >::type type;
57 };
58 
59 template <class _Tp>
60 struct _LIBCPP_TEMPLATE_VIS decay
61 {
62 private:
63     typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
64 public:
65   typedef _LIBCPP_NODEBUG typename __decay<_Up, __libcpp_is_referenceable<_Up>::value>::type type;
66 };
67 
68 template <class _Tp>
69 using __decay_t = typename decay<_Tp>::type;
70 #endif // __has_builtin(__decay)
71 
72 #if _LIBCPP_STD_VER >= 14
73 template <class _Tp> using decay_t = __decay_t<_Tp>;
74 #endif
75 
76 _LIBCPP_END_NAMESPACE_STD
77 
78 #endif // _LIBCPP___TYPE_TRAITS_DECAY_H
79