userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
cached_hash.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <functional>
7
#include <type_traits>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
utils
{
12
16
template
<
class
Key>
17
struct
CachedHash
final {
18
std::size_t hash;
19
Key key;
20
};
21
23
template
<
class
T>
24
constexpr
bool
operator==(
const
CachedHash<T>
& x,
const
CachedHash<T>
& y) {
25
return
x.hash == y.hash && x.key == y.key;
26
}
27
29
template
<
class
Equal>
30
class
CachedHashKeyEqual {
31
public
:
32
constexpr
explicit
CachedHashKeyEqual(
const
Equal& eq)
33
: equality_(eq)
34
{}
35
36
template
<
class
T>
37
constexpr
bool
operator()(
const
CachedHash<T>
& x,
const
CachedHash<T>
& y)
const
{
38
return
equality_(x.key, y.key);
39
}
40
41
private
:
42
[[no_unique_address]] Equal equality_;
43
};
44
46
template
<
class
Equal>
47
requires
(!std::is_final_v<Equal>)
48
class
CachedHashKeyEqual<Equal> : private Equal {
49
public:
50
constexpr explicit CachedHashKeyEqual(const Equal& eq)
51
: Equal(eq)
52
{}
53
54
template
<
class
T>
55
constexpr
bool
operator()(
const
CachedHash<T>
& x,
const
CachedHash<T>
& y)
const
{
56
return
Equal::operator()(x.key, y.key);
57
}
58
};
59
60
}
// namespace utils
61
62
USERVER_NAMESPACE_END
63
64
template
<
class
T>
65
struct
std::hash<USERVER_NAMESPACE::
utils::CachedHash
<T>> {
66
constexpr
std::size_t operator()(
const
USERVER_NAMESPACE::utils::CachedHash<T>& value)
const
noexcept
{
67
return
value.hash;
68
}
69
};
userver
utils
cached_hash.hpp
Generated on
for userver by
Doxygen
1.17.0