forked from precious/dr_program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_utils.h
More file actions
25 lines (21 loc) · 760 Bytes
/
Copy pathdata_utils.h
File metadata and controls
25 lines (21 loc) · 760 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
#ifndef DATA_UTILS_H
#define DATA_UTILS_H
// methods of this namespace act similar to the stl algorithms however don't use
// iterators and work only with containers that have operator[] (and with usual C arrays)
namespace Data {
// C - container type (vector or pointer to array)
// T - type of values in container
template <typename C,typename T>
static T reduce(function<T& (T&,T&)> f,C container,int size) {
T result = container[0];
for(int i = 1;i < size;i++)
result = f(result,container[i]);
return result;
}
template <typename C,typename T>
static void map(function<void (T&)> f,C container,int size) {
for(int i = 0;i < size;i++)
f(container[i]);
}
}
#endif // DATA_UTILS_H