hash.hh File Reference

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

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.


Defines

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

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.
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.
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.

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.


Define Documentation

#define DUNE_DEFINE_HASH ( template_args,
type   ) 

Defines the required struct specialization to make type hashable via `Dunehash`.

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 `Dunehash`, 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
 DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename A, int i),DUNE_HASH_TYPE(Foo<A,i>))
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_args The 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.
type The exact type of the specialization, wrapped in a call to DUNE_HASH_TYPE.
#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.

#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.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 25 Mar 2018 for dune-common by  doxygen 1.6.1