userver
C++ Async Framework
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
Toggle main menu visibility
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
All results
cached_hash.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/cached_hash.hpp
4
/// @brief @copybrief utils::CachedHash
5
6
#
include
<
functional
>
7
#
include
<
type_traits
>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
utils
{
12
13
/// @ingroup userver_universal
14
///
15
/// @brief Holds the key and its hash for faster comparisons and hashing
16
template
<
class
Key>
17
struct
CachedHash final {
18
std::size_t hash;
19
Key key;
20
};
17
struct
CachedHash final {
…
};
21
22
/// @brief Compares utils::CachedHash by hash first and then by keys
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
}
24
constexpr
bool
operator
==(
const
CachedHash<T>& x,
const
CachedHash<T>& y) {
…
}
27
28
/// @brief Compares utils::CachedHash by hash first and then by keys
29
template
<
class
T>
30
constexpr
bool
operator
!=(
const
CachedHash<T>& x,
const
CachedHash<T>& y) {
31
return
!(x.key == y.key);
32
}
30
constexpr
bool
operator
!=(
const
CachedHash<T>& x,
const
CachedHash<T>& y) {
…
}
33
34
/// @brief Compares utils::CachedHash only by keys
35
template
<
class
Equal,
class
= std::enable_if_t<!std::is_final_v<Equal>>>
36
class
CachedHashKeyEqual
:
private
Equal {
37
public
:
38
explicit
constexpr
CachedHashKeyEqual(
const
Equal& eq) : Equal(eq) {}
39
40
template
<
class
T>
41
constexpr
bool
operator()(
const
CachedHash<T>& x,
const
CachedHash<T>& y)
const
{
42
return
Equal::operator()(x.key, y.key);
43
}
44
};
36
class
CachedHashKeyEqual
:
private
Equal {
…
};
45
46
template
<
class
Equal>
47
class
CachedHashKeyEqual
<Equal, std::false_type> {
48
public
:
49
explicit
constexpr
CachedHashKeyEqual(
const
Equal& eq) : equality_(eq) {}
50
51
template
<
class
T>
52
constexpr
bool
operator()(
const
CachedHash<T>& x,
const
CachedHash<T>& y)
const
{
53
return
equality_(x.key, y.key);
54
}
55
56
private
:
57
Equal equality_;
58
};
47
class
CachedHashKeyEqual
<Equal, std::false_type> {
…
};
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
};
65
struct
std::hash<USERVER_NAMESPACE::
utils
::CachedHash<T>> {
…
};
Docs version:
v1.0
,
v2.0
,
trunk/develop
userver
utils
cached_hash.hpp
Generated on Fri Apr 11 2025 14:25:51 for userver by
Doxygen
1.13.2