-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe8.cpp
84 lines (66 loc) · 1.54 KB
/
e8.cpp
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
//
// Created by martin on 11-10-22.
//
#include <bits/stdc++.h>
#include <ostream>
#include "Vector.hpp"
#define vector Vector
struct Test
{
int one;
int two;
Test (int one, int two) :
one(one),
two(two)
{
}
friend std::ostream &operator<< (std::ostream &os, const Test &test)
{
os << "{ " << test.one << ", " << test.two << " }";
return os;
}
};
using namespace std;
template < typename T >
void print (const vector<T> &v, int width = 3)
{
for (size_t i { 0 } ; i < v.size() ; ++i)
{
cout << setw(width) << v[i];
}
cout << endl;
}
int main (int argc, char *argv[])
try
{
Debug_vector<double> vd;
vd.push_back(123.123);
vd.push_back(321.321);
vd.push_back(222.222);
vd.push_back(12.12);
vd.push_back(33333.333);
print(vd, 8);
Debug_vector<Test> vt;
vt.push_back({ 1, 2 });
vt.push_back({ 3, 4 });
vt.push_back({ 5, 6 });
vt.push_back({ 7, 8 });
vt.push_back({ 9, 0 });
print(vt, 8);
/* don't work for classes with constructors, see page 1193 for more info. */
// Vector<string> vs;
//
// vs.push_back("Hello");
// vs.push_back("World");
// vs.push_back("C");
// vs.push_back("C++");
// vs.push_back("C/C++");
//
// print(vs, 12);
return EXIT_SUCCESS;
}
catch (exception &e)
{
cerr << "Error: " << e.what() << endl;
return EXIT_FAILURE;
}