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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:14:08+00:00 2026-05-26T20:14:08+00:00

I have a map, where string representing the name of attribute and the second

  • 0

I have a map, where string representing the name of attribute and the second value representing the type, which this attribute should have.

map.insert(make_pair("X", iDatatype::iUint));
map.insert(make_pair("Y", iDatatype::iUint));
map.insert(make_pair("RADIANT", iDatatype::iFloat));

where iDatatype is just enumeration of all possible types.

 typedef enum
{
    iUnknown    = 0,
    iByte   = 1,
    iChar       = 2,
    iUChar      = 3,
    iShort      = 4.....

} iDatatype;

If the program gets the command to create, for example, “RADIANT” than it look at the map, find the iDatatype value (iter->second) and go to switch case.

 switch (iter->second) {
           case iDatatype::iUint:
           uint value = ......
            // You gotta do what you gonna do
            break;
              } .......

In Switch case, the function, which depends on type of attribute, will be called.

This code works. But I am not sure, if it the best solution to map string with the types.
And the problem that I don’t know what should I look for? Could you recommend what methods or techniques are commonly used for such purpose? Thank you a lot.

  • 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-26T20:14:09+00:00Added an answer on May 26, 2026 at 8:14 pm

    Unless you need the map for some other reference, another approach will be:

    if(command == "X" || command == "Y") // make sure command is std::string
                                         // or use strcmp
    {
        // create uint
    }
    else if(command == "RADIANT")
    {
        // create float
    }
    

    However I’m not sure how much faster this will be than using a map, because a map uses binary search while this uses iterative search.
    If you want to gain the boost of binary search while no need for another enum you can use a map of functions:

    std::map<std::string, std::function<void()> map;
    map.insert(make_pair("X", &create_uint));
    map.insert(make_pair("Y", &create_uint));
    map.insert(make_pair("RADIANT", &create_float));
    

    and later call it like:

    std::string key = "X";
    map[key]();
    

    you can also pass parameters to it like:

    void create_uint(std::string param) { /* ... */ }
    
    std::map<std::string, std::function<void(std::string)> map;
    map.insert(make_pair("X", &create_uint));
    
    std::string key = "X";
    std::string param = "XYZ";
    map[key](param);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have something like this: Map<String, String> myMap = ...; for(String key : myMap.keySet())
I have tried this but it does not work: val map:Map[String,String] = for {
I have a map of type: map[string]interface{} And finally, I get to create something
We have a number of Scala classes returning Map[String,String] (key,value) results for storage in
I have code like this: val dm = List[String]() val dk = List[Map[String,Object]]() .....
I have a string representing a path. Because this application is used on Windows,
So I have a Map in Scala like this: val m = Map[String, String](
I have a map between string and a class object. I populate this map
Suppose I have list countries of type List[String] and map capitals of type Map[String,

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.