根据业务需求,在编码过程中,经常会遇到switch case表达式是字符串的场景,现支持如下。
【1】实现文件
支持实现的文件
1 #pragma once
2
3 #include <cstddef>
4 #include <cstdint>
5 #include <type_traits>
6
7 namespace prefab
8 {
9 template<typename T>
10 struct fnv1a_constant;
11
12 template<>
13 struct fnv1a_constant<std::uint32_t>
14 {
15 static constexpr std::uint32_t prime = 16777619;
16 static constexpr std::uint32_t offset = 2166136261;
17 };
18
19 template<>
20 struct fnv1a_constant<std::uint64_t>
21 {
22 static constexpr std::uint64_t prime = 1099511628211ull;
23 static constexpr std::uint64_t offset = 14695981039346656037ull;
24 };
25
26 template<typename T, typename TChar>
27 inline constexpr T fnv1a_hash(const TChar* const str, const T result = fnv1a_constant<T>::offset)
28 {
29 return (str[0] == '