Skip to content

Commit

Permalink
Merge pull request CleverRaven#33168 from jbytheway/clang_tidy_cert_d…
Browse files Browse the repository at this point in the history
…cl59_cpp

clang-tidy cert-dcl59-cpp
  • Loading branch information
ZhilkinSerg authored Aug 12, 2019
2 parents 38912d4 + aeb643f commit b28c17f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ readability-*,\
-bugprone-undefined-memory-manipulation,\
-bugprone-unused-return-value,\
-bugprone-use-after-move,\
-cert-dcl59-cpp,\
-cert-env33-c,\
-cert-err34-c,\
-cert-flp30-c,\
Expand Down
16 changes: 9 additions & 7 deletions src/tuple_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// so that it is picked up by argument-dependent name lookup (ADL).
namespace cata
{
namespace
{

// Code from boost
// Reciprocal of the golden ratio helps spread entropy
Expand All @@ -23,29 +21,33 @@ inline void hash_combine( std::size_t &seed, const T &v )
seed ^= std::hash<T>()( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
}

namespace tuple_hash_detail
{

// Recursive template code derived from Matthieu M.
template < class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1 >
struct HashValueImpl
struct Impl
{
static void apply( size_t &seed, const Tuple &tuple ) {
HashValueImpl < Tuple, Index - 1 >::apply( seed, tuple );
Impl < Tuple, Index - 1 >::apply( seed, tuple );
hash_combine( seed, std::get<Index>( tuple ) );
}
};

template <class Tuple>
struct HashValueImpl<Tuple, 0> {
struct Impl<Tuple, 0> {
static void apply( size_t &seed, const Tuple &tuple ) {
hash_combine( seed, std::get<0>( tuple ) );
}
};
} // namespace

} // namespace tuple_hash_detail

struct tuple_hash {
template <typename ... TT>
std::size_t operator()( const std::tuple<TT...> &tt ) const {
size_t seed = 0;
HashValueImpl<std::tuple<TT...> >::apply( seed, tt );
tuple_hash_detail::Impl<std::tuple<TT...> >::apply( seed, tt );
return seed;
}

Expand Down

0 comments on commit b28c17f

Please sign in to comment.