summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-3.cc
blob: 190fe91c13ec176dc3608145d8945949b71de0af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// { dg-do compile { target c++11 } }

// Copyright (C) 2011-2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

#include <functional>
#include <type_traits>

struct S { };

struct S0
{
  typedef int argument_type;
};

struct S1
{
  typedef float first_argument_type;
};

struct S2
{
  typedef char second_argument_type;
};

struct S01 : S0, S1 { };
struct S02 : S0, S2 { };
struct S12 : S1, S2 { };

struct S012 : S0, S1, S2 { };

using std::true_type;
using std::false_type;
using std::__void_t;

_GLIBCXX_HAS_NESTED_TYPE(argument_type)
_GLIBCXX_HAS_NESTED_TYPE(first_argument_type)
_GLIBCXX_HAS_NESTED_TYPE(second_argument_type)

template<typename T>
  struct has_arg_type : __has_argument_type<T>
  { };

template<typename T>
  struct has_1st_arg_type : __has_first_argument_type<T>
  { };

template<typename T>
  struct has_2nd_arg_type : __has_second_argument_type<T>
  { };

template<typename T, bool = has_arg_type<T>::value>
struct test_arg_type
{
  static_assert( !has_arg_type<std::reference_wrapper<T>>::value,
      "reference_wrapper has no nested argument_type");
};

template<typename T>
struct test_arg_type<T, true>
{
  typedef std::reference_wrapper<T> ref;

  static_assert( has_arg_type<ref>::value,
      "reference_wrapper has nested argument_type");

  static_assert(
      std::is_same< typename T::argument_type,
                    typename ref::argument_type >::value,
      "reference_wrapper has the correct argument_type");
};

template<typename T,
         bool = has_1st_arg_type<T>::value && has_2nd_arg_type<T>::value>
struct test_1st_2nd_arg_types
{
  typedef std::reference_wrapper<T> ref;

  static_assert( !has_1st_arg_type<ref>::value,
      "reference_wrapper has no nested first_argument_type");

  static_assert( !has_2nd_arg_type<ref>::value,
      "reference_wrapper has no nested second_argument_type");
};

template<typename T>
struct test_1st_2nd_arg_types<T, true>
{
  typedef std::reference_wrapper<T> ref;

  static_assert( has_1st_arg_type<ref>::value,
      "reference_wrapper has nested first_argument_type");

  static_assert( has_2nd_arg_type<ref>::value,
      "reference_wrapper has nested second_argument_type");

  static_assert(
      std::is_same< typename T::first_argument_type,
                    typename ref::first_argument_type>::value,
      "reference_wrapper has correct first_argument_type");

  static_assert(
      std::is_same< typename T::second_argument_type,
                    typename ref::second_argument_type>::value,
      "reference_wrapper has correct second_argument_type");
};


template<typename T>
  void test()
  {
    test_arg_type<T> t __attribute__((unused));
    test_arg_type<const T> tc __attribute__((unused));
    test_arg_type<volatile T> tv __attribute__((unused));
    test_arg_type<const volatile T> tcv __attribute__((unused));
    test_1st_2nd_arg_types<T> t12 __attribute__((unused));
    test_1st_2nd_arg_types<const T> t12c __attribute__((unused));
    test_1st_2nd_arg_types<volatile T> t12v __attribute__((unused));
    test_1st_2nd_arg_types<const volatile T> t12cv __attribute__((unused));
  }

int main()
{
  test<S>();
  test<S0>();
  test<S1>();
  test<S2>();
  test<S01>();
  test<S02>();
  test<S12>();
  test<S012>();
}