Lambda expression as binary predicate for a map

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?
Last edited on
Lambda expression creates an instance of unspecified type.
map expects a type as template parameter.

You can do a workaround using temporary:
1
2
3
4
5
int main()
{
    auto orderDecs = [](const int& value1, const int& value2) ->bool {return(value1 > value2);}
    multimap <int, string, decltype(orderDecs) > PancakeEaters(orderDecs);
}

Relevant links:
http://stackoverflow.com/questions/5849059/lambda-expressions-as-class-template-parameters
http://stackoverflow.com/questions/16179528/c-template-non-type-argument-lambda-function
http://stackoverflow.com/questions/3810519/how-to-use-a-lambda-expression-as-a-template-parameter
Thanks for your help and also the links, guess I haven't been able to word my problem correctly when I was googling.
Topic archived. No new replies allowed.