dice-hash
Hash function for stl types and container
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
dice::hash::dice_hash_templates< Policy > Class Template Reference

Class which contains all dice_hash functions. More...

#include <DiceHash.hpp>

Static Public Member Functions

template<typename T >
static std::size_t dice_hash (T const &t) noexcept
 Base case for dice_hash.
 
template<typename T >
requires std::is_fundamental_v<std::decay_t<T>>
static std::size_t dice_hash (T const &fundamental) noexcept
 Implementation for fundamentals.
 
template<typename CharT >
static std::size_t dice_hash (std::basic_string< CharT > const &str) noexcept
 Implementation for string types.
 
template<typename CharT >
static std::size_t dice_hash (std::basic_string_view< CharT > const &sv) noexcept
 Implementation for string view.
 
template<typename T >
static std::size_t dice_hash (T *ptr) noexcept
 Implementation for raw pointers.
 
template<typename T >
static std::size_t dice_hash (std::unique_ptr< T > const &ptr) noexcept
 Implementation for unique pointers.
 
template<typename T >
static std::size_t dice_hash (std::shared_ptr< T > const &ptr) noexcept
 implementation for shared pointers.
 
template<typename T , std::size_t N>
static std::size_t dice_hash (std::array< T, N > const &arr) noexcept
 Implementation for std arrays.
 
template<typename T >
static std::size_t dice_hash (std::vector< T > const &vec) noexcept
 Implementation for vectors.
 
template<typename... TupleArgs>
static std::size_t dice_hash (std::tuple< TupleArgs... > const &tpl) noexcept
 Implementation for tuples.
 
template<typename T , typename V >
static std::size_t dice_hash (std::pair< T, V > const &p) noexcept
 Implementation for pairs.
 
static std::size_t dice_hash (std::monostate const &) noexcept
 Overload for std::monostate.
 
template<typename... VariantArgs>
static std::size_t dice_hash (std::variant< VariantArgs... > const &var) noexcept
 Implementation for variant.
 
template<typename T >
requires is_ordered_container_v<T>
static std::size_t dice_hash (T const &container) noexcept
 Implementation for ordered container.
 
template<typename T >
requires is_unordered_container_v<T>
static std::size_t dice_hash (T const &container) noexcept
 Implementation for unordered container.
 

Detailed Description

template<Policies::HashPolicy Policy>
class dice::hash::dice_hash_templates< Policy >

Class which contains all dice_hash functions.

Template Parameters
PolicyThe Policy the hash is based on.

Member Function Documentation

◆ dice_hash() [1/15]

template<Policies::HashPolicy Policy>
template<typename T , std::size_t N>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::array< T, N > const arr)
inlinestaticnoexcept

Implementation for std arrays.

It will use different implementations if the type is fundamental or not.

Template Parameters
TThe type of the values.
NThe number of values.
Parameters
arrThe array itself.
Returns
Hash value.

◆ dice_hash() [2/15]

template<Policies::HashPolicy Policy>
template<typename CharT >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::basic_string< CharT > const str)
inlinestaticnoexcept

Implementation for string types.

Template Parameters
CharTA char type. See the definition of std::string for more information.
Parameters
strThe string to hash.
Returns
Hash value.

◆ dice_hash() [3/15]

template<Policies::HashPolicy Policy>
template<typename CharT >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::basic_string_view< CharT > const sv)
inlinestaticnoexcept

Implementation for string view.

Template Parameters
CharTA char type. See the definition of std::string for more information.
Parameters
svThe string view to hash.
Returns
Hash value.

◆ dice_hash() [4/15]

template<Policies::HashPolicy Policy>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::monostate const )
inlinestaticnoexcept

Overload for std::monostate.

It is needed so its usage in std::variant is possible. Will simply return the seed.

Returns
The seed of the hash function.

◆ dice_hash() [5/15]

template<Policies::HashPolicy Policy>
template<typename T , typename V >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::pair< T, V > const p)
inlinestaticnoexcept

Implementation for pairs.

Will hash the entries and then combine them.

Template Parameters
TType of the first value.
VType of the second value.
Parameters
pThe pair itself.
Returns
Hash value.

◆ dice_hash() [6/15]

template<Policies::HashPolicy Policy>
template<typename T >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::shared_ptr< T > const ptr)
inlinestaticnoexcept

implementation for shared pointers.

CAUTION: hashes the POINTER, not the OBJECT POINTED TO!

Template Parameters
TA shared pointer type.
Parameters
ptrThe pointer to hash.
Returns
Hash value.

◆ dice_hash() [7/15]

template<Policies::HashPolicy Policy>
template<typename... TupleArgs>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::tuple< TupleArgs... > const tpl)
inlinestaticnoexcept

Implementation for tuples.

Will hash every entry and then combine the hashes.

Template Parameters
TupleArgsThe types of the tuple values.
Parameters
tplThe tuple itself.
Returns
Hash value.

◆ dice_hash() [8/15]

template<Policies::HashPolicy Policy>
template<typename T >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::unique_ptr< T > const ptr)
inlinestaticnoexcept

Implementation for unique pointers.

CAUTION: hashes the POINTER, not the OBJECT POINTED TO!

Template Parameters
TA unique pointer type.
Parameters
ptrThe pointer to hash.
Returns
Hash value.

◆ dice_hash() [9/15]

template<Policies::HashPolicy Policy>
template<typename... VariantArgs>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::variant< VariantArgs... > const var)
inlinestaticnoexcept

Implementation for variant.

Will hash the value which was set. The hash of a variant of a type is equal to the hash of the type. For example: a variant of int of 42 is equal to the hash of the int of 42. If the variant is valueless_by_exception, the seed will be returned.

Template Parameters
VariantArgsTypes of the possible values.
Parameters
varThe variant itself.
Returns
Hash value.

◆ dice_hash() [10/15]

template<Policies::HashPolicy Policy>
template<typename T >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( std::vector< T > const vec)
inlinestaticnoexcept

Implementation for vectors.

It will use different implementations for fundamental and non-fundamental types.

Template Parameters
TThe type of the values.
Parameters
vecThe vector itself.
Returns
Hash value.

◆ dice_hash() [11/15]

template<Policies::HashPolicy Policy>
template<typename T >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( T ptr)
inlinestaticnoexcept

Implementation for raw pointers.

CAUTION: hashes the POINTER, not the OBJECT POINTED TO!

Template Parameters
TA pointer type.
Parameters
ptrThe pointer to hash.
Returns
Hash value.

◆ dice_hash() [12/15]

template<Policies::HashPolicy Policy>
template<typename T >
requires is_ordered_container_v<T>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( T const container)
inlinestaticnoexcept

Implementation for ordered container.

It uses a custom type trait to check if the type is in fact an ordered container. CAUTION: If you want to add another type to the trait, you might need to do it before this is included!

Template Parameters
TThe container type.
Parameters
containerThe container itself.
Returns
Hash value.

◆ dice_hash() [13/15]

template<Policies::HashPolicy Policy>
template<typename T >
requires is_unordered_container_v<T>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( T const container)
inlinestaticnoexcept

Implementation for unordered container.

It uses a custom type trait to check if the type is in fact an unordered container. CAUTION: If you want to add another type to the trait, you might need to do it before this is included!

Template Parameters
TThe container type.
Parameters
containerThe container itself.
Returns
Hash value.

◆ dice_hash() [14/15]

template<Policies::HashPolicy Policy>
template<typename T >
requires std::is_fundamental_v<std::decay_t<T>>
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( T const fundamental)
inlinestaticnoexcept

Implementation for fundamentals.

Template Parameters
TFundamental type.
Parameters
fundamentalValue to hash.
Returns
Hash value.

◆ dice_hash() [15/15]

template<Policies::HashPolicy Policy>
template<typename T >
static std::size_t dice::hash::dice_hash_templates< Policy >::dice_hash ( T const t)
inlinestaticnoexcept

Base case for dice_hash.

This case is only chosen if no other match is found in this struct. Than it tries to find a specialization of dice::hash::dice_hash_overload and if none is found, this function will not compile.

Template Parameters
TThe type to hash.
Returns
Hash value.

The documentation for this class was generated from the following file: