-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_example.cpp
More file actions
57 lines (42 loc) · 806 Bytes
/
auto_example.cpp
File metadata and controls
57 lines (42 loc) · 806 Bytes
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
#include <tuple>
#include <iostream>
#include <vector>
using namespace std;
void test1() {
vector<int> arrayOfInts = { 5, 3, 2, 6 };
// iteration using auto (copy)
for (auto i : arrayOfInts) {
cout << i << " ; ";
}
cout << endl;
}
void test2() {
vector<string> arrayOfString = { "String 1", "String 2" };
// iteration using auto reference
for (auto &i : arrayOfString) {
cout << i << " ; ";
}
cout << endl;
}
int getValue(int t) {
return 45;
}
float getValue(const char *s) {
return 6.87F;
}
template<typename Type>
void doSomething(Type v) {
auto returnValue = getValue(v);
returnValue *= 2;
cout << returnValue << endl;
}
void test3() {
doSomething(6);
doSomething("A string");
}
int main(int argc, const char * *argv) {
test1();
test2();
test3();
cout << endl;
}