KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a following struct: struct Data { std::string firstMember; std::string secondMember; std::string thirdMember; }; I want to select one of the members by string name in constexpr manner, like Data instance; auto& member = getMember(instance, "firstMember"); getMember is constexpr function/struct/macros/whatever in question and expression should be (I want it to be) optimized into simple auto& member = instance.firstMember; . My desire here is to be able to call getMember from another constexpr function, which in turn are computing name of particular member --> some kind of compile time reflection. I know, there is no reflection in C++, therefore it's OK to register somehow (partially specialize? use some macros magic?) names of members of struct in question, like: REGISTER_MEMBER(Data, "firstMember", firstMember); All I want is to have that compile time optimization and do nothing in runtime. Is that possible in C++11 and how?
Tags (comma-separated)
Save Edits
Cancel