]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/self_insert.cc
Add tests for inserting aliased objects into std::vector
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / modifiers / insert / self_insert.cc
CommitLineData
097e8994
FD
1// { dg-options "-std=gnu++11" }
2
3// Copyright (C) 2016 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#include <vector>
21
22#include "testsuite_hooks.h"
23
24bool test __attribute__((unused)) = true;
25
26void test01()
27{
28 std::vector<std::vector<int>> vv =
29 {
30 { 2, 3 },
31 { 4, 5 },
32 { 0, 1 }
33 };
34
35 // Make sure it doesn't reallocate during insertion.
36 vv.reserve(4);
37
38 vv.insert(vv.begin(), vv[0]);
39
40 VERIFY( vv.size() == 4 );
41 VERIFY( vv[0].size() == 2 );
42 VERIFY( vv[0][0] == 2 );
43 VERIFY( vv[0][1] == 3 );
44}
45
46void test02()
47{
48 std::vector<std::vector<int>> vv =
49 {
50 { 2, 3 },
51 { 4, 5 },
52 { 0, 1 }
53 };
54
55 // Make sure we will reallocate for insertion.
56 VERIFY( vv.capacity() == 3 );
57
58 vv.insert(vv.begin(), vv[0]);
59
60 VERIFY( vv.size() == 4 );
61 VERIFY( vv[0].size() == 2 );
62 VERIFY( vv[0][0] == 2 );
63 VERIFY( vv[0][1] == 3 );
64}
65
66int main()
67{
68 test01();
69 test02();
70}