add o3tl version of hash_combine to not depend on boost for this

Change-Id: I081f8d116ef811baa8aa5de35a6cb51fa4de7d56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114983
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2021-05-11 12:23:48 +02:00
committed by Tomaž Vajngerl
parent 57ed14b5c5
commit e6c0c282be
2 changed files with 32 additions and 3 deletions
+29
View File
@@ -0,0 +1,29 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
namespace o3tl
{
template <typename T, typename N, std::enable_if_t<(sizeof(N) == 4), bool> = false>
inline void hash_combine(N& nSeed, T const& nValue)
{
static_assert(sizeof(nSeed) == 4);
nSeed ^= std::hash<T>{}(nValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 2);
}
template <typename T, typename N, std::enable_if_t<(sizeof(N) == 8), bool> = false>
inline void hash_combine(N& nSeed, T const& nValue)
{
static_assert(sizeof(nSeed) == 8);
nSeed ^= std::hash<T>{}(nValue) + 0x9E3779B97F4A7C15llu + (nSeed << 12) + (nSeed >> 4);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+3 -3
View File
@@ -15,7 +15,7 @@
#include <o3tl/lru_map.hxx>
#include <boost/functional/hash.hpp>
#include <o3tl/hash_combine.hxx>
using namespace ::o3tl;
@@ -202,8 +202,8 @@ struct TestClassKeyHashFunction
std::size_t operator()(TestClassKey const& aKey) const
{
std::size_t seed = 0;
boost::hash_combine(seed, aKey.mA);
boost::hash_combine(seed, aKey.mB);
o3tl::hash_combine(seed, aKey.mA);
o3tl::hash_combine(seed, aKey.mB);
return seed;
}
};