Skip to content

Instantly share code, notes, and snippets.

@NewProggie
Created June 18, 2016 19:06
Show Gist options
  • Save NewProggie/5d06523f88a9d3cdf717e7769b142b4f to your computer and use it in GitHub Desktop.
Save NewProggie/5d06523f88a9d3cdf717e7769b142b4f to your computer and use it in GitHub Desktop.
#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