opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
transparent_string_hasher.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstddef>
7#include <string_view>
8
9namespace osc
10{
11 // a `std::hash`-like object that can transparently hash any object that is
12 // string-like (i.e. implicitly converts into a `std::string_view`)
14
15 using is_transparent = void; // C++20, `std::unordered_map` uses this
16
17 size_t operator()(std::string_view string_view) const noexcept
18 {
19 // if something implicitly converts into a `std::string_view` then it's
20 // eligible for transparent hashing
21 return std::hash<std::string_view>{}(string_view);
22 }
23
25 {
26 // special case: `SharedPreHashedString`s are pre-hashed
27 return std::hash<SharedPreHashedString>{}(shared_pre_hashed_string);
28 }
29
30 size_t operator()(const StringName& string_name) const noexcept
31 {
32 // special case: `StringName`s are pre-hashed
33 return std::hash<StringName>{}(string_name);
34 }
35 };
36}
Definition shared_pre_hashed_string.h:55
Definition string_name.h:14
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
Definition transparent_string_hasher.h:13
size_t operator()(const StringName &string_name) const noexcept
Definition transparent_string_hasher.h:30
size_t operator()(std::string_view string_view) const noexcept
Definition transparent_string_hasher.h:17
size_t operator()(const SharedPreHashedString &shared_pre_hashed_string) const noexcept
Definition transparent_string_hasher.h:24
void is_transparent
Definition transparent_string_hasher.h:15