]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/common_reference/requirements/typedefs.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / common_reference / requirements / typedefs.cc
1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
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
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
20
21 #include <type_traits>
22
23 template<typename T, typename = void>
24 struct has_type : std::false_type { };
25
26 template<typename T>
27 struct has_type<T, std::void_t<typename T::type>> : std::true_type { };
28
29 template<typename... T>
30 constexpr bool
31 has_common_ref()
32 {
33 return has_type<std::common_reference<T...>>::value;
34 }
35
36 using std::is_same_v;
37 using std::common_reference_t;
38
39 void test01()
40 {
41
42 static_assert( !has_common_ref<>() );
43 static_assert( !has_common_ref<char(*)(), int(*)()>() );
44 static_assert( !has_common_ref<void*, int>() );
45
46 static_assert( is_same_v<common_reference_t<int>, int> );
47 static_assert( is_same_v<common_reference_t<int&>, int&> );
48 static_assert( is_same_v<common_reference_t<void>, void> );
49 static_assert( is_same_v<common_reference_t<const void>, const void> );
50 static_assert( is_same_v<common_reference_t<const void, void>, void> );
51 static_assert( is_same_v<common_reference_t<void(*const)(), void(*)()>, void(*)()> );
52 static_assert( is_same_v<common_reference_t<int, int>, int> );
53 static_assert( is_same_v<common_reference_t<int&, int>, int> );
54 static_assert( is_same_v<common_reference_t<int, int&>, int> );
55 static_assert( is_same_v<common_reference_t<int&&, int>, int> );
56 static_assert( is_same_v<common_reference_t<int&, int&>, int&> );
57 static_assert( is_same_v<common_reference_t<int&, int&&>, const int&> );
58 static_assert( is_same_v<common_reference_t<int&&, int&>, const int&> );
59 static_assert( is_same_v<common_reference_t<int&&, int&&>, int&&> );
60 static_assert( is_same_v<common_reference_t<int&&, const int&&>, const int&&> );
61 static_assert( is_same_v<common_reference_t<int&, int&, int&&>, const int&> );
62 static_assert( is_same_v<common_reference_t<int&&, int&, int&>, const int&> );
63 static_assert( is_same_v<common_reference_t<char&, int&>, int> );
64 static_assert( is_same_v<common_reference_t<long&, int&>, long> );
65 }
66
67 struct A { };
68 struct B { };
69 struct C { };
70
71 template<template<typename> class AQual, template<typename> class BQual>
72 struct std::basic_common_reference<A, B, AQual, BQual>
73 {
74 using type = BQual<AQual<C>>;
75 };
76
77 static_assert( is_same_v<common_reference_t<A, B>, C> );
78 static_assert( is_same_v<common_reference_t<A&, B>, C&> );
79 static_assert( is_same_v<common_reference_t<A&, const B>, C&> );
80 static_assert( is_same_v<common_reference_t<const A, B&>, const C&> );
81 static_assert( is_same_v<common_reference_t<const A&, B&&>, const C&> );
82 static_assert( is_same_v<common_reference_t<const A, B&&>, const C&&> );
83
84 struct D { };
85 struct E { };
86 struct F { };
87
88 template<> struct std::common_type<D, E> { using type = F; };
89
90 static_assert( is_same_v<common_reference_t<D, E>, F> );
91 static_assert( is_same_v<common_reference_t<D&, E>, F> );
92 static_assert( is_same_v<common_reference_t<D&, E&&>, F> );