Created
June 18, 2016 19:06
-
-
Save NewProggie/5d06523f88a9d3cdf717e7769b142b4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <cstdint> | |
#include <iomanip> | |
#include <iostream> | |
#include <numeric> | |
#include <string> | |
#include <vector> | |
struct HashString { | |
void operator()(const std::string &s) { | |
hash = std::accumulate(s.begin(), s.end(), hash, hash_char); | |
} | |
uint32_t hash = 0; | |
}; | |
template <typename Cont> | |
uint32_t hash_all_strings(const Cont& v) { | |
const auto hasher = std::for_each(v.begin(), v.end(), HashString()); | |
return hasher.hash; | |
} | |
int main() { | |
std::vector<std::string> v{"one", "two", "three", "four", "five" }; | |
uint32_t hash = hash_all_strings(v); | |
std::cout << "Hash: " << hash << std::dec << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment