-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin.hpp
More file actions
72 lines (66 loc) · 1.69 KB
/
Copy pathbuiltin.hpp
File metadata and controls
72 lines (66 loc) · 1.69 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
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <vector>
#include <string>
#include <list>
template<typename T>
std::list<T> l(T arg)
{
std::list<T> retValue;
retValue.push_back(arg);
return retValue;
}
template<typename T, typename... Args>
std::list<T> l(T value, Args... args)
{
std::list<T> retValue;
retValue.push_back(value);
for (T arg : l(args...))
{
retValue.push_back(arg);
}
return retValue;
}
template <typename Func,typename Container>
auto reduce(Func f,Container &container)
-> decltype(Container::value_type())
{
typedef typename Container::value_type ReturnType;
ReturnType result = ReturnType();
if(container.begin() != container.end())
{
typename Container::const_iterator it;
it = container.begin();
for(result = *(it++);it!=container.end();++it)
{
result = f(result,*it);
}
}
return result;
}
template<typename Func, typename Container>
auto map(Func func, Container& container)
->std::list<decltype(func(Container::value_type))>
{
typedef std::list<decltype(func(Container::value_type()))> ReturnType;
ReturnType result = ReturnType();
for (typename Container::value_type value : container)
{
result.push_back(func(value));
}
return result;
}
template<typename Func, typename Container>
auto filter(Func func, Container& container)
->std::list<decltype(Container::value_type())>
{
typedef std::list<decltype(Container::value_type())> ReturnType;
ReturnType result = ReturnType();
for (typename Container::value_type value : container)
{
if(func(value))
{
result.push_back(value);
}
}
return result;
}