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/integral_constant.h>
16 #include <__type_traits/is_array.h>
17 #include <__type_traits/is_function.h>
18 #include <__type_traits/is_referenceable.h>
19 #include <__type_traits/remove_cv.h>
20 #include <__type_traits/remove_extent.h>
21 #include <__type_traits/remove_reference.h>
22 
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 #  pragma GCC system_header
25 #endif
26 
27 _LIBCPP_BEGIN_NAMESPACE_STD
28 
29 template <class _Up, bool>
30 struct __decay {
31     typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
32 };
33 
34 template <class _Up>
35 struct __decay<_Up, true> {
36 public:
37     typedef _LIBCPP_NODEBUG typename conditional
38                      <
39                          is_array<_Up>::value,
40                          typename add_pointer<typename remove_extent<_Up>::type>::type,
41                          typename conditional
42                          <
43                               is_function<_Up>::value,
44                               typename add_pointer<_Up>::type,
45                               typename remove_cv<_Up>::type
46                          >::type
47                      >::type type;
48 };
49 
50 template <class _Tp>
51 struct _LIBCPP_TEMPLATE_VIS decay
52 {
53 private:
54     typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
55 public:
56     typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
57 };
58 
59 #if _LIBCPP_STD_VER > 11
60 template <class _Tp> using decay_t = typename decay<_Tp>::type;
61 #endif
62 
63 _LIBCPP_END_NAMESPACE_STD
64 
65 #endif // _LIBCPP___TYPE_TRAITS_DECAY_H
66