- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ 地图库 - key_comp() 函数
描述
C++ 函数std::map::key_comp()返回一个比较键的函数对象,它是此容器的构造函数参数comp的副本。
宣言
以下是 std::map::key_comp() 函数形式 std::map 标头的声明。
C++98
key_compare key_comp() const;
参数
没有任何
返回值
返回一个键比较函数对象。
例外情况
该成员函数不会抛出异常。
时间复杂度
常数即 O(1)
例子
以下示例显示了 std::map::key_comp() 函数的用法。
#include <iostream>
#include <map>
using namespace std;
int main(void) {
/* Initializer_list constructor */
map<char, int> m = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5},
};
auto comp = m.key_comp();
char last = m.rbegin()->first;
auto it = m.begin();
cout << "Map contains following elements" << endl;
do
cout << it->first << " = " << it->second << endl;
while (comp((*it++).first, last));
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Map contains following elements a = 1 b = 2 c = 3 d = 4 e = 5
地图.htm