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