unordered_map heterogeneous access
This commit is contained in:
@@ -20,9 +20,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
||||
|
||||
// https://www.cppstories.com/2021/heterogeneous-access-cpp20/
|
||||
struct string_hash
|
||||
{
|
||||
using is_transparent = void;
|
||||
[[nodiscard]] size_t operator()(const char * txt) const
|
||||
{
|
||||
return std::hash<std::string_view>{}(txt);
|
||||
}
|
||||
[[nodiscard]] size_t operator()(std::string_view txt) const
|
||||
{
|
||||
return std::hash<std::string_view>{}(txt);
|
||||
}
|
||||
[[nodiscard]] size_t operator()(const std::string & txt) const
|
||||
{
|
||||
return std::hash<std::string>{}(txt);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user