add switch case as string key

This commit is contained in:
chatlanin
2022-11-07 13:01:31 +03:00
parent 9f47c86bc2
commit 7c79befcb2
4 changed files with 68 additions and 2 deletions

View File

@@ -68,4 +68,14 @@ namespace hack::utils
{
inline static T id = value;
};
// this function can will use
// as switch wiht string
// switch(case_int("key"))
// case case_int("test"): hack::log()("wow!");
// case case_int("no_test"): hack::log()("wow!");
inline constexpr std::uint32_t case_int(const char* str, std::uint32_t hash = 2166136261UL)
{
return *str ? case_int(str + 1, (hash ^ *str) * 16777619ULL) : hash;
}
}