]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
8d9254fc 1// Copyright (C) 2019-2020 Free Software Foundation, Inc.
0f8b14ee
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
18// { dg-options "-std=gnu++2a" }
19// { dg-do compile { target c++2a } }
20
21#include <type_traits>
22
23template<typename T, typename = void>
24 struct has_type : std::false_type { };
25
26template<typename T>
27 struct has_type<T, std::void_t<typename T::type>> : std::true_type { };
28
29template<typename... T>
30constexpr bool
31has_common_ref()
32{
33 return has_type<std::common_reference<T...>>::value;
34}
35
36using std::is_same_v;
37using std::common_reference_t;
38
39void 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
67struct A { };
68struct B { };
69struct C { };
70
71template<template<typename> class AQual, template<typename> class BQual>
72struct std::basic_common_reference<A, B, AQual, BQual>
73{
74 using type = BQual<AQual<C>>;
75};
76
77static_assert( is_same_v<common_reference_t<A, B>, C> );
78static_assert( is_same_v<common_reference_t<A&, B>, C&> );
79static_assert( is_same_v<common_reference_t<A&, const B>, C&> );
80static_assert( is_same_v<common_reference_t<const A, B&>, const C&> );
81static_assert( is_same_v<common_reference_t<const A&, B&&>, const C&> );
82static_assert( is_same_v<common_reference_t<const A, B&&>, const C&&> );
83
84struct D { };
85struct E { };
86struct F { };
87
88template<> struct std::common_type<D, E> { using type = F; };
89
90static_assert( is_same_v<common_reference_t<D, E>, F> );
91static_assert( is_same_v<common_reference_t<D&, E>, F> );
92static_assert( is_same_v<common_reference_t<D&, E&&>, F> );