title: Static_cast and templated conversion function
body: <p>I have a class that wraps some type and attaches a Dimension. It should be convertible to the underlying type, but only if <code>Dim=0</code>. The conversion operator should not be callable in other cases (so a <code>static_assert</code> in the function would not work for me).</p>
  <p>The following code works, if the <code>enable_if</code>-construction is deleted, but not in this form.</p>
  <pre><code>template&lt;class T, int Dim&gt;
  class Unit {
      public:
      explicit Unit(T const&amp; value): _value(value) {}
  
      template&lt;int D = Dim, typename = typename std::enable_if&lt;D == 0&gt;::type&gt;
      operator T() { return _value; }
      private:
      T _value;
  };
  
  auto main() -&gt; int
  {
      auto a = double{0};
      auto u = Unit&lt;double, 0&gt;{a};
      auto i = static_cast&lt;int&gt;(u);    
      return i;
  }  
  </code></pre>
  <p>What is the reason for this and is there a work around to allow the cast, but also restrict the conversion?</p>