Guest User

Untitled

a guest
May 29th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 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.   void check() const
  14.   {
  15.     m["abc"] = 123;
  16.     m["def"] = 456;
  17.     for (auto& elem : m)
  18.       std::cout << elem.first << ":" << elem.second << std::endl;
  19.   }
  20.  private:
  21.   std::unordered_map<boost::string_view, std::size_t, Hasher> m;
  22.  
  23. };
  24.  
  25. int main() {
  26.   Hasher p;
  27.   p.check();
  28.   return 0;
  29. }
Add Comment
Please, Sign In to add comment