-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
64 lines (50 loc) · 998 Bytes
/
main.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
/*
Author: Maverick Peppers
Date: 10/22/2018
Example file
See `Enumerate.h` for more info
*/
#include "Enumerate.h"
#include <iostream>
#include <vector>
#include <map>
#include <string>
int main() {
std::vector<int> test{1, 2, 3, 4, 5};
f(test);
g(test);
std::map<std::string, int> map{{"a", 10}, {"b", 9},{"c", 7}, {"d", 8}};
h(map);
}
int f(std::vector<int>& ints)
{
int result = 0;
size_t i = 0;
for(auto iter = ints.begin(); iter != ints.end();)
{
result += i + *iter;
++i;
++iter;
}
return result;
}
int g(std::vector<int>& ints)
{
int result = 0;
for(const auto& [i, n] : enumerate(ints))
{
result += i + n;
++n;
}
return result;
}
int h(std::map<std::string, int>& map)
{
int result = 0;
for(auto i : enumerate(map))
{
// i will be index to the key-value pair at map[i]
std::cout << "index: " << i << std::endl;
}
return result;
}