Skip to content

Latest commit

 

History

History
68 lines (55 loc) · 2.37 KB

hash-class.md

File metadata and controls

68 lines (55 loc) · 2.37 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
hash Class | Microsoft Docs
11/04/2016
cpp-standard-libraries
article
functional/std::hash
bitset/std::hash
memory/std::hash
string/std::hash
system_error/std::hash
thread/std::hash
typeindex/std::hash
vector/std::hash
XSTDDEF/std::hash
xstring/std::hash
C++
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
std::hash [C++]
e1b500c6-a5c8-4f6f-ad33-7ec52eb8e2e4
21
corob-msft
corob
ghogen

hash Class

Computes hash code for a value.

Syntax

template <class Ty>  
struct hash {  
    size_t operator()(Ty val) const; 
};  

Remarks

The function object defines a hash function, suitable for mapping values of type Ty to a distribution of index values. The member operator() returns a hash code for val, suitable for use with template classes unordered_map, unordered_multimap, unordered_set, and unordered_multiset. The standard library provides specializations for basic types: Ty may be any scalar type, including pointer types and enumeration types. In addition, there are specializations for the library types string, wstring, u16string, u32string, string_view, wstring_view, u16string_view, u32string_view, bitset, error_code, error_condition, optional, shared_ptr, thread, type_index, unique_ptr, variant, and vector<bool>.

Example

// std__functional__hash.cpp   
// compile with: /EHsc   
#include <functional>   
#include <iostream>   
#include <unordered_set>   
  
int main()   
    {   
    std::unordered_set<int, std::hash<int> > c0;   
    c0.insert(3);   
    std::cout << *c0.find(3) << std::endl;   
  
    return (0);   
    }  
  
3  

Requirements

Header: <functional>

Namespace: std

See Also

<unordered_map>
unordered_multimap Class
unordered_multiset Class
<unordered_set>