Cachemere
Modular Caching Library for C++
transparent_eq.h
1 #ifndef CACHEMERE_TRANSPARENT_EQ_H
2 #define CACHEMERE_TRANSPARENT_EQ_H
3 
4 #include <absl/hash/hash.h>
5 
6 namespace cachemere::detail {
7 
8 template<typename Key> struct TransparentEq {
9  // Declare this type as transparent - this is needed for abseil maps to support heterogeneous lookup.
10  using is_transparent = void;
11 
12  bool operator()(const Key& a, const Key& b) const
13  {
14  return a == b;
15  }
16 
17  template<typename KeyView> bool operator()(const Key& a, const KeyView& b) const
18  {
19  // We only require operator==(const Key&) to be defined on the KeyView.
20  return b == a;
21  }
22 
23  template<typename KeyView> bool operator()(const KeyView& a, const Key& b) const
24  {
25  // We only require operator==(const Key&) to be defined on the KeyView.
26  return a == b;
27  }
28 };
29 
30 } // namespace cachemere::detail
31 
32 #endif // CACHEMERE_TRANSPARENT_EQ_H
cachemere::detail::TransparentEq
Definition: transparent_eq.h:8