Namespaces
Variants
Views
Actions

std::hash <std::variant>

From cppreference.com
< cpp‎ | utility‎ | variant
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)

(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
 
Defined in header <variant>
template <class... Types>
struct hash<std::variant<Types...>>;
(since C++17)

The template specialization of std::hash for the std::variant template allows users to obtain hashes of variant objects.

The specialization std::hash<std::variant<Types...>> is enabled (see std::hash) if every specialization in std::hash<std::remove_const_t<Types>>... is enabled, and is disabled otherwise.

The member functions of this specialization are not guaranteed to be noexcept.

Contents

[edit] Template parameters

Types - the types of the alternatives supported by the variant object

[edit] Notes

Unlike std::hash<std::optional>, hash of a variant does not typically equal the hash of the contained value; this makes it possible to distinguish std::variant<int, int> holding the same value as different alternatives.

[edit] Example

[edit] See also

(C++11)
hash function object
(class template) [edit]