Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:39:13+00:00 2026-05-18T09:39:13+00:00

Recently, I’ve been using one of the lesser-used STL features- custom allocators, and I

  • 0

Recently, I’ve been using one of the lesser-used STL features- custom allocators, and I need some serious help in reducing my semantic overhead. Take for example, the definition of an unordered map, which maps filenames to an unordered map of a pair of ints and a shared_ptr to a Token, but using 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;

That’s 404 characters of definitions. And then to construct it, I have to pass in the default for every template argument, except the Allocator, which can’t be default constructed, AND the bucket count, for which no definition exists, resulting in another 168 characters just to construct the damn thing. Plus, of course, the same again every time I want to insert, because the value type of the first map has to be constructed like that too.

Is there any way that all of this can be avoided without having to write my own unordered_map? It’s seriously starting to slow down my productivity.

Edit: Sorry! I meant, in general, for STL containers, not just unordered_map specifically, it’s just the worst case. I’ve also got this problem with regular map, unordered_set, etc, and can’t go writing a function to do all of this for all of the possible STL containers I might need invidually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:39:14+00:00Added an answer on May 18, 2026 at 9:39 am

    icecrime’s solution can also be done with only slightly more ugliness on older compilers via the code below. You also may be able to add factory functions to simplify construction.

    template<typename K, typename V> struct unordered_map_type
    {
        typedef std::unordered_map<
            K, 
            V,
            std::hash<K>,
            std::equal_to<K>,
            Allocator<
                std::pair<const K, V>
            >
        > type;
    };
    
    typedef std::pair<int, int> token_key_type;
    typedef unordered_map_type<token_key_type, std::shared_ptr<Token> >::type filename_map_value_type;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I started changing some of our applications to support MS SQL Server as
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Recently I had to develop a SharePoint workflow, and I found the experience quite
Recently we got a new server at the office purely for testing purposes. It
Recently, I read an article entitled SATA vs. SCSI reliability . It mostly discusses
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently a friend and I were talking about securing stored procedure code in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.