-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator_basics.cpp
More file actions
62 lines (54 loc) · 1.18 KB
/
iterator_basics.cpp
File metadata and controls
62 lines (54 loc) · 1.18 KB
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
#include <iostream>
#include<stdexcept>
#include<algorithm>
#include<numeric>
#include "vector.h"
#include<functional>
using namespace std;
int main(){
Vector x;
// Test der Absicherung
x.push_back(1);
auto e = x.end();
auto b = x.begin();
try{
cout << *e << endl;
}catch(runtime_error &e){
cout << e.what() << endl;
}
cout << *b << endl;
x.pop_back();
try{
cout << *b << endl;
}catch(runtime_error &e){
cout << e.what() << endl;
}
// Test von Max
Vector y{5,10,8};
auto i = max_element(y.begin(),y.end());
cout << "Max: " << *i << endl;
// Testen sie Min, Accumulate, count_if, ..., Sort
// Test von reserve, ==/!=, ++ postfix/prefix, operator->, insert/erase und range based for
y.reserve(20);
i = y.begin();
++i;
Vector::const_iterator j{i++};
if (i == j) cout << "should not happen";
if (++j != i) cout << "should not happen too";
cout << *(j.operator->()) << '\n';
i = y.insert(i,7);
j = i = y.insert(i,4);
y.insert(++i,9);
y.erase(j);
for (const auto& val : y) cout << val << " ";
cout << '\n';
return 0;
}
/*
[Fehlermeldung]
1
[Fehlermeldung]
Max: 10
8
5 10 9 7 8
*/