目录

hash_function

描述 (Description)

它返回unordered_set容器使用的哈希函数对象。

声明 (Declaration)

以下是std :: unordered_set :: hash_function的声明。

C++11

hasher hash_function() const;

参数 (Parameters)

没有

返回值

它返回哈希函数。

异常 (Exceptions)

如果任何元素比较对象抛出异常,则抛出异常。

请注意,无效参数会导致未定义的行为。

时间复杂

恒定时间。

例子 (Example)

以下示例显示了std :: unordered_set :: hash_function的用法。

#include <iostream>
#include <string>
#include <unordered_set>
typedef std::unordered_set<std::string> stringset;
int main () {
   stringset myset;
   stringset::hasher fn = myset.hash_function();
   std::cout << "that contains: " << fn ("that") << std::endl;
   std::cout << "than contains: " << fn ("than") << std::endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

that: 15843861542616104093
than: 18313131606624605886
↑回到顶部↑
WIKI教程 @2018