title: Force Templated Constructor to Run?
body: <p>I know there is a initailzer trick to forcing a global object to be constructed regardless of where it is used. This is used for std::cout i believe.</p>
  
  <pre><code>#ifndef GUARD_H
  #define GUARD_H
  
  class Magical
  {
     // default constructor and such...
  };
  
  class Init
  {
  public:
      Init();
  };
  
  extern Magical&amp; magic;
  
  namespace
  {
      Init __magical_initializer; // works as this object is constructed in every source file it is included in
  }
  
  #endif
  </code></pre>
  
  <p>src:</p>
  
  <pre><code>#include "magical.h"
  
  #include &lt;new&gt;
  
  static int count; // believe there is a spec somewhere which states global integers are initialized with zero
  
  static alignas(Magical) char buffer[sizeof(Magical)];
  
  Magical&amp; magic = *reinterpret_cast&lt;Magical*&gt;(buffer);
  
  Init::Init()
  {
      if(!count++)
      {
          new(buffer) Magical;
      }
  }
  </code></pre>
  
  <p>I was wondering if there was a template equivalent to this, as such my code would look something like this:</p>
  
  <pre><code>template&lt;typename T&gt;
  class Base
  {
  
      static Magical&lt;T&gt; __private; // need this constructor to be called.
  
  };
  
  // usage:
  
  class SomeClass : public Base&lt;SomeClass&gt;
  {
  };
  </code></pre>