OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [23_containers/] [vector/] [modifiers/] [moveable.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { dg-options "-std=gnu++0x" }
2
 
3
// Copyright (C) 2005, 2006, 2007, 2008, 2009 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 even 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
 
21
#include <vector>
22
#include <testsuite_hooks.h>
23
#include <testsuite_rvalref.h>
24
 
25
using namespace __gnu_test;
26
 
27
// Test vector::push_back makes no unneeded copies.
28
void
29
test01()
30
{
31
  bool test __attribute__((unused)) = true;
32
 
33
  std::vector<copycounter> a;
34
  copycounter c(1);
35
  copycounter::copycount = 0;
36
  for(int i = 0; i < 10; ++i)
37
    a.push_back(c);
38
  VERIFY(copycounter::copycount == 10);
39
 
40
  for(int i = 0; i < 100; ++i)
41
    a.insert(a.begin() + i, c);
42
  VERIFY(copycounter::copycount == 110);
43
 
44
  for(int i = 0; i < 1000; ++i)
45
    a.insert(a.end(), c);
46
  VERIFY(copycounter::copycount == 1110);
47
}
48
 
49
// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
50
// when it has to also reallocate the vector's internal buffer.
51
void
52
test02()
53
{
54
  bool test __attribute__((unused)) = true;
55
 
56
  copycounter c(1);
57
  std::vector<copycounter> a(10, c), b(100, c);
58
  copycounter::copycount = 0;
59
  a.insert(a.begin(), b.begin(), b.begin() + 20);
60
  VERIFY(copycounter::copycount == 20);
61
  a.insert(a.end(), b.begin(), b.begin() + 50);
62
  VERIFY(copycounter::copycount == 70);
63
  a.insert(a.begin() + 50, b.begin(), b.end());
64
  VERIFY(copycounter::copycount == 170);
65
}
66
 
67
// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
68
// when it doesn't have to reallocate the vector's internal buffer.
69
void
70
test03()
71
{
72
  bool test __attribute__((unused)) = true;
73
 
74
  copycounter c(1);
75
  std::vector<copycounter> a(10, c), b(100, c);
76
  copycounter::copycount = 0;
77
  a.reserve(1000);
78
  VERIFY(copycounter::copycount == 0);
79
  a.insert(a.begin(), b.begin(), b.begin() + 20);
80
  VERIFY(copycounter::copycount == 20);
81
  a.insert(a.end(), b.begin(), b.begin() + 50);
82
  VERIFY(copycounter::copycount == 70);
83
  a.insert(a.begin() + 50, b.begin(), b.end());
84
  VERIFY(copycounter::copycount == 170);
85
}
86
 
87
// Test vector::insert(iterator, count, value) makes no unneeded copies
88
// when it has to also reallocate the vector's internal buffer.
89
void
90
test04()
91
{
92
  bool test __attribute__((unused)) = true;
93
 
94
  copycounter c(1);
95
  std::vector<copycounter> a(10, c);
96
  copycounter::copycount = 0;
97
  a.insert(a.begin(), 20, c);
98
  VERIFY(copycounter::copycount == 20);
99
  a.insert(a.end(), 50, c);
100
  VERIFY(copycounter::copycount == 70);
101
  a.insert(a.begin() + 50, 100, c);
102
  VERIFY(copycounter::copycount == 170);
103
}
104
 
105
// Test vector::insert(iterator, count, value) makes no unneeded copies
106
// when it doesn't have to reallocate the vector's internal buffer.
107
void
108
test05()
109
{
110
  bool test __attribute__((unused)) = true;
111
 
112
  copycounter c(1);
113
  std::vector<copycounter> a(10, c);
114
  copycounter::copycount = 0;
115
  a.reserve(1000);
116
  a.insert(a.begin(), 20, c);
117
  // NOTE : These values are each one higher than might be expected, as
118
  // vector::insert(iterator, count, value) copies the value it is given
119
  // when it doesn't reallocate the buffer.
120
  VERIFY(copycounter::copycount == 20 + 1);
121
  a.insert(a.end(), 50, c);
122
  VERIFY(copycounter::copycount == 70 + 2);
123
  a.insert(a.begin() + 50, 100, c);
124
  VERIFY(copycounter::copycount == 170 + 3);
125
}
126
 
127
 
128
 
129
int main()
130
{
131
  test01();
132
  test02();
133
  test03();
134
  test04();
135
  test05();
136
  return 0;
137
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.