]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2018-2023 Free Software Foundation, Inc. |
3d18dc9d JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
6d0b43f5 | 18 | // { dg-do compile { target c++20 } } |
3d18dc9d JW |
19 | |
20 | #include <type_traits> | |
21 | ||
bb54e0b8 JW |
22 | #ifndef __cpp_lib_unwrap_ref |
23 | # error "Feature-test macro for unwrap_reference missing in <type_traits>" | |
24 | #elif __cpp_lib_unwrap_ref != 201811L | |
25 | # error "Feature-test macro for unwrap_reference has wrong value in <type_traits>" | |
26 | #endif | |
27 | ||
3d18dc9d JW |
28 | template<typename T, typename U> struct expect_same; |
29 | template<typename T> struct expect_same<T, T> : std::true_type { }; | |
30 | ||
31 | template<typename T, typename U = T> | |
32 | constexpr bool check() | |
33 | { | |
34 | using std::unwrap_reference; | |
35 | using T2 = typename unwrap_reference<T>::type; | |
82e8c3da | 36 | static_assert(expect_same<T2, std::unwrap_reference_t<T2>>::value); |
3d18dc9d JW |
37 | return expect_same<T2, U>::value; |
38 | } | |
39 | ||
40 | void | |
41 | test01() | |
42 | { | |
43 | static_assert( check<int>() ); | |
44 | static_assert( check<const int>() ); | |
45 | static_assert( check<const int&>() ); | |
46 | static_assert( check<const int*>() ); | |
47 | static_assert( check<const int*&>() ); | |
48 | ||
49 | // reference_wrapper types should get unwrapped: | |
50 | static_assert( check<std::reference_wrapper<int>, int&>() ); | |
51 | static_assert( check<std::reference_wrapper<const int>, const int&>() ); | |
52 | static_assert( check<std::reference_wrapper<long>, long&>() ); | |
53 | ||
54 | // But not cv-qualified reference_wrapper types: | |
55 | static_assert( check<const std::reference_wrapper<int>>() ); | |
56 | static_assert( check<volatile std::reference_wrapper<int>>() ); | |
57 | static_assert( check<const volatile std::reference_wrapper<int>>() ); | |
58 | ||
59 | // Or references to reference_wrapper types: | |
60 | static_assert( check<std::reference_wrapper<int>&>() ); | |
61 | static_assert( check<std::reference_wrapper<int>&&>() ); | |
62 | static_assert( check<const std::reference_wrapper<int>&>() ); | |
63 | } |