DUNE PDELab (git)

hash.hh File Reference

Support for calculating hash values of objects. More...

#include <functional>
#include <dune/common/typetraits.hh>

Go to the source code of this file.

Classes

struct  Dune::hash< T >
 Functor for hashing objects of type T. More...
 

Namespaces

namespace  Dune
 Dune namespace.
 

Macros

#define DUNE_DEFINE_HASH(template_args, type)
 Defines the required struct specialization to make type hashable via Dune::hash. More...
 
#define DUNE_HASH_TEMPLATE_ARGS(...)
 Wrapper macro for the template arguments in DUNE_DEFINE_HASH. More...
 
#define DUNE_HASH_TYPE(...)
 Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH. More...
 

Functions

template<typename T >
void Dune::hash_combine (std::size_t &seed, const T &arg)
 Calculates the hash value of arg and combines it in-place with seed. More...
 
template<typename It >
std::size_t Dune::hash_range (It first, It last)
 Hashes all elements in the range [first,last) and returns the combined hash. More...
 
template<typename It >
void Dune::hash_range (std::size_t &seed, It first, It last)
 Hashes all elements in the range [first,last) and combines the hashes in-place with seed. More...
 

Detailed Description

Support for calculating hash values of objects.

This file provides the functor Dune::hash to calculate hash values and some infrastructure to simplify extending Dune::hash for user-defined types, independent of the actual underlying implementation.

Macro Definition Documentation

◆ DUNE_DEFINE_HASH

#define DUNE_DEFINE_HASH (   template_args,
  type 
)

Defines the required struct specialization to make type hashable via Dune::hash.

In order to calculate the hash, operator() of the generated specialization will return the result of an unqualified call to the global function hash_value(const type&). As the call is not qualified, the function will be found using argument-dependent lookup, allowing implementors to conveniently place it inside the class body.

Consider the following type:

namespace ns {
template<typename A, int i>
class Foo
{
...
};
}

In order to add support for Dune::hash, you need to extend the definition like this:

namespace ns {
template<typename A, int i>
class Foo
{
...
// The keyword "friend" turns this into a global function that is a friend of Foo.
inline friend std::size_t hash_value(const Foo& arg)
{
return ...;
}
};
}
// Define hash struct specialization
#define DUNE_DEFINE_HASH(template_args, type)
Defines the required struct specialization to make type hashable via Dune::hash.
Definition: hash.hh:100
#define DUNE_HASH_TYPE(...)
Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.
Definition: hash.hh:117
#define DUNE_HASH_TEMPLATE_ARGS(...)
Wrapper macro for the template arguments in DUNE_DEFINE_HASH.
Definition: hash.hh:109
Warning
As the specialization has to be placed in the original namespace of the hash struct (e.g. std), this macro must be called from the global namespace!
Parameters
template_argsThe template arguments required by the hash struct specialization, wrapped in a call to DUNE_HASH_TEMPLATE_ARGS. If this is a complete specialization, call DUNE_HASH_TEMPLATE_ARGS without arguments.
typeThe exact type of the specialization, wrapped in a call to DUNE_HASH_TYPE.

◆ DUNE_HASH_TEMPLATE_ARGS

#define DUNE_HASH_TEMPLATE_ARGS (   ...)

Wrapper macro for the template arguments in DUNE_DEFINE_HASH.

This macro should always be used as a wrapper for the template arguments when calling DUNE_DEFINE_HASH. It works around some preprocessor limitations when the template arguments contain commas or the list is completely empty.

◆ DUNE_HASH_TYPE

#define DUNE_HASH_TYPE (   ...)

Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.

This macro should always be used as a wrapper for the type of the specialization when calling DUNE_DEFINE_HASH. It works around some preprocessor limitations when the type contains commas.

Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)