Recently, I used one of the less used STL functions - custom allocators, and I need some serious help in reducing my semantic overhead. Take, for example, the definition of an unordered map that maps file names to an unordered map of int and shared_ptr pairs on a token, but uses a custom allocator.
typedef std::pair<int, int> token_key_type; typedef std::unordered_map< token_key_type, std::shared_ptr<Token>, std::hash<token_key_type>, std::equal_to<token_key_type>, Allocator< std::pair< const token_key_type, std::shared_ptr< Token > > > > filename_map_value_type; std::unordered_map< string, filename_map_value_type, std::hash<string>, std::equal_to<string>, Allocator< std::pair< const string, filename_map_value_type > > > tokens;
These are 404 character definitions. And then, to build it, I have to pass a default value for each argument of the template, with the exception of Allocator, which cannot be configured by default, and counting the bucket for which there is no definition, resulting in another 168 characters just plotting the trait take it. Plus, of course, the same thing again every time I want to insert, because the value type of the first map also needs to be built.
Is there a way to avoid this without having to write my own unordered_map? This is seriously starting to slow down my performance.
Edit: Sorry! I meant, in general, for STL containers, and not just for unordered_map specifically, this is just the worst case. I also have this problem with a normal map, unordered_set, etc., And I cannot write a function to do all this for all possible STL containers that I might need using invidually.
c ++ c ++ 11 visual-studio-2010
Puppy
source share