Euphoria
Classes | Macros
Hash-util

Helper macros for specializing the std::hash. More...

Classes

struct  eu::core::HashCombiner
 A utility for combining hash values of multiple objects into a single hash value. More...
 

Macros

#define HASH_DEF_BEGIN(TYPE)
 Begins the definition of a specialization of std::hash for the given TYPE.
 
#define HASH_DEF(NAME)   .combine(x.NAME)
 Adds the hash of a member variable to the hash combination.
 
#define HASH_DEF_END()
 Ends the definition of the std::hash specialization.
 

Detailed Description

Helper macros for specializing the std::hash.

This group provides a util HashCombiner to simplify the creation of hash functions for user-defined types (using std::hash) and macros for specialization of std::hash for custom types.

Example usage:

HASH_DEF(member1)
HASH_DEF(member2)
#define HASH_DEF(NAME)
Adds the hash of a member variable to the hash combination.
Definition hash.h:70
#define HASH_DEF_BEGIN(TYPE)
Begins the definition of a specialization of std::hash for the given TYPE.
Definition hash.h:51
#define HASH_DEF_END()
Ends the definition of the std::hash specialization.
Definition hash.h:79

Macro Definition Documentation

◆ HASH_DEF

#define HASH_DEF (   NAME)    .combine(x.NAME)

#include <libs/core/src/eu/core/hash.h>

Adds the hash of a member variable to the hash combination.

\hideinlinesource

This macro should be used within a HASH_DEF_BEGIN and HASH_DEF_END block to combine the hash of a specific member variable of the type.

Parameters
NAMEThe name of the member variable to include in the hash.

Definition at line 70 of file hash.h.

◆ HASH_DEF_BEGIN

#define HASH_DEF_BEGIN (   TYPE)

#include <libs/core/src/eu/core/hash.h>

Value:
template<> \
struct std::hash<TYPE> \
{ \
std::size_t operator()(const TYPE& x) const \
{ \
{ \
}
A utility for combining hash values of multiple objects into a single hash value.
Definition hash.h:26

Begins the definition of a specialization of std::hash for the given TYPE.

Should be closed by the HASH_DEF_END macro

Parameters
TYPEThe user-defined type for which the hash specialization is being created. \hideinlinesource

Definition at line 51 of file hash.h.

◆ HASH_DEF_END

#define HASH_DEF_END ( )

#include <libs/core/src/eu/core/hash.h>

Value:
.result; \
} \
} \
;

Ends the definition of the std::hash specialization.

This macro should be used to close the hash function definition started with HASH_DEF_BEGIN. It returns the final combined hash value.

\hideinlinesource

Definition at line 79 of file hash.h.