title: Force explicit template instantiation with CRTP
body: <p>I am trying to use a CRTPed base to hold some static initialization code like this:</p>
  
  <pre><code>template &lt;typename T&gt;
  class InitCRTP
  {
  public:
  static InitHelper&lt;T&gt; init;
  };
  
  template &lt;typename T&gt; InitHelper&lt;T&gt; InitCRTP&lt;T&gt;::init;
  </code></pre>
  
  <p>Now, any class which needs to do the work in <code>InitHelper&lt;T&gt;</code> can do this:</p>
  
  <pre><code>class WantInit : public InitCRTP&lt;WantInit&gt;
  {
    public:
    void dummy(){init;}//To force instantiation of init 
  };
  template class InitCRTP&lt;WantInit&gt;;//Forcing instantiation of init through explicit instantiation of `InitCRTP&lt;WantInit&gt;`.
  </code></pre>
  
  <p>To force instantiation of <code>InitCRTP&lt;WantInit&gt;::init</code>, I can either use <code>dummy</code> or use the explicit instantiation as shown above. Is there a way of getting around this with doing neither? I would like users of this pattern to be able to simply inherit from <code>InitCRTP&lt;WantInit&gt;</code> and not worry about anything else. If it helps, using <code>C++11</code> is not an issue.</p>