1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.4.2.1 [tuple.cnstr] Allocator-extended constructors
24 #include <testsuite_hooks.h>
28 // type that can't be constructed with an allocator
31 CannotUse(int = 0, int = 0) : ok(true) { }
36 // type that can be constructed with an allocator
37 // but which has uses_allocator == false
40 typedef MyAlloc allocator_type
;
42 DoesNotUse(int = 0) : ok(true) { }
43 DoesNotUse(std::allocator_arg_t
, MyAlloc
, int = 0) : ok(false) { }
44 DoesNotUse(MyAlloc
) : ok(false) { }
45 DoesNotUse(int, MyAlloc
) : ok(false) { }
47 DoesNotUse(const DoesNotUse
&) : ok(true) { }
48 DoesNotUse(std::allocator_arg_t
, MyAlloc
, const DoesNotUse
&) : ok(false) { }
49 DoesNotUse(const DoesNotUse
&, MyAlloc
) : ok(false) { }
51 DoesNotUse(DoesNotUse
&&) : ok(true) { }
52 DoesNotUse(std::allocator_arg_t
, MyAlloc
, DoesNotUse
&&) : ok(false) { }
53 DoesNotUse(DoesNotUse
&&, MyAlloc
) : ok(false) { }
61 struct uses_allocator
<DoesNotUse
, A
> : false_type
{ };
64 // type that can be constructed with an allocator as second argument
67 typedef MyAlloc allocator_type
;
69 UsesWithTag(int = 0) : ok(false) { }
70 UsesWithTag(std::allocator_arg_t
, MyAlloc
, int = 0) : ok(true) { }
71 UsesWithTag(MyAlloc
) : ok(false) { }
72 UsesWithTag(int, MyAlloc
) : ok(false) { }
74 UsesWithTag(const UsesWithTag
&) : ok(false) { }
75 UsesWithTag(std::allocator_arg_t
, MyAlloc
, const UsesWithTag
&) : ok(true) { }
76 UsesWithTag(const UsesWithTag
&, MyAlloc
) : ok(false) { }
78 UsesWithTag(UsesWithTag
&&) : ok(false) { }
79 UsesWithTag(std::allocator_arg_t
, MyAlloc
, UsesWithTag
&&) : ok(true) { }
80 UsesWithTag(UsesWithTag
&&, MyAlloc
) : ok(false) { }
85 // type that can be constructed with an allocator as last argument
88 typedef MyAlloc allocator_type
;
90 UsesWithoutTag(int = 0) : ok(false) { }
91 UsesWithoutTag(MyAlloc
) : ok(true) { }
92 UsesWithoutTag(int, MyAlloc
) : ok(true) { }
94 UsesWithoutTag(const UsesWithoutTag
&) : ok(false) { }
95 UsesWithoutTag(const UsesWithoutTag
&, MyAlloc
) : ok(true) { }
97 UsesWithoutTag(UsesWithoutTag
&&) : ok(false) { }
98 UsesWithoutTag(UsesWithoutTag
&&, MyAlloc
) : ok(true) { }
105 bool test
__attribute__((unused
)) = true;
106 using std::allocator_arg
;
108 using std::make_tuple
;
111 typedef CannotUse T1
;
112 typedef DoesNotUse T2
;
113 typedef UsesWithTag T3
;
114 typedef UsesWithoutTag T4
;
115 typedef tuple
<T1
, T2
, T3
, T4
> test_type
;
119 // default construction
120 test_type
t1(allocator_arg
, a
);
121 VERIFY( get
<0>(t1
).ok
);
122 VERIFY( get
<1>(t1
).ok
);
123 VERIFY( get
<2>(t1
).ok
);
124 VERIFY( get
<3>(t1
).ok
);
127 test_type
t2(allocator_arg
, a
, t1
);
128 VERIFY( get
<0>(t2
).ok
);
129 VERIFY( get
<1>(t2
).ok
);
130 VERIFY( get
<2>(t2
).ok
);
131 VERIFY( get
<3>(t2
).ok
);
134 test_type
t3(allocator_arg
, a
, std::move(t1
));
135 VERIFY( get
<0>(t3
).ok
);
136 VERIFY( get
<1>(t3
).ok
);
137 VERIFY( get
<2>(t3
).ok
);
138 VERIFY( get
<3>(t3
).ok
);
140 // construction from int
141 test_type
t4(allocator_arg
, a
, 1, 2, 3, 4);
142 VERIFY( get
<0>(t4
).ok
);
143 VERIFY( get
<1>(t4
).ok
);
144 VERIFY( get
<2>(t4
).ok
);
145 VERIFY( get
<3>(t4
).ok
);
147 auto ints
= make_tuple(1, 2, 3, 4);
149 // construction from lvalue tuple of ints
150 test_type
t5(allocator_arg
, a
, ints
);
151 VERIFY( get
<0>(t5
).ok
);
152 VERIFY( get
<1>(t5
).ok
);
153 VERIFY( get
<2>(t5
).ok
);
154 VERIFY( get
<3>(t2
).ok
);
156 // construction from rvalue tuple of ints
157 test_type
t6(allocator_arg
, a
, std::move(ints
));
158 VERIFY( get
<0>(t6
).ok
);
159 VERIFY( get
<1>(t6
).ok
);
160 VERIFY( get
<2>(t6
).ok
);
161 VERIFY( get
<3>(t6
).ok
);