std::multiset<Key,Compare,Allocator>:: value_comp
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::multiset
| Member functions | |||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||
|
value_compare value_comp
(
)
const
;
|
(自 C++26 起为 constexpr) | |
返回用于比较值的函数对象。这与 key_comp() 相同。
目录 |
返回值
值比较函数对象。
复杂度
常量。
示例
运行此代码
#include <iostream> #include <set> #include <utility> // 示例模块97键比较函数 struct ModCmp { bool operator()(int lhs, int rhs) const { return (lhs % 97) < (rhs % 97); } }; int main() { std::multiset<int, ModCmp> cont{1, 2, 3, 4, 5}; // 与 key_comp() 行为相同 auto comp_func = cont.value_comp(); for (const int val{100}; const int key : cont) { const bool before = comp_func(key, val); const bool after = comp_func(val, key); std::cout << "键 (" << key << ") "; if (!before && !after) std::cout << "等价于键 (" << val << ")\n"; else if (before) std::cout << "位于键 (" << val << ") 之前\n"; else if (after) std::cout << "位于键 (" << val << ") 之后\n"; else std::unreachable(); } }
输出:
键 (1) 位于键 (100) 之前 键 (2) 位于键 (100) 之前 键 (3) 等价于键 (100) 键 (4) 位于键 (100) 之后 键 (5) 位于键 (100) 之后
参见
|
返回用于比较键的函数
(公开成员函数) |