]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2005, 2007 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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 #include <testsuite_hooks.h>
32 #include <testsuite_rvalref.h>
34 using namespace __gnu_test
;
36 // Test vector::push_back makes no unneeded copies.
40 bool test
__attribute__((unused
)) = true;
42 std::vector
<copycounter
> a
;
44 copycounter::copycount
= 0;
45 for(int i
= 0; i
< 10; ++i
)
47 VERIFY(copycounter::copycount
== 10);
49 for(int i
= 0; i
< 100; ++i
)
50 a
.insert(a
.begin() + i
, c
);
51 VERIFY(copycounter::copycount
== 110);
53 for(int i
= 0; i
< 1000; ++i
)
55 VERIFY(copycounter::copycount
== 1110);
58 // Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
59 // when it has to also reallocate the vector's internal buffer.
63 bool test
__attribute__((unused
)) = true;
66 std::vector
<copycounter
> a(10, c
), b(100, c
);
67 copycounter::copycount
= 0;
68 a
.insert(a
.begin(), b
.begin(), b
.begin() + 20);
69 VERIFY(copycounter::copycount
== 20);
70 a
.insert(a
.end(), b
.begin(), b
.begin() + 50);
71 VERIFY(copycounter::copycount
== 70);
72 a
.insert(a
.begin() + 50, b
.begin(), b
.end());
73 VERIFY(copycounter::copycount
== 170);
76 // Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
77 // when it doesn't have to reallocate the vector's internal buffer.
81 bool test
__attribute__((unused
)) = true;
84 std::vector
<copycounter
> a(10, c
), b(100, c
);
85 copycounter::copycount
= 0;
87 VERIFY(copycounter::copycount
== 0);
88 a
.insert(a
.begin(), b
.begin(), b
.begin() + 20);
89 VERIFY(copycounter::copycount
== 20);
90 a
.insert(a
.end(), b
.begin(), b
.begin() + 50);
91 VERIFY(copycounter::copycount
== 70);
92 a
.insert(a
.begin() + 50, b
.begin(), b
.end());
93 VERIFY(copycounter::copycount
== 170);
96 // Test vector::insert(iterator, count, value) makes no unneeded copies
97 // when it has to also reallocate the vector's internal buffer.
101 bool test
__attribute__((unused
)) = true;
104 std::vector
<copycounter
> a(10, c
);
105 copycounter::copycount
= 0;
106 a
.insert(a
.begin(), 20, c
);
107 VERIFY(copycounter::copycount
== 20 + 1);
108 a
.insert(a
.end(), 50, c
);
109 VERIFY(copycounter::copycount
== 70 + 2);
110 a
.insert(a
.begin() + 50, 100, c
);
111 VERIFY(copycounter::copycount
== 170 + 3);
114 // Test vector::insert(iterator, count, value) makes no unneeded copies
115 // when it doesn't have to reallocate the vector's internal buffer.
119 bool test
__attribute__((unused
)) = true;
122 std::vector
<copycounter
> a(10, c
);
123 copycounter::copycount
= 0;
125 a
.insert(a
.begin(), 20, c
);
126 // NOTE : These values are each one higher than might be expected, as
127 // vector::insert(iterator, count, value) copies the value it is given
128 // when it doesn't reallocate the buffer.
129 VERIFY(copycounter::copycount
== 20 + 1);
130 a
.insert(a
.end(), 50, c
);
131 VERIFY(copycounter::copycount
== 70 + 2);
132 a
.insert(a
.begin() + 50, 100, c
);
133 VERIFY(copycounter::copycount
== 170 + 3);