fork download
  1. #include <unordered_map>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. // this works: ----------------------------------------------------------------------
  7. auto hf = [](string const& key)->size_t { return key[0]; };
  8. unordered_map<string const, int, decltype(hf)> m (1, hf);
  9.  
  10. // this works too (1): --------------------------------------------------------------
  11. template<class HASHER>
  12. auto make_unordered_map1(size_t bucketCount, HASHER const & hf)
  13. -> unordered_map<string const, int, HASHER const &>
  14. {
  15. return unordered_map<string const, int, HASHER const &>(bucketCount, hf);
  16. }
  17. auto x1 = make_unordered_map1(1, [](string const& key)->size_t { return key[0]; });
  18.  
  19. // as does this(2): -----------------------------------------------------------------
  20. template<class HASHER>
  21. auto make_unordered_map2(size_t bucketCount, HASHER const & hf2)
  22. -> unordered_map<string const, int, decltype(hf2)>
  23. {
  24. return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
  25. }
  26. auto x2 = make_unordered_map2(1, [](string const& key)->size_t { return key[0]; });
  27.  
  28. // ----------------------------------------------------------------------------------
  29. int main()
  30. {
  31. return 0;
  32. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout

Standard output is empty