Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. using namespace std;
  4.  
  5. template< class Key > class HashFunction
  6. {
  7. public:
  8. HashFunction( const Key & k );
  9.  
  10. inline operator unsigned() const
  11. {
  12. return mHashCode;
  13. }
  14. size_t operator()(const Key &k) const;
  15.  
  16. private:
  17. unsigned mHashCode;
  18. };
  19.  
  20. template<> HashFunction< string >::HashFunction( const string & k )
  21. {
  22. mHashCode=std::hash<string>{}(k);
  23. }
  24.  
  25. template <> size_t HashFunction< string >::operator()(const string &k) const
  26. {
  27. return mHashCode;
  28. }
  29.  
  30. template< class Key, class Val, class Hash = HashFunction< Key > >
  31. class unordered_map_wrapper
  32. {
  33. public:
  34. unordered_map_wrapper();
  35. private:
  36. unordered_map<Key, Val, Hash> * mTable;
  37. };
  38.  
  39. template< class Key, class Val, class Hash >
  40. unordered_map_wrapper< Key, Val, Hash >::unordered_map_wrapper()
  41. {
  42. mTable=new unordered_map<Key, Val, Hash>(5);
  43. }
  44.  
  45. int main() {
  46. unordered_map_wrapper<string, unsigned> h;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement