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 doesn't
  11. template<class HASHER>
  12. auto make_unordered_map(size_t bucketCount, HASHER const & hf2)
  13. -> unordered_map<string const, int, decltype(hf2)>&&
  14. {
  15. return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
  16. }
  17. auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });
  18.  
  19. int main()
  20. {
  21. return 0;
  22. }
Success #stdin #stdout 0s 3024KB
stdin
Standard input is empty
stdout
Standard output is empty