Merged revisions 195034,195219,195245,195357,195374,195428,195599,195673,195809 via...
[official-gcc.git] / main / libstdc++-v3 / testsuite / 20_util / tuple / cons / allocators.cc
blobb907a2e1020355a0c364cdec2cdbac27b8ef4930
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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
22 #include <memory>
23 #include <tuple>
24 #include <testsuite_hooks.h>
26 struct MyAlloc { };
28 // type that can't be constructed with an allocator
29 struct CannotUse
31 CannotUse(int = 0, int = 0) : ok(true) { }
33 bool ok;
36 // type that can be constructed with an allocator
37 // but which has uses_allocator == false
38 struct DoesNotUse
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) { }
55 bool ok;
58 namespace std
60 template<typename A>
61 struct uses_allocator<DoesNotUse, A> : false_type { };
64 // type that can be constructed with an allocator as second argument
65 struct UsesWithTag
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) { }
82 bool ok;
85 // type that can be constructed with an allocator as last argument
86 struct UsesWithoutTag
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) { }
100 bool ok;
103 void test01()
105 bool test __attribute__((unused)) = true;
106 using std::allocator_arg;
107 using std::tuple;
108 using std::make_tuple;
109 using std::get;
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;
117 MyAlloc a;
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 );
126 // copy construction
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 );
133 // move construction
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 );
165 int main()
167 test01();
168 return 0;