title: Skipping explicit template initialization to avoid double initialization
body: <p>I try to make a template to only work with double and a user-defined type.
  The user can choose the user defined type by a typedef in a included header file. </p>
  
  <pre><code>typedef float Usertype;
  </code></pre>
  
  <p>I solved this by writing the following in the end of my template source files:</p>
  
  <pre><code>template class SpaceDiscretizer&lt;Datatype::Usertype&gt;;
  template class SpaceDiscretizer&lt;double&gt;;
  </code></pre>
  
  <p>However I run into a problem when the user defines Usertype as double!
  I tried to follow some directions, namely these topics: <a href="https://stackoverflow.com/questions/11982012/how-can-i-provide-template-specializations-for-typedefs-of-the-same-type">How can I provide template specializations for typedefs of the same type?</a>, <a href="https://stackoverflow.com/questions/13925730/conditional-explicit-template-instantiation">Conditional explicit template instantiation</a></p>
  
  <pre><code>struct dummy{};
  template class SpaceDiscretizer&lt; std::conditional&lt;std::is_same&lt;double,Datatype::Usertype&gt;::value, dummy, double&gt;::type&gt;;
  //typedef typename std::enable_if&lt;false,double&gt;::type mytype;
  //template class SpaceDiscretizer&lt;mytype&gt;;
  template class SpaceDiscretizer&lt;Datatype::Usertype&gt;;
  </code></pre>
  
  <p>The first one doesn't work,because if SpaceDiscretizer gets initialized with anything non-complicated,except for double, it does not work. But I want to give the user a easy way to add a working alternative to double in the feature.
  The second (commented out) try fails, because this is not an overload and if type is non existent, mytype won't be ignored, but an error is put out instead.</p>
  
  <p><strong>Edit:</strong>
  I have a lot of places, where I don't use a template or must ensure that multiple unconnected classes use the same datatype. I am requiered to keep the implementation in .cpp file. To solve this, I include a header file to all the relevant places, so that the user can change the value at one place and have it all be consistent. A problem arises, because I always want to initialize for double, but it would be natural for the user to specify double as the Usertype.</p>