Code:
#include <iostream>
template <class FunctorType>
void caller(const FunctorType& func) {
func();
}
int main() {
double data[5] = {5., 0., 0., 0., 0.};
auto peek_data = [data]() { std::cout << data[0] << std::endl; };
auto change_data = [data]() mutable { data[0] = 4.2; };
caller(peek_data); // This works
caller(change_data); // This doesn't
return 0;
}
If I compile this with clang++ -std=c++11 mutable_lambda.cpp, I got
error: no matching function for call to object of type 'const (lambda at mutable_lambda.cpp:8:22)'.
Question: Why passing the second lambda expression with mutable copy capture failed to compile? Thanks in advance!