title: Passing a reflection with boost::hana
body: <p>Is there a way to get an object representing a <code>boost::hana</code> structure reflection which I can pass around and store in a map/database? </p>
  
  <p>I am creating an interface between an environment and shared libraries which are loaded dynamically as plugins.  I need to reflect some of the data structures used in the libraries so that the user can navigate these structures using the environment at runtime.</p>
  
  <p>In an example I have this structure which I can reflect easily: </p>
  
  <pre><code>struct Car {
      BOOST_HANA_DEFINE_STRUCT(Car, 
          (std::string, brand),
          (std::string, model)
      );
  };
  </code></pre>
  
  <p>My library will make an instance of <code>Car</code> and will need to make it available through an entry-point.  This means it will need to adhere to implement a base-class from my environment SDK which looks a little something like this: </p>
  
  <pre><code>template&lt;class SharedStructureType&gt;
  class LibraryAPI
  {
  public:
      virtual void run() = 0; // Some entrypoint called by the environment
  
      ReflectedType GetReflection()
      {
          return to_reflection(m_sharedData);
      }
  
  protected:
      SharedStructureType m_sharedData;
  
  private:
      ReflectedType to_reflection(SharedStructureType);
  };
  </code></pre>
  
  <p>My problem is that I'm not sure how to implement <code>LibraryAPI::to_reflection</code>.</p>
  
  <p>When a structure is reflected with boost::hana, I expected to see some object or member created which represents the reflection rules and that is what I was hoping to pass across the interface.  However, the debugger shows nothing like that.  </p>
  
  <p>I suspect that it is all resolved in the giant templates resolved at compile-time.  However, my environment and library will not be compiled at the same time and so this makes things more complicated.</p>
  
  <p>Is there a way to get an object representing a boost::hana structure reflection which I can pass around and store in a map/database?</p>
  
  <p>---------------Edit-----------</p>
  
  <p>I don't really care about de-referencing the data as much as I care about knowing the name, offset, and size of each member used by the library.  That will let me use the environment to map data between libraries based on configurations without the need to share header files between libraries.  I might add type to the reflection as a means to validate the memcpy before actually doing it.</p>
  
  <p>Unfortunately in this case, <code>bmw.brand</code> and <code>boost::hana::second(pair)</code> never occupy the same memory when I run this in a debugger.</p>
  
  <pre><code>Car bmw{"BMW", "Z3"};
  boost::hana::for_each(bmw, [&amp;](auto pair) {
      if(&amp;bmw.brand == &amp;boost::hana::second(pair)
          // We never get here
          int i;
  });
  </code></pre>