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 8453843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:51:57+00:00 2026-06-10T11:51:57+00:00

I have 4 separate integers that need to be mapped to an arbitrary, constant

  • 0

I have 4 separate integers that need to be mapped to an arbitrary, constant value.

For example, 4,2,1,1 will map to the number 42

And the number 4,2,1,2 will map to the number 86.

Is there anyway I can achieve this by using #define’s or some sort of std::map. The concept seems very simple but for some reason I can’t think of a good, efficient method of doing it. The methods I have tried are not working so I’m looking for some guidence on implementation of this.

  • 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-06-10T11:51:59+00:00Added an answer on June 10, 2026 at 11:51 am

    Will a simple function suffice?

    int get_magic_number( int a, int b , int c, int d)
    {
       if( (a==4)&&(b==2)&&(c==1)&&(d==1) ) return 42;
       if( (a==4)&&(b==2)&&(c==1)&&(d==2) ) return 86;
       ...
       throw SomeKindOfError();
    }
    

    Now that may look ugly, but you can easily create a macro to pretty it up. (Or a helper class or whatever… I’ll just show the macro as I think its easy.

    int get_magic_number( int a, int b , int c, int d)
    {
       #DEFINE MAGIC(A,B,C,D,X) if((a==(A))&&(b==(B))&&(c==(C))&&(d==(D))) return (X);
       MAGIC(4,2,1,1,  42);
       MAGIC(4,2,1,2,  86);
       ...
       #UNDEF MAGIC
       throw SomeKindOfError();
    }
    

    If you really care you can probably craft a constexpr version of this too, which you’ll never be able to do with std::map based solutions.

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

Sidebar

Related Questions

We have 2 separate products that need to communicate with each other via web
Do I need to have separate/multiple workers to run multiple websites (each with a
I have a website that is mirrored cross two sub-domains. So I have separate
I have a string that is defined as one or more dot-separated integers like
I have a perl script that writes out an array filled with integers to
I have a long running task that I need to implement on a webpage.
In C#, I have an array of integers, that represent the primary keys of
I have a program that I need to use signals and handlers with. I
I need to have text IDs in my application. For example, we have acceptable
I have a set of information that I need to store in some kind

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.