xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::tools::Hash Class Reference

A hash object with extended functionality. More...

#include <xentara/utils/tools/Hash.hpp>

Public Types

using is_transparent = std::true_type
 Tells std::unordered_map and std::unordered_set that this is a transparent hash.
 

Public Member Functions

template<StdHashable Type>
constexpr auto operator() (const Type &value) const noexcept(detail::kIsNoexceptHashable< Type >) -> std::size_t
 Hashes an object that can be hashed using std::hash.
 
template<typename Char >
requires std::same_as<std::remove_cv_t<Char>, char> || std::same_as<std::remove_cv_t<Char>, wchar_t> || std::same_as<std::remove_cv_t<Char>, char8_t> || std::same_as<std::remove_cv_t<Char>, char16_t> || std::same_as<std::remove_cv_t<Char>, char32_t>
constexpr auto operator() (Char *string) const noexcept -> std::size_t
 Calculates a hash value for a null-terminated string.
 
template<typename First , typename Second >
constexpr auto operator() (const std::pair< First, Second > &value) const noexcept(detail::kIsNoexceptHashable< std::pair< First, Second > >) -> std::size_t
 Calculates a hash value for an std::pair.
 
template<typename... Types>
constexpr auto operator() (const std::tuple< Types... > &tuple) const noexcept(detail::kIsNoexceptHashable< std::tuple< Types... > >) -> std::size_t
 Calculates a hash value for an std::tuple.
 
template<typename First , typename Second , typename... More>
constexpr auto operator() (const First &first, const Second &second, const More &... more) const noexcept(detail::kIsNoexceptHashable< std::tuple< First, Second, More... > >) -> std::size_t
 Combines the hash values of two or more objects.
 

Detailed Description

A hash object with extended functionality.

This has object differs in a number of ways from std::hash:

  1. This object is transparent, meaning that the object itself is not a template. This allows heterogeneous lookup in C++20, where the key used to look up the value does not have to be the same type as the key. You can, for example, look up an entry in a hash table that uses std::string as a key using an std::string_view.
  2. This object hashes char *, const char *, wchar_t *, const wchar_t *, char8_t *, const char8_t *, char16_t *, const char16_t *, char32_t *, and const char32_t * as their std::basic_string_view equivalents
  3. This class can hash std::pair and std::tuple, if all the members can be hashed
  4. This class has amulti-parameter operator()() that takes multiple values and combines their hash values

Member Typedef Documentation

◆ is_transparent

Member Function Documentation

◆ operator()() [1/5]

template<typename Char >
requires std::same_as<std::remove_cv_t<Char>, char> || std::same_as<std::remove_cv_t<Char>, wchar_t> || std::same_as<std::remove_cv_t<Char>, char8_t> || std::same_as<std::remove_cv_t<Char>, char16_t> || std::same_as<std::remove_cv_t<Char>, char32_t>
constexpr auto xentara::utils::tools::Hash::operator() ( Char *  string) const -> std::size_t
constexprnoexcept

Calculates a hash value for a null-terminated string.

Parameters
stringThe string. The string can be a null string, which will be hashed the same way as an empty string.

◆ operator()() [2/5]

template<typename First , typename Second , typename... More>
constexpr auto xentara::utils::tools::Hash::operator() ( const First &  first,
const Second &  second,
const More &...  more 
) const -> std::size_t
constexprnoexcept

Combines the hash values of two or more objects.

◆ operator()() [3/5]

template<typename First , typename Second >
constexpr auto xentara::utils::tools::Hash::operator() ( const std::pair< First, Second > &  value) const -> std::size_t
constexprnoexcept

Calculates a hash value for an std::pair.

◆ operator()() [4/5]

template<typename... Types>
constexpr auto xentara::utils::tools::Hash::operator() ( const std::tuple< Types... > &  tuple) const -> std::size_t
constexprnoexcept

Calculates a hash value for an std::tuple.

◆ operator()() [5/5]

template<StdHashable Type>
constexpr auto xentara::utils::tools::Hash::operator() ( const Type &  value) const -> std::size_t
constexprnoexcept

Hashes an object that can be hashed using std::hash.