Firstly, sorry if it is not proper forum, but I feel like it is still a beginner thing, if it is not, then I apologize.
Recently I've learned about how lambda expression works, and decided to reprogram one of my previous exercises using a lambda as a binary predicate for key sorting in a multimap. Basically I use it to sort how many pancakes some people ate, while still keeping their number(or name). Without lambda the code looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
template <typename T>
struct OrderDescending
{
bool operator()(const T& value1, const T& value2) const
{
return (value1 > value2);
}
};
int main(){
//some other stuff...
multimap <int, string, OrderDescending<int>> PancakeEaters;
}
|
That implementation works perfectly fine. Now, I try to do it with a lambda:
1 2 3 4 5
|
int main(){
multimap <int, string,
[](const int& value1, const int& value2) ->bool {return(value1 > value2);} >
PancakeEaters;
}
|
Now it doesn't work, and it shows me error at the square brackets: "Error, expected a type spefifier".
Is it my fault, did I type incorrect syntax, or maybe you cannot use lambda as a multimap predicate?