title: Conditional compilation of templates
body: <p>I am trying to get static_assert to help me avoid null pointers in C++11.</p>
  
  <p>The problem seems to be that C++11 require the compiler to compile templates even if they are not instantiated.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>#include &lt;type_traits&gt;
  
  template&lt;typename T, typename... Us&gt;
  std::enable_if_t&lt; std::is_constructible&lt;T, Us...&gt;::value == true, T * &gt;
  create_if_constructible(Us... args) { return new T(args...); }
  
  template&lt;typename T, typename... Us&gt;
  std::enable_if_t&lt; std::is_constructible&lt;T, Us...&gt;::value == false, T * &gt;
  create_if_constructible(Us... args) { 
     static_assert( false, "Class T constructor does not match argument list.");
     return nullptr; 
  }
  
  struct ClassA {
     ClassA(int a, string b) {}
  };
  
  void foo() {
     ClassA *a = create_if_constructible&lt;ClassA&gt;(1, "Hello");
     // ClassA *b = create_if_constructible&lt;ClassA&gt;(1, "Hello", "world"); // I want compile time error here.
  }
  </code></pre>
  
  <p>I would like this to compile without error. But the static_assert is compiled and gives me a compile time error.</p>
  
  <p>Only if the the second instantiation of the ClassA is in the code should it give me a compile time error. </p>