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

  • SEARCH
  • Home
  • 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 6612665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:07:31+00:00 2026-05-25T20:07:31+00:00

I have to use a huge dictionary with integer (or enum) keys and string

  • 0

I have to use a huge dictionary with integer (or enum) keys and string values. But this is totally constant. No way to change in runtime. Is there a way (using templates etc.) to retrieve dictionary data at compile time instead of using existing dictionary structure?

  • 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-25T20:07:32+00:00Added an answer on May 25, 2026 at 8:07 pm

    Clang and LLVM have solved your issue by generating tables containing their objects, using a combination of code generation and preprocessor trickery.

    You can skip either step, depending on your own setup. For example:

    // records.inc
    EXPAND_RECORD(Foo, "Foo", 4);
    EXPAND_RECORD(Bar, "Bar", 18);
    EXPAND_RECORD(Bar2, "Bar", 19);
    

    Now, you can generate your enum:

    // records.h
    enum Record {
    
    #define EXPAND_RECORD(Name, String, Value) Name,
    #include "records.inc"
    #undef EXPAND_RECORD
    
    };
    
    char const* getRecordName(Record r);
    int getRecordValue(Record r);
    
    // records.cpp
    
    char const* getRecordName(Record r) {
      switch(r) {
    #define EXPAND_RECORD(Name, String, Value) case Name: return String;
    #include "records.inc"
    #undef EXPAND_RECORD
      }
    
      abort(); // unreachable, or you can return a "null" value
    }
    
    int getRecordValue(Record r) {
      switch(r) {
    #define EXPAND_RECORD(Name, String, Value) case Name: return Value;
    #include "records.inc"
    #undef EXPAND_RECORD
      }
    
      abort(); // unreachable, or you can return a "null" value
    }
    

    In Clang and LLVM, a code generation phase is used to generate the .inc from more pleasant definition files.

    It works pretty well… but do be aware that any modification of the enum implies full recompilation. You might wish to go to a “codeset” approach, where the enum is used internally but never leaked outside, and stable values (those of the enum) are provided to the client (unsigned), so that old clients can link to the new libraries without recompilation: they will be limited to use the old set of codes, which is no problem if it’s stable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python module that makes use of a huge dictionary global variable,
I have this huge JSON file. Currently the way I am using it is:
I have a huge text file (~1GB) and sadly the text editor I use
Hello I have use DOMDocs in the past but I am stuck how to
I have a huge dictionary of words: word1 => [value1] word2 => [value2] word3
I have a situation where I need to use a huge number for the
I have a website with a huge htaccess, but I'm trying to find a
Here's the use case: I have this long form with group of field that
I have use IlMerge to merge all the dlls of my projects in one
I have use include ('base.php') script in my other scripts ( more.php ). Now

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.