std::multiset<Key,Compare,Allocator>::value_comp - cppreference.com

From cppreference.com

std::multiset::value_comparevalue_comp()const;Returns the function object that compares the values. It is the same as

key_comp

.

Return value

The value comparison function object.

Complexity

Constant.

Example

Run this code

#include<iostream>#include<set>#include<utility>// Example module 97 key compare functionstructModCmp{booloperator()(intlhs,intrhs)const{return(lhs%97)<(rhs%97);}};intmain(){std::multiset<int,ModCmp>cont{1,2,3,4,5};// Same behaviour as key_comp()autocomp_func=cont.value_comp();for(constintval{100};constintkey:cont){constboolbefore=comp_func(key,val);constboolafter=comp_func(val,key);std::cout<<"Key ("<<key<<") ";if(!before&&!after)std::cout<<"equivalent to key ("<<val<<")\n";elseif(before)std::cout<<"goes before key ("<<val<<")\n";elseif(after)std::cout<<"goes after key ("<<val<<")\n";elsestd::unreachable();}}Output:

Key (1) goes before key (100) Key (2) goes before key (100) Key (3) equivalent to key (100) Key (4) goes after key (100) Key (5) goes after key (100) See also

returns the function that compares keys
(public member function)

[edit]