BPHash
General object hashing library for C++
tuple.hpp
Go to the documentation of this file.
1 /*! \file
2  * \brief Hashing of std::tuple
3  */
4 
5 /* Copyright (c) 2016 Benjamin Pritchard <ben@bennyp.org>
6  * This file is part of the BPHash project, which is released
7  * under the BSD 3-clause license. See the LICENSE file for details
8  */
9 
10 #pragma once
11 
12 #include "bphash/Hasher.hpp"
13 #include <tuple>
14 
15 namespace bphash {
16 namespace detail {
17 
18 
19 template<size_t Idx, typename... Types>
20 typename std::enable_if<Idx == sizeof...(Types), void>::type
21 tuple_element_hasher(Hasher &, const std::tuple<Types...> &)
22 { }
23 
24 template<size_t Idx, typename... Types>
25 typename std::enable_if<Idx < sizeof...(Types), void>::type
26 tuple_element_hasher(Hasher & h, const std::tuple<Types...> & tup)
27 {
28  h(std::get<Idx>(tup));
29  tuple_element_hasher<Idx+1>(h, tup);
30 }
31 
32 
33 } // close namespace detail
34 
35 
36 
37 template<typename... Types>
38 typename std::enable_if<is_hashable<Types...>::value, void>::type
39 hash_object( const std::tuple<Types...> & tup, Hasher & h)
40 {
41  detail::tuple_element_hasher<0>(h, tup);
42 }
43 
44 
45 } // close namespace bphash
46 
Trait class that determines if a type is hashable or not.
Definition: Detector.hpp:25
std::enable_if< is_hashable< T >::value, void >::type hash_object(const std::array< T, N > &a, Hasher &h)
Hashing of std::array.
Definition: array.hpp:20
A class that hashes objects (header)
std::enable_if< Idx==sizeof...(Types), void >::type tuple_element_hasher(Hasher &, const std::tuple< Types... > &)
Definition: tuple.hpp:21
Class that is used to hash objects.
Definition: Hasher.hpp:78