xref: /llvm-project/libc/src/__support/CPP/type_traits/decay.h (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1 //===-- decay type_traits ---------------------------------------*- C++ -*-===//
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 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
9 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
10 
11 #include "src/__support/macros/attributes.h"
12 
13 #include "src/__support/CPP/type_traits/add_pointer.h"
14 #include "src/__support/CPP/type_traits/conditional.h"
15 #include "src/__support/CPP/type_traits/is_array.h"
16 #include "src/__support/CPP/type_traits/is_function.h"
17 #include "src/__support/CPP/type_traits/remove_cv.h"
18 #include "src/__support/CPP/type_traits/remove_extent.h"
19 #include "src/__support/CPP/type_traits/remove_reference.h"
20 #include "src/__support/macros/config.h"
21 
22 namespace LIBC_NAMESPACE_DECL {
23 namespace cpp {
24 
25 // decay
26 template <class T> class decay {
27   using U = cpp::remove_reference_t<T>;
28 
29 public:
30   using type = conditional_t<
31       cpp::is_array_v<U>, cpp::add_pointer_t<cpp::remove_extent_t<U>>,
32       cpp::conditional_t<cpp::is_function_v<U>, cpp::add_pointer_t<U>,
33                          cpp::remove_cv_t<U>>>;
34 };
35 template <class T> using decay_t = typename decay<T>::type;
36 
37 } // namespace cpp
38 } // namespace LIBC_NAMESPACE_DECL
39 
40 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
41