I'm trying to sort an array using a lambda to use another array in the comparison function. Inside a larger function, I have this code:
std::sort(arr.begin(), arr.end(),[] (int& a, int& b)
{
return (*i)[a] < (*i)[b];
});
I get the following errors in the containing function:
mcmc.cpp:139: error: expected primary-expression before ‘[’ token
mcmc.cpp:139: error: expected primary-expression before ‘]’ token
mcmc.cpp:139: error: expected primary-expression before ‘int’
mcmc.cpp:139: error: expected primary-expression before ‘int’
When compiling, I'm including the -std=c++0x option as well.
I'm confused about what's going on. For some reason, it doesn't seem to recognize my syntax as valid. I did a yum update just in case, but it still seems as if it just doesn't recognize the use of lambdas.