summaryrefslogtreecommitdiff
path: root/ecos/packages/language/cxx/ustl/current/tests/bvt04.cpp
blob: f64ca70b0f145c854c6aa8996070c56e542ffb75 (plain)
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
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.

#include "stdtest.h"

class A {
public:
    A (void)
    { cout << "A::A\n"; }
    A (const A&)
    { cout << "Copy A::A\n"; }
    const A& operator= (const A&)
    { cout << "A::operator=\n"; return (*this); }
    ~A (void)
    { cout << "A::~A\n"; }
};

void TestVector (void)
{
    static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 };
    vector<int> v;
    v.push_back (1);
    cout << v << endl;
    v.reserve (20);
    cout.format ("Reserved to capacity() == %zu (%zu used, ", v.capacity(), v.size());
    if (v.max_size() == SIZE_MAX / sizeof(int))
	cout << "SIZE_MAX/elsize";
    else
	cout << v.max_size();
    cout << " max)\n";
    v.insert (v.begin() + 1, 1 + VectorRange(c_TestNumbers));
    cout << v << endl;
    cout.format ("front() = %d, back() = %d\n", v.front(), v.back());
    v.erase (v.begin());
    v.pop_back();
    cout << v << endl;
    v.insert (v.begin() + 10, 3, 666);
    v.at(5) = 777;
    cout << v << endl;
    v.resize (v.size() - 5);
    if (v.empty())
	cout << "v is now empty\n";
    cout << v << endl;
    cout.format ("v[5] == %d\n", v[5]);
    v.clear();
    if (v.empty())
	cout << "v is now empty\n";
    vector<int> v2 (20, 66);
    cout << v2 << endl;
    v2.assign (20, 33);
    cout << v2 << endl;
    v.assign (VectorRange (c_TestNumbers));
    cout << v << endl;
    if (v == v2)
	cout << "v == v2\n";
    v2 = v;
    if (v == v2)
	cout << "v == v2\n";
    vector<A> ctv;
    A a;
    ctv.assign (3, a);
    ctv.pop_back();
    cout << "Class insertion testing successful\n";
}

StdBvtMain (TestVector)