Thomas - 1 year ago 99

C++ Question

`function<bool(const pair<int, int>&, const pair<int, int>&)> cmp = [](const pair<int, int> & left, const pair<int, int> & right){if(left > right) return true;};`

//multiset<pair<int, int>, function<bool(const pair<int, int>&, const pair<int, int>&)> mt(cmp);

multiset<pair<int, int>, decltype(cmp)> mt1(cmp);

cout<<typeid(decltype(cmp)).name()<<endl<<typeid(cmp).name()<<endl;

the comment code(

`mt`

`mt1`

I tried to

`cout`

Besides, I also tried like this:

`multiset<pair<int, int>, const function<bool(const pair<int, int>&, const pair<int, int>&) &> mt(cmp);`

or

`multiset<pair<int, int>, function<bool(const pair<int, int>&, const pair<int, int>&) &> mt(cmp);`

All of them don't work.

So what is the type of the second argument exactly? If I don't use

`decltype`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Look carefully at your code, you lost a `>`

.

```
multiset<pair<int, int>, function<bool(const pair<int, int>&, const pair<int, int>&)>> mt(cmp);
// ~
```

Using `decltype`

should be a good idea.

BTW: You should return something when `if`

returns `false`

in lambda. Or just `return left > right;`

.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**