xref: /llvm-project/libcxx/test/std/utilities/function.objects/refwrap/unwrap_ref_decay.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 // <functional>
10 //
11 // template <class T>
12 // struct unwrap_ref_decay;
13 //
14 // template <class T>
15 // using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
16 
17 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
18 
19 #include <functional>
20 #include <type_traits>
21 
22 
23 template <typename T, typename Result>
24 void check() {
25   static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, Result>);
26   static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, std::unwrap_ref_decay_t<T>>);
27 }
28 
29 struct T { };
30 
31 int main() {
32   check<T,             T>();
33   check<T&,            T>();
34   check<T const,       T>();
35   check<T const&,      T>();
36   check<T*,            T*>();
37   check<T const*,      T const*>();
38   check<T[3],          T*>();
39   check<T const [3],   T const*>();
40   check<T (),          T (*)()>();
41   check<T (int) const, T (int) const>();
42   check<T (int) &,     T (int) &>();
43   check<T (int) &&,    T (int) &&>();
44 
45   check<std::reference_wrapper<T>,         T&>();
46   check<std::reference_wrapper<T>&,        T&>();
47   check<std::reference_wrapper<T const>,   T const&>();
48   check<std::reference_wrapper<T const>&,  T const&>();
49   check<std::reference_wrapper<T*>,        T*&>();
50   check<std::reference_wrapper<T*>&,       T*&>();
51   check<std::reference_wrapper<T const*>,  T const*&>();
52   check<std::reference_wrapper<T const*>&, T const*&>();
53   check<std::reference_wrapper<T[3]>,      T (&)[3]>();
54   check<std::reference_wrapper<T[3]>&,     T (&)[3]>();
55   check<std::reference_wrapper<T ()>,      T (&)()>();
56   check<std::reference_wrapper<T ()>&,     T (&)()>();
57 }
58