title: How to enable member function using boolean template parameter?
body: <p>I would like a class to have two different implementations of <code>push</code>, and choose based on a boolean template argument. I tried using the SFINAE principle as described in <a href="https://stackoverflow.com/a/41740466/6263317">this answer</a>, like so:</p>
  
  <pre><code>template&lt;class T, bool foo=true&gt;
  class Bar {
    template &lt;&gt;
    typename std::enable_if&lt;foo&gt;::type
    push(const T&amp; value) { /* one implementation */}
  
    template &lt;&gt;
    typename std::enable_if&lt;!foo&gt;::type
    push(const T&amp; value) { /* another implementation */ } 
  }
  </code></pre>
  
  <p>however, I am getting an error of "cannot specialize a function <code>push</code> within class scope" under gcc, and I do not understand why. Although my code is not exactly like that in the linked answer, it seems very similar and I can't spot the critical difference.</p>
  
  <p>I also tried using a syntax similar to that suggested in <a href="https://stackoverflow.com/a/29001963/6263317">this answer</a> but it is also not working (the error is "class member cannot be redeclared" instead):</p>
  
  <pre><code>  template &lt;bool enable=foo&gt;
    typename std::enable_if&lt;enable&gt;::type
    push(const T&amp; value) { /* one implementation */}
  
    template &lt;bool enable=!foo&gt;
    typename std::enable_if&lt;enable&gt;::type
    push(const T&amp; value) { /* another implementation */ } 
  </code></pre>
  
  <p>How can I accomplish this?</p>