Guest User

Untitled

a guest
May 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <boost/utility/string_view.hpp>
  4. #include <boost/functional/hash.hpp>
  5.  
  6. using namespace std;
  7.  
  8. class Hasher {
  9.  public:
  10.   std::size_t operator()(boost::string_view str) const {
  11.     return boost::hash_range<const char*>(str.begin(), str.end());
  12.   }
  13. };
  14.  
  15. int main() {
  16.   std::unordered_map<boost::string_view, std::size_t, Hasher> m;
  17.  
  18.   m["abc"] = 123;
  19.   m["def"] = 456;
  20.  
  21.   for (auto& elem : m)
  22.     std::cout << elem.first << ":" << elem.second << std::endl;
  23.  
  24.   return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment