#include <unordered_map>
#include <string>
using namespace std;
// this works: ----------------------------------------------------------------------
auto hf = [](string const& key)->size_t { return key[0]; };
unordered_map<string const, int, decltype(hf)> m (1, hf);
// this works too (1): --------------------------------------------------------------
template<class HASHER>
auto make_unordered_map1(size_t bucketCount, HASHER const & hf)
-> unordered_map<string const, int, HASHER const &>
{
return unordered_map<string const, int, HASHER const &>(bucketCount, hf);
}
auto x1 = make_unordered_map1(1, [](string const& key)->size_t { return key[0]; });
// as does this(2): -----------------------------------------------------------------
template<class HASHER>
auto make_unordered_map2(size_t bucketCount, HASHER const & hf2)
-> unordered_map<string const, int, decltype(hf2)>
{
return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
}
auto x2 = make_unordered_map2(1, [](string const& key)->size_t { return key[0]; });
// ----------------------------------------------------------------------------------
int main()
{
return 0;
}
I2luY2x1ZGUgPHVub3JkZXJlZF9tYXA+CiNpbmNsdWRlIDxzdHJpbmc+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIHRoaXMgd29ya3M6IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KYXV0byBoZiA9IFtdKHN0cmluZyBjb25zdCYga2V5KS0+c2l6ZV90IHsgcmV0dXJuIGtleVswXTsgfTsKdW5vcmRlcmVkX21hcDxzdHJpbmcgY29uc3QsIGludCwgZGVjbHR5cGUoaGYpPiBtICgxLCBoZik7CgovLyB0aGlzIHdvcmtzIHRvbyAoMSk6IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCnRlbXBsYXRlPGNsYXNzIEhBU0hFUj4KYXV0byBtYWtlX3Vub3JkZXJlZF9tYXAxKHNpemVfdCBidWNrZXRDb3VudCwgSEFTSEVSIGNvbnN0ICYgaGYpCiAgLT4gdW5vcmRlcmVk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