1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2005-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/>.
22 #include <testsuite_hooks.h>
23 #include <testsuite_rvalref.h>
25 using namespace __gnu_test;
27 // Test deque::push_back makes no unneeded copies.
31 bool test __attribute__((unused)) = true;
33 std::deque<copycounter> a;
35 copycounter::copycount = 0;
36 for(int i = 0; i < 1000; ++i)
38 VERIFY(copycounter::copycount == 1000);
41 // Test deque::push_front makes no unneeded copies.
45 bool test __attribute__((unused)) = true;
47 std::deque<copycounter> a;
49 copycounter::copycount = 0;
50 for(int i = 0; i < 1000; ++i)
52 VERIFY(copycounter::copycount == 1000);
55 // Test deque::insert makes no unneeded copies.
59 bool test __attribute__((unused)) = true;
61 std::deque<copycounter> a(1000);
63 copycounter::copycount = 0;
64 a.insert(a.begin(),c);
66 for(int i = 0; i < 500; ++i)
67 a.insert(a.begin() + i, c);
68 VERIFY(copycounter::copycount == 502);
71 // Test deque::insert(iterator, count, value) makes no unneeded copies
72 // when it has to also reallocate the deque's internal buffer.
76 bool test __attribute__((unused)) = true;
79 std::deque<copycounter> a(10, c);
80 copycounter::copycount = 0;
81 a.insert(a.begin(), 20, c);
82 VERIFY(copycounter::copycount == 20);
83 a.insert(a.end(), 50, c);
84 VERIFY(copycounter::copycount == 70);
85 // NOTE : These values are each one higher than might be expected, as
86 // deque::insert(iterator, count, value) copies the value it is given
87 // when it has to move elements in the deque in case that value is
91 a.insert(a.begin() + 10, 100, c);
92 VERIFY(copycounter::copycount == 170 + 1);
94 a.insert(a.end() - 10, 1000, c);
95 VERIFY(copycounter::copycount == 1170 + 2);
98 // Test deque::insert(iterator, count, value) makes no unneeded copies
99 // when it doesn't have to reallocate the deque's internal buffer.
103 bool test __attribute__((unused)) = true;
106 std::deque<copycounter> a(10, c);
107 copycounter::copycount = 0;
109 a.insert(a.begin(), 20, c);
110 VERIFY(copycounter::copycount == 20 );
111 a.insert(a.end(), 50, c);
112 VERIFY(copycounter::copycount == 70 );
114 // NOTE : These values are each one higher than might be expected, as
115 // deque::insert(iterator, count, value) copies the value it is given
116 // when it has to move elements in the deque in case that value is
119 a.insert(a.begin() + 10, 100, c);
120 VERIFY(copycounter::copycount == 170 + 1);
122 a.insert(a.end() - 10, 200, c);
123 VERIFY(copycounter::copycount == 370 + 2);