Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Created January 25, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiogaluppo/812f6453072c97983fed to your computer and use it in GitHub Desktop.
Save fabiogaluppo/812f6453072c97983fed to your computer and use it in GitHub Desktop.
#include <unordered_map>
template <typename TKey, typename TValue>
inline std::unordered_map<TKey, TValue> make_dic(typename std::unordered_map<TKey, TValue>::size_type capacity)
{
return std::unordered_map<TKey, TValue>(capacity);
}
...
auto dic = make_dic<std::string, std::string>(1024);
//better than:
//std::unordered_map<std::string, std::string> dic = make_dic<std::string, std::string>(1024);
std::cout << (typeid(dic).name()) << "\n"; //class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment