title: static initialization order and concatenation of strings
body: <p>We have a rather large project that defines <code>static const std::string</code>s in several places to be used as parameter names; some of them need to be concatenated during static initialization:</p>
  
  <p>foo.h:</p>
  
  <pre><code>struct Foo {
    static const std::string ParamSuffix;
  };
  </code></pre>
  
  <p>foo.cpp:</p>
  
  <pre><code>const std::string Foo::ParamSuffix = ".suffix";
  </code></pre>
  
  <p>bar.h:</p>
  
  <pre><code>struct Bar {
    static const std::string ParamPrefix;
  };
  </code></pre>
  
  <p>bar.cpp:</p>
  
  <pre><code>const std::string Bar::ParamPrefix = "prefix";
  </code></pre>
  
  <p>baz.h:</p>
  
  <pre><code>struct Baz {
      static const std::string ParamName;
  };
  </code></pre>
  
  <p>baz.cpp:</p>
  
  <pre><code>const std::string Baz::ParamName = Bar::ParamPrefix + Foo::ParamSuffix;
  </code></pre>
  
  <p>The problem is obviously the "static initialization fiasco" as it is undefined in which order the <code>static const</code> members are initialized.</p>
  
  <p>I dislike the usual solution, i.e. replace all these variables by functions, because </p>
  
  <ol>
  <li>There's a lot of these variables, i.e. a lot of code changes</li>
  <li>The concatenations require special functions, which makes the code base inconsistent and even more ugly</li>
  </ol>
  
  <p>I currently cannot use C++11, which would make things easier with its <code>constexpr</code> feature (I think).</p>
  
  <p><strong>The question is:</strong> Is there any trick that would allow me to concatenate <code>static const std::string</code>s (or wrapper objects or whatever) to initialize another <code>static const std::string</code>?</p>