-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession4_templates.cpp
52 lines (43 loc) · 1.06 KB
/
session4_templates.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
// C++ 101 de chillin - Sesión 4
// https://youtu.be/2MfsjLpTIZc
// https://www.twitch.tv/videos/966204946
//
// Twitter: @pablomarc0s y @BytesAndHumans
// Twitch: https://www.twitch.tv/nietmetal
// Youtube: https://www.youtube.com/channel/UCl_nn643qHc9_jnuskaXCGA
#include <cstdio>
#include <vector>
#include <variant>
/*int sum(int a, int b) {
return a + b;
}
float sum(float a, float b) {
return a + b;
}*/
// template <class T>
/*template <typename T>
T sum(T a, T b) {
return a + b;
}*/
template <typename T, typename U>
T sum(T a, U b) {
return a + b;
}
int main(int argc, char *argv[])
{
printf("Templates\n");
printf("sum ints: %d\n", sum(1, 2));
printf("sum floats: %f\n", sum(1.0f, 2.0f));
sum(1, 2.0f);
std::vector<int> myVector;
myVector.emplace_back(1);
myVector.emplace_back(2);
myVector.emplace_back(3);
myVector.emplace_back(4);
myVector.emplace_back(5);
for (auto value : myVector) {
printf("%d, ", value);
}
printf("\n");
std::vector<std::variant<int, double>> myVariantVector;
}