]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc
4 // Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // 23.2.4.2 vector capacity
26 #include <testsuite_allocator.h>
27 #include <testsuite_hooks.h>
29 using __gnu_test::copy_tracker
;
30 using __gnu_test::allocation_tracker
;
31 using __gnu_test::tracker_alloc
;
32 using __gnu_test::copy_constructor
;
33 using __gnu_test::assignment_operator
;
34 using __gnu_test::destructor
;
36 // Verifies basic functionality of reserve() with forced reallocation.
41 typedef copy_tracker T
;
42 typedef std::vector
<T
, tracker_alloc
<T
> > X
;
44 allocation_tracker::resetCounts();
47 const X::size_type old_size
= a
.size();
48 const X::size_type old_capacity
= a
.capacity();
49 const X::size_type new_capacity
= old_capacity
+ 10;
52 a
.reserve(new_capacity
);
55 VERIFY(new_capacity
<= a
.capacity());
57 VERIFY(old_size
== a
.size());
58 VERIFY(copy_constructor::count() <= old_size
);
59 VERIFY(destructor::count() <= old_size
);
61 // check for memory leaks
62 VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
65 // Verifies that reserve() with reallocation offers the strong
66 // exception guarantee.
68 test_reserve_exception_guarantee()
71 typedef copy_tracker T
;
72 typedef std::vector
<T
, tracker_alloc
<T
> > X
;
74 allocation_tracker::resetCounts();
77 const X::size_type old_size
= a
.size();
78 const X::size_type old_capacity
= a
.capacity();
79 const X::size_type new_capacity
= old_capacity
+ 10;
81 copy_constructor::throw_on(3);
85 a
.reserve(new_capacity
);
86 VERIFY(("no exception thrown", false));
92 VERIFY(old_capacity
== a
.capacity());
93 VERIFY(copy_constructor::count() == destructor::count()+1);
95 VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
101 test_reserve_exception_guarantee();