title: simulate compile time reflection in C++
body: <p>I have a following struct:</p>
  
  <pre><code>struct Data
  {
      std::string firstMember;
      std::string secondMember;
      std::string thirdMember;
  };
  </code></pre>
  
  <p>I want to select one of the members by string name in <code>constexpr</code> manner, like</p>
  
  <pre><code>Data instance;
  auto&amp; member = getMember(instance, "firstMember"); 
  </code></pre>
  
  <p>getMember is <code>constexpr</code> function/struct/macros/whatever in question and expression should be (I want it to be) optimized into simple <code>auto&amp; member = instance.firstMember;</code>. My desire here is to be able to call <code>getMember</code> from another <code>constexpr</code> function, which in turn are computing name of particular member --> some kind of compile time reflection.</p>
  
  <p>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:</p>
  
  <pre><code>REGISTER_MEMBER(Data, "firstMember", firstMember);
  </code></pre>
  
  <p>All I want is to have that compile time optimization and do nothing in runtime. Is that possible in C++11 and how?</p>