Skip to main content
Captain Obvlious's user avatar
Captain Obvlious's user avatar
Captain Obvlious's user avatar
Captain Obvlious
  • Member for 5 years, 1 month
  • Last seen more than a week ago

About

.

////////////////////////// // strings as case labels // this does not handle hash collisions ////////////////////////// constexpr uint32_t djb2Hash( const char* str, int index = 0) { return !str[index] ? 0x1505 : (djb2Hash(str, index + 1) * 0x21) ^ str[index]; } // Create a literal type for short-hand case strings constexpr unsigned int operator"" _C( const char str[], size_t size) { return djb2Hash(str); } void Bloblawblah(const std::string& cond) { switch(djb2Hash(cond.c_str())) { case "Hello"_C: std::cout << "Goodbye"; break; case "World"_C: std::cout << "Planet"; break; default: std::cout << "BOGUS!"; } std::cout << std::endl; } 

Badges

This user doesn’t have any gold badges yet.
1
silver badge
6
bronze badges
8
Score
1
Posts
33
Posts %
8
Score
1
Posts
33
Posts %
8
Score
1
Posts
33
Posts %
8
Score
1
Posts
33
Posts %
4
Score
1
Posts
33
Posts %
4
Score
1
Posts
33
Posts %