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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:13:08+00:00 2026-06-05T10:13:08+00:00

I have a std::map<string, double> whose members look something like: X = [{N, 200},

  • 0

I have a std::map<string, double> whose members look something like:

X = [{"N", 200}, {"sigma", 1.0}, {"T", .2}]

Now, given the struct foo Y:

struct foo {
    int N;
    double T;
};

Can I programmatically map the key/value pairs X -> Y without writing a custom class for each X -> Y type mapping? Note that:

  1. X["sigma"] is not in Y, i.e. the mapping is not necessarily one-to-one
  2. The type of Y.N is an int while X["N"] is a double.

I suspect the answer is no, unless some trickery is done at compile time.

Edit: It may not be clear what I’m looking for. A pseudo-code version for this example would look something like:

if("N" in X) -> Y.N = X["N"];
if("T" in X) -> Y.T = X["T"];

Or programmatically:

for key in Y:
    if (key in X) -> Y.key = X[key]
  • 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-05T10:13:10+00:00Added an answer on June 5, 2026 at 10:13 am

    No. C++ has no concept of reflection. At compile time, there’s no "foo::N" string anymore. The compiler has converted all occurances of foo::N in the source code to a 0 byte offset within Foo objects. Also, you cannot enumerate class members at compile time.

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

Sidebar

Related Questions

I have two maps, tk1 and tk2 with the following structure: std::map<std::string, double>tk1; std::map<std::string,
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
I have a structure like struct category { int id,newID; std::string name; }; and
I have the following C++ code std::map<std::string, std::vector<std::vector<std::vector<double> > > > details details[string][index][index].push_back(123.5); May
Basically I have, typedef map<std::string, set<double> > MAP_STRING_TO_SET; What is the best way to
I have a std::map mymap Now, if I insert values in the map like:
If I have a structure like std::map<string, int> myMap; myMap["banana"] = 1; myMap["apple"] =
I have defined a Map boost::unordered_map<std::string,std::string>m_mapABC ; And I Store values in it Like
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
I have a map named valueMap as follows: typedef std::map<std::string, std::string>MAP; MAP valueMap; ...

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.