Skip to content

Instantly share code, notes, and snippets.

@elbeno
Last active August 29, 2015 14:21
Show Gist options
  • Save elbeno/001da6c83c8876e1a9b7 to your computer and use it in GitHub Desktop.
Save elbeno/001da6c83c8876e1a9b7 to your computer and use it in GitHub Desktop.
constexpr __FILE__ hashing
#include <iostream>
using namespace std;
constexpr unsigned long long fnv_hash64_r(unsigned long long result, const char* string)
{
return (*string == 0) ? result : fnv_hash64_r(1099511628211ULL * result ^ *string, string + 1);
}
constexpr unsigned long long fnv_hash64(const char* string)
{
return fnv_hash64_r(14695981039346656037ULL, string);
}
constexpr auto this_file = fnv_hash64(__FILE__);
int main(int argc, char** argv)
{
cout << hex << this_file << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment