key_comp函数
语法:key_comp
1 |
key_compare key_comp() const; |
key_comp()返回一个用于元素间值比较的函数
源代码
1 2 3 4 |
/// Returns the comparison object with which the %set was constructed. key_compare key_comp() const { return _M_t.key_comp(); } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <set> using namespace std; int main() { set<int> s1; s1.insert(10); s1.insert(12); s1.insert(13); s1.insert(9); cout<<s1.key_comp()(1,2)<<endl;; } |
测试结果:
1 |
1 |
注:key_comp函数返回比较器,s1集合默认比较器是less,所以(1,2)会输出1(true).