]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/operator_plus.cc
1 // 2019-04-30 Nina Dinka Ranns <dinka.ranns@gmail.com>
2 // Copyright (C) 2019-2021 Free Software Foundation, Inc.
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 // { dg-do run { target c++11 } }
20 // COW strings don't support C++11 allocator propagation:
21 // { dg-require-effective-target cxx11-abi }
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
26 #include <ext/throw_allocator.h>
29 using traits
= std::char_traits
<C
>;
31 using __gnu_test::propagating_allocator
;
35 typedef propagating_allocator
<C
, true> alloc_type
;
36 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
38 test_type
v1("something",alloc_type(1));
39 test_type
v2("something",alloc_type(2));
41 VERIFY(r1
.get_allocator().get_personality() == 1);
43 auto r2
= v1
+ std::move(v2
);
44 VERIFY(r2
.get_allocator().get_personality() == 2);
46 test_type
v3("something", alloc_type(3));
47 test_type
v4("something", alloc_type(4));
48 auto r3
= std::move(v3
) + v4
;
49 VERIFY(r3
.get_allocator().get_personality() == 3);
51 auto r4
= std::move(v1
) +std::move(v4
);
52 VERIFY(r4
.get_allocator().get_personality() == 1);
54 test_type
v5("something", alloc_type(5));
56 VERIFY(r5
.get_allocator().get_personality() == 5);
59 VERIFY(r6
.get_allocator().get_personality() == 5);
61 auto r7
= std::move(v5
) + "str";
62 VERIFY(r7
.get_allocator().get_personality() == 5);
64 test_type
v6("something", alloc_type(6));
65 auto r8
= std::move(v6
) + 'c';
66 VERIFY(r8
.get_allocator().get_personality() == 6);
68 test_type
v7("something", alloc_type(7));
70 VERIFY(r9
.get_allocator().get_personality() == 7);
73 VERIFY(r10
.get_allocator().get_personality() == 7);
75 auto r11
= "str" + std::move(v7
);
76 VERIFY(r11
.get_allocator().get_personality() == 7);
78 test_type
v8("something", alloc_type(8));
79 auto r12
= 'c' + std::move(v8
);
80 VERIFY(r12
.get_allocator().get_personality() == 8);
84 typedef propagating_allocator
<C
, false> alloc_type
;
85 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
87 test_type
v1("something",alloc_type(1));
88 test_type
v2("something",alloc_type(2));
90 VERIFY(r1
.get_allocator().get_personality() != 1);
92 auto r2
= v1
+ std::move(v2
);
93 VERIFY(r2
.get_allocator().get_personality() == 2);
95 test_type
v3("something", alloc_type(3));
96 test_type
v4("something", alloc_type(4));
97 auto r3
= std::move(v3
) + v4
;
98 VERIFY(r3
.get_allocator().get_personality() == 3);
100 auto r4
= std::move(v1
) +std::move(v4
);
101 VERIFY(r4
.get_allocator().get_personality() == 1);
103 test_type
v5("something", alloc_type(5));
104 auto r5
= v5
+ "str";
105 VERIFY(r5
.get_allocator().get_personality() != 5);
108 VERIFY(r6
.get_allocator().get_personality() != 5);
110 auto r7
= std::move(v5
) + "str";
111 VERIFY(r7
.get_allocator().get_personality() == 5);
113 test_type
v6("something", alloc_type(6));
114 auto r8
= std::move(v6
) + 'c';
115 VERIFY(r8
.get_allocator().get_personality() == 6);
117 test_type
v7("something", alloc_type(7));
118 auto r9
= "str" + v7
;
119 VERIFY(r9
.get_allocator().get_personality() != 7);
122 VERIFY(r10
.get_allocator().get_personality() != 7);
124 auto r11
= "str" + std::move(v7
);
125 VERIFY(r11
.get_allocator().get_personality() == 7);
127 test_type
v8("something", alloc_type(8));
128 auto r12
= 'c' + std::move(v8
);
129 VERIFY(r12
.get_allocator().get_personality() == 8);
133 typedef propagating_allocator
<C
, false> alloc_type
;
134 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
136 test_type
v1("s",alloc_type(1));
139 test_type
v2(10000,'x',alloc_type(2));
142 auto r
=std::move(v1
)+std::move(v2
);
143 VERIFY(r
.get_allocator().get_personality() == 1);