summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/tuple/dr2729.cc
blob: 1c6c67e44e1b498f784a9fac0de9d74f7e06f78a (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (C) 2018-2020 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/>.

// { dg-do compile { target c++11 } }

#include <tuple>
#include <testsuite_tr1.h>

using std::tuple;
using std::pair;
using __gnu_test::assign::AnyAssign;
using __gnu_test::assign::DelAnyAssign;
using __gnu_test::assign::DelCopyAssign;
using __gnu_test::CopyConsOnlyType;

// Copy assignment:
template<typename T>
constexpr bool copy() { return std::is_copy_assignable<T>::value; }

// Move assigmment:
template<typename T>
constexpr bool move() { return std::is_move_assignable<T>::value; }

static_assert( copy<tuple<>>(), "");
static_assert( move<tuple<>>(), "");

static_assert( copy<tuple<int>>(), "");
static_assert( copy<tuple<AnyAssign>>(), "");
static_assert( copy<tuple<int, int>>(), "");
static_assert( copy<tuple<AnyAssign, AnyAssign>>(), "");
static_assert( copy<tuple<int, AnyAssign>>(), "");
static_assert( copy<tuple<AnyAssign, int>>(), "");
static_assert( copy<tuple<int, int, int>>(), "");
static_assert( copy<tuple<AnyAssign, AnyAssign, AnyAssign>>(), "");
static_assert( copy<tuple<int, AnyAssign, AnyAssign>>(), "");
static_assert( copy<tuple<AnyAssign, int, AnyAssign>>(), "");
static_assert( copy<tuple<AnyAssign, AnyAssign, int>>(), "");

static_assert( move<tuple<int>>(), "");
static_assert( move<tuple<AnyAssign>>(), "");
static_assert( move<tuple<int, int>>(), "");
static_assert( move<tuple<AnyAssign, AnyAssign>>(), "");
static_assert( move<tuple<int, AnyAssign>>(), "");
static_assert( move<tuple<AnyAssign, int>>(), "");
static_assert( move<tuple<int, int, int>>(), "");
static_assert( move<tuple<AnyAssign, AnyAssign, AnyAssign>>(), "");
static_assert( move<tuple<int, AnyAssign, AnyAssign>>(), "");
static_assert( move<tuple<AnyAssign, int, AnyAssign>>(), "");
static_assert( move<tuple<AnyAssign, AnyAssign, int>>(), "");

static_assert( ! copy<tuple<DelCopyAssign>>(), "");
static_assert( ! copy<tuple<DelCopyAssign, int>>(), "");
static_assert( ! copy<tuple<int, DelCopyAssign>>(), "");
static_assert( ! copy<tuple<DelCopyAssign, int, int>>(), "");
static_assert( ! copy<tuple<int, DelCopyAssign, int>>(), "");
static_assert( ! copy<tuple<int, int, DelCopyAssign>>(), "");

static_assert( move<tuple<DelCopyAssign>>(), "");
static_assert( move<tuple<DelCopyAssign, int>>(), "");
static_assert( move<tuple<int, DelCopyAssign>>(), "");
static_assert( move<tuple<DelCopyAssign, int, int>>(), "");
static_assert( move<tuple<int, DelCopyAssign, int>>(), "");
static_assert( move<tuple<int, int, DelCopyAssign>>(), "");

static_assert( ! move<tuple<CopyConsOnlyType>>(), "");
static_assert( ! move<tuple<CopyConsOnlyType, int>>(), "");
static_assert( ! move<tuple<int, CopyConsOnlyType>>(), "");
static_assert( ! move<tuple<CopyConsOnlyType, int, int>>(), "");
static_assert( ! move<tuple<int, CopyConsOnlyType, int>>(), "");
static_assert( ! move<tuple<int, int, CopyConsOnlyType>>(), "");

// Assignment from different types of tuple (and pair):
template<typename To, typename From>
constexpr bool assign() { return std::is_assignable<To&, From>::value; }

// 0-tuples
static_assert( ! assign<tuple<>, tuple<int>>(), "" );
static_assert( ! assign<tuple<>, const tuple<int>&>(), "" );

// 1-tuples
static_assert( ! assign<tuple<int>, tuple<>>(), "" );
static_assert( ! assign<tuple<int>, const tuple<>&>(), "" );
static_assert( ! assign<tuple<AnyAssign>, tuple<>>(), "" );
static_assert( ! assign<tuple<AnyAssign>, tuple<int, int>>(), "" );
static_assert( ! assign<tuple<AnyAssign>, pair<int, int>>(), "" );

static_assert( ! assign<tuple<void*>, tuple<int>>(), "" );
static_assert( ! assign<tuple<void*>, const tuple<int>&>(), "" );

static_assert( assign<tuple<long>, tuple<int>>(), "" );
static_assert( assign<tuple<long>, tuple<int>&>(), "" );
static_assert( assign<tuple<long>, const tuple<int>>(), "" );
static_assert( assign<tuple<long>, const tuple<int>&>(), "" );

// 2-tuples
static_assert( assign<tuple<long, long>, tuple<int, int>>(), "" );
static_assert( assign<tuple<long, long>, tuple<int, int>&>(), "" );
static_assert( assign<tuple<long, long>, const tuple<int, int>>(), "" );
static_assert( assign<tuple<long, long>, const tuple<int, int>&>(), "" );

static_assert( assign<tuple<long, long>, pair<int, int>>(), "" );
static_assert( assign<tuple<long, long>, const pair<int, int>&>(), "" );
static_assert( assign<tuple<long, long>, pair<int, int>>(), "" );
static_assert( assign<tuple<long, long>, const pair<int, int>&&>(), "" );

static_assert( assign<tuple<DelCopyAssign, AnyAssign>,
		      tuple<DelCopyAssign, int>>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			tuple<DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			const tuple<DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			const tuple<DelCopyAssign, int>&&>(), "" );

static_assert( assign<tuple<AnyAssign, DelCopyAssign>,
		      tuple<int, DelCopyAssign>>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			tuple<int, DelCopyAssign>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			const tuple<int, DelCopyAssign>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			const tuple<int, DelCopyAssign>&&>(), "" );

static_assert( ! assign<tuple<void*, int>,
			tuple<int, int>>(), "" );
static_assert( ! assign<tuple<void*, int>,
			const tuple<int, int>&>(), "" );

static_assert( assign<tuple<DelCopyAssign, AnyAssign>,
		      pair<DelCopyAssign, int>>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			pair<DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			const pair<DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<DelCopyAssign, AnyAssign>,
			const pair<DelCopyAssign, int>&&>(), "" );

static_assert( assign<tuple<AnyAssign, DelCopyAssign>,
		      pair<int, DelCopyAssign>>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			pair<int, DelCopyAssign>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			const pair<int, DelCopyAssign>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign>,
			const pair<int, DelCopyAssign>&&>(), "" );

static_assert( ! assign<tuple<void*, int>,
			pair<int, int>>(), "" );
static_assert( ! assign<tuple<void*, int>,
			const pair<int, int>&>(), "" );

// 3-tuples
static_assert( assign<tuple<AnyAssign, DelCopyAssign, AnyAssign>,
		      tuple<int, DelCopyAssign, int>>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign, AnyAssign>,
			tuple<int, DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign, AnyAssign>,
			const tuple<int, DelCopyAssign, int>&>(), "" );
static_assert( ! assign<tuple<AnyAssign, DelCopyAssign, AnyAssign>,
			const tuple<int, DelCopyAssign, int>&&>(), "" );

static_assert( ! assign<tuple<int, void*, int>,
			tuple<int, int, int>>(), "" );
static_assert( ! assign<tuple<int, void*, int>,
			const tuple<int, int, int>&>(), "" );