-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_hash.cpp
More file actions
17 lines (15 loc) · 760 Bytes
/
test_hash.cpp
File metadata and controls
17 lines (15 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
constexpr auto cexprHash(const char *str, std::size_t v = 0) noexcept -> std::size_t {
return (*str == 0) ? v : 31 * cexprHash(str + 1) + *str;
}
int main() {
constexpr auto files_hash = cexprHash("files");
std::cout << "Compile-time hash of 'files': " << files_hash << std::endl;
std::cout << "Runtime hash of 'files': " << cexprHash("files") << std::endl;
std::cout << "Runtime hash of 'name': " << cexprHash("name") << std::endl;
std::cout << "Runtime hash of 'version': " << cexprHash("version") << std::endl;
std::cout << "Runtime hash of 'category': " << cexprHash("category") << std::endl;
std::cout << "Runtime hash of 'repo': " << cexprHash("repo") << std::endl;
return 0;
}