]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/common_reference/requirements/typedefs.cc
1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
21 #include <type_traits>
23 template<typename T
, typename
= void>
24 struct has_type
: std::false_type
{ };
27 struct has_type
<T
, std::void_t
<typename
T::type
>> : std::true_type
{ };
29 template<typename
... T
>
33 return has_type
<std::common_reference
<T
...>>::value
;
37 using std::common_reference_t
;
42 static_assert( !has_common_ref
<>() );
43 static_assert( !has_common_ref
<char(*)(), int(*)()>() );
44 static_assert( !has_common_ref
<void*, int>() );
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> );
71 template<template<typename
> class AQual
, template<typename
> class BQual
>
72 struct std::basic_common_reference
<A
, B
, AQual
, BQual
>
74 using type
= BQual
<AQual
<C
>>;
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
&&> );
88 template<> struct std::common_type
<D
, E
> { using type
= F
; };
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
> );