OSDN Git Service

2012-04-30 Andreas Tobler <andreast@fgznet.ch>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / vector / capacity / shrink_to_fit2.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2011 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
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/>.
19
20 #include <vector>
21 #include <testsuite_hooks.h>
22 #include <testsuite_allocator.h>
23
24 using __gnu_test::propagating_allocator;
25
26 void test01()
27 {
28   bool test __attribute__((unused)) = true;
29
30   typedef propagating_allocator<int, true> alloc_type;
31   alloc_type alloc(5);
32
33   std::vector<int, alloc_type> v(10u, 1, alloc);
34   v.reserve(100);
35   VERIFY( v.size() < v.capacity() );
36   v.shrink_to_fit();
37   VERIFY( v.size() == v.capacity() );
38   VERIFY( v.get_allocator().get_personality() == alloc.get_personality() );
39 }
40
41 void test02()
42 {
43   bool test __attribute__((unused)) = true;
44
45   typedef propagating_allocator<int, false> alloc_type;
46   alloc_type alloc(5);
47
48   std::vector<int, alloc_type> v(10u, 1, alloc);
49   v.reserve(100);
50   VERIFY( v.size() < v.capacity() );
51   v.shrink_to_fit();
52   VERIFY( v.size() == v.capacity() );
53   VERIFY( v.get_allocator().get_personality() == alloc.get_personality() );
54 }
55
56 int main()
57 {
58   test01();
59   test02();
60   return 0;
61 }