I want to pass a lambda function as an argument to a method. Example:
T reduce(const T initial, const std::function<T(T, T)> acc) {
T value = initial;
for (size_t i = 0; i < S; ++i) {
value = acc(value, this->values[i]);
}
return value;
}
...
int sum = this->reduce(42, [](int acc, int value) { return acc + value; });
If I try to compile this code for Arduino, I get an obvious error:
error: 'function' in namespace 'std' does not name a template type
How can I use a lambda function in Arduino?