1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*
* Copyright (C) 2017, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: config
*
* Author: Thorben Hasenpusch
*
* Purpose: Rudimentary tests for a working <vector> implementation.
*/
#include <vector>
struct Recursive : std::vector<Recursive>
{
int i;
};
int main()
{
std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if (v.size() != 3) {
return -1;
}
if (v[2] != 3) {
return -1;
}
v.erase(v.begin());
if (v[0] != 2) {
return -1;
}
v.pop_back();
if (v.size() != 1) {
return -1;
}
v.clear();
v.push_back(42);
v.push_back(13);
v.resize(1);
if (v.size() != 1 || v[0] != 42) {
return -1;
}
if (v.front() != v[0]) {
return -1;
}
if (v.back() != v[v.size() - 1]) {
return -1;
}
// ensure iterators are NOT invalidated by swap()
std::vector<int>::iterator it = v.begin();
std::vector<int> w;
w.push_back(23);
v.swap(w);
if (it != w.begin()) {
return -1;
}
// test if recursive vector structures can be constructed without causing
// a stack overflow
if (std::vector<Recursive>().size() != 0) {
return -1;
}
// test whether we can compare const and mutable iterators
std::vector<int>::const_iterator cit = w.begin();
if (it != cit) {
return -1;
}
return 0;
}
|