title: How to encode large complex, constant data structures in C++
body: <p>In the past, I've used gcc's <a href="http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html">C99-style compound-literal extension</a> to C++ to encode nested constant data structures in code. Here's an example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct Tree {
      const char *name;
      const Tree *left;
      const Tree *right;
  };
  
  const Tree *const tree = (Tree []) {
      "top", // name
      (Tree[]) {
          "left",
          0,
          0
      },
      (Tree[]) {
          "right",
          0,
          0
      }
  };
  
  static void dump(const Tree *tree) {
      if (!tree) {
          cout &lt;&lt; "null";
          return;
      }
  
      cout &lt;&lt; tree-&gt;name &lt;&lt; "(";
      dump(tree-&gt;left);
      cout &lt;&lt; ", ";
      dump(tree-&gt;right);
      cout &lt;&lt; ")";
  }
  
  int main(void) {
      dump(tree);
      cout &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>The idea is to use static storage duration for these reasonably large constant structures, with zero initialization cost, and indeed no need to page anything into memory unless needed.</p>
  
  <p>This no longer works in recent version of clang, however, and the latest OS X is bundling clang under the name 'gcc'. So I need a different solution.</p>
  
  <p>What's the best standard-conforming idiom for this in C++?</p>
  
  <p>I don't particularly want to pay the cost of constructing all the objects in these structures, so if that can be avoided, it would be great.</p>