]>
Commit | Line | Data |
---|---|---|
8868286e | 1 | // { dg-options "-std=gnu++11" } |
e857783f | 2 | |
f1717362 | 3 | // Copyright (C) 2011-2016 Free Software Foundation, Inc. |
e857783f | 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. | |
10 | ||
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. | |
15 | ||
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/>. | |
19 | ||
20 | #include <memory> | |
21 | #include <scoped_allocator> | |
22 | #include <vector> | |
23 | #include <testsuite_hooks.h> | |
24 | #include <testsuite_allocator.h> | |
25 | ||
26 | using __gnu_test::uneq_allocator; | |
27 | ||
28 | struct Element | |
29 | { | |
30 | typedef uneq_allocator<Element> allocator_type; | |
31 | ||
32 | allocator_type alloc; | |
33 | ||
34 | Element(const allocator_type& a = allocator_type()) : alloc(a) { } | |
35 | ||
106b97d3 | 36 | Element(std::allocator_arg_t, const allocator_type& a, int = 0) |
e857783f | 37 | : alloc(a) { } |
38 | ||
39 | Element(std::allocator_arg_t, const allocator_type& a, const Element&) | |
40 | : alloc(a) { } | |
41 | ||
42 | const allocator_type& get_allocator() const { return alloc; } | |
43 | }; | |
44 | ||
45 | void test01() | |
46 | { | |
47 | bool test __attribute((unused)) = false; | |
48 | ||
49 | typedef std::scoped_allocator_adaptor<Element::allocator_type> alloc1_type; | |
50 | ||
51 | typedef std::vector<Element, alloc1_type> EltVec; | |
52 | ||
53 | alloc1_type a1(1); | |
54 | Element e; | |
55 | EltVec ev1(1, e, a1); | |
106b97d3 | 56 | VERIFY( ev1.get_allocator().get_personality() == 1 ); |
e857783f | 57 | VERIFY( ev1[0].get_allocator().get_personality() == 1 ); |
58 | } | |
59 | ||
60 | void test02() | |
61 | { | |
62 | bool test __attribute((unused)) = false; | |
63 | ||
106b97d3 | 64 | typedef std::scoped_allocator_adaptor<Element::allocator_type> inner_alloc_type; |
e857783f | 65 | |
106b97d3 | 66 | typedef std::vector<Element, inner_alloc_type> EltVec; |
67 | ||
68 | typedef std::scoped_allocator_adaptor<Element::allocator_type, | |
69 | Element::allocator_type> alloc_type; | |
e857783f | 70 | |
71 | typedef std::vector<EltVec, alloc_type> EltVecVec; | |
72 | ||
106b97d3 | 73 | alloc_type a(1, Element::allocator_type(2)); // outer=1, inner=2 |
e857783f | 74 | Element e; |
75 | EltVec ev(1, e); | |
76 | EltVecVec evv(1, ev, a); | |
77 | ||
78 | VERIFY( evv.get_allocator().get_personality() == 1 ); | |
79 | VERIFY( evv[0].get_allocator().get_personality() == 2 ); | |
80 | VERIFY( evv[0][0].get_allocator().get_personality() == 2 ); | |
81 | ||
106b97d3 | 82 | alloc_type a2(3, Element::allocator_type(4)); // outer=3, inner=4 |
e857783f | 83 | |
84 | EltVecVec evv2(evv, a2); // copy with a different allocator | |
85 | ||
86 | VERIFY( evv2.get_allocator().get_personality() == 3 ); | |
87 | VERIFY( evv2[0].get_allocator().get_personality() == 4 ); | |
88 | VERIFY( evv2[0][0].get_allocator().get_personality() == 4 ); | |
89 | ||
90 | EltVecVec evv3(std::move(evv), a2); // move with a different allocator | |
91 | ||
92 | VERIFY( evv3.get_allocator().get_personality() == 3 ); | |
93 | VERIFY( evv3[0].get_allocator().get_personality() == 4 ); | |
94 | VERIFY( evv3[0][0].get_allocator().get_personality() == 4 ); | |
95 | ||
96 | } | |
97 | ||
98 | ||
99 | int main() | |
100 | { | |
101 | test01(); | |
106b97d3 | 102 | test02(); |
e857783f | 103 | } |