This comparison object is set on object construction, and may either be a pointer to a function or an object of a class with a function call operator. In both cases it takes two arguments of the same type as the container elements, and returns true if the first argument is considered to go before the second in the strict weak ordering the object defines, and false otherwise.
In multiset containers, the element values are the keys themselves, therefore key_comp and its sibling member function value_comp both return the same.
Parameters
noneReturn value
The comparison object.multiset::key_compare is a member type defined to Compare, which is the second template parameter in the multiset class template.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Output:
mymultiset contains: 0 1 2 3 4 5 |
Complexity
Constant.See also
| multiset::value_comp | Return comparison object (public member function) |
| multiset::find | Get iterator to element (public member function) |
| multiset::count | Count elements with a specific key (public member function) |
| multiset::lower_bound | Return iterator to lower bound (public member function) |
| multiset::upper_bound | Return iterator to upper bound (public member function) |
