diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc')
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc new file mode 100644 index 000000000..969cb1c92 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +// Test vector::push_back makes no unneeded copies. +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<copycounter> a; + copycounter c(1); + copycounter::copycount = 0; + for(int i = 0; i < 10; ++i) + a.push_back(c); + VERIFY(copycounter::copycount == 10); + + for(int i = 0; i < 100; ++i) + a.insert(a.begin() + i, c); + VERIFY(copycounter::copycount == 110); + + for(int i = 0; i < 1000; ++i) + a.insert(a.end(), c); + VERIFY(copycounter::copycount == 1110); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test02() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c), b(100, c); + copycounter::copycount = 0; + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test03() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c), b(100, c); + copycounter::copycount = 0; + a.reserve(1000); + VERIFY(copycounter::copycount == 0); + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test04() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c); + copycounter::copycount = 0; + a.insert(a.begin(), 20, c); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test05() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c); + copycounter::copycount = 0; + a.reserve(1000); + a.insert(a.begin(), 20, c); + // NOTE : These values are each one higher than might be expected, as + // vector::insert(iterator, count, value) copies the value it is given + // when it doesn't reallocate the buffer. + VERIFY(copycounter::copycount == 20 + 1); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70 + 2); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170 + 3); +} + + + +int main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} |