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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt04.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "stdtest.h"
7
 
8
class A {
9
public:
10
    A (void)
11
    { cout << "A::A\n"; }
12
    A (const A&)
13
    { cout << "Copy A::A\n"; }
14
    const A& operator= (const A&)
15
    { cout << "A::operator=\n"; return (*this); }
16
    ~A (void)
17
    { cout << "A::~A\n"; }
18
};
19
 
20
void TestVector (void)
21
{
22
    static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 };
23
    vector<int> v;
24
    v.push_back (1);
25
    cout << v << endl;
26
    v.reserve (20);
27
    cout.format ("Reserved to capacity() == %zu (%zu used, ", v.capacity(), v.size());
28
    if (v.max_size() == SIZE_MAX / sizeof(int))
29
        cout << "SIZE_MAX/elsize";
30
    else
31
        cout << v.max_size();
32
    cout << " max)\n";
33
    v.insert (v.begin() + 1, 1 + VectorRange(c_TestNumbers));
34
    cout << v << endl;
35
    cout.format ("front() = %d, back() = %d\n", v.front(), v.back());
36
    v.erase (v.begin());
37
    v.pop_back();
38
    cout << v << endl;
39
    v.insert (v.begin() + 10, 3, 666);
40
    v.at(5) = 777;
41
    cout << v << endl;
42
    v.resize (v.size() - 5);
43
    if (v.empty())
44
        cout << "v is now empty\n";
45
    cout << v << endl;
46
    cout.format ("v[5] == %d\n", v[5]);
47
    v.clear();
48
    if (v.empty())
49
        cout << "v is now empty\n";
50
    vector<int> v2 (20, 66);
51
    cout << v2 << endl;
52
    v2.assign (20, 33);
53
    cout << v2 << endl;
54
    v.assign (VectorRange (c_TestNumbers));
55
    cout << v << endl;
56
    if (v == v2)
57
        cout << "v == v2\n";
58
    v2 = v;
59
    if (v == v2)
60
        cout << "v == v2\n";
61
    vector<A> ctv;
62
    A a;
63
    ctv.assign (3, a);
64
    ctv.pop_back();
65
    cout << "Class insertion testing successful\n";
66
}
67
 
68
StdBvtMain (TestVector)

powered by: WebSVN 2.1.0

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