21 #ifndef __EDELIB_FUNCTIONAL_H__
22 #define __EDELIB_FUNCTIONAL_H__
37 template <
typename T,
typename F>
38 unsigned int filter(
const F& func,
const T& container, T& ret) {
39 typename T::const_iterator it = container.begin();
40 typename T::const_iterator ite = container.end();
42 for(; it != ite; ++it) {
54 template <
typename T,
typename F>
55 void map(F& func,
const T& container, T& ret) {
56 typename T::const_iterator it = container.begin();
57 typename T::const_iterator ite = container.end();
59 for(; it != ite; ++it)
60 ret.push_back(func(*it));
78 template <
typename T,
typename R,
typename F>
79 void reduce(F& func,
const T& container, R& ret) {
80 unsigned int sz = container.size();
84 ret = *container.begin();
86 typename T::const_iterator it = container.begin();
87 typename T::const_iterator it2 = it;
89 typename T::const_iterator ite = container.end();
91 ret = func(*it, *it2);
92 for(++it2; it2 != ite; ++it2)
93 ret = func(*it2, ret);
101 template <
typename T,
typename F>
103 typename T::const_iterator it = container.begin();
104 typename T::const_iterator ite = container.end();
106 for(; it != ite; ++it)
115 template <
typename T,
typename F>
116 void for_each(
const F& func,
const T& container,
void* p) {
117 typename T::const_iterator it = container.begin();
118 typename T::const_iterator ite = container.end();
120 for(; it != ite; ++it)
void reduce(F &func, const T &container, R &ret)
Definition: Functional.h:79
void for_each(const F &func, const T &container)
Definition: Functional.h:102
unsigned int filter(const F &func, const T &container, T &ret)
Definition: Functional.h:38
void map(F &func, const T &container, T &ret)
Definition: Functional.h:55