title: Default value on generic predicate as argument - continued
body: <p>I know there was already <a href="https://stackoverflow.com/questions/4804536/default-value-on-generic-predicate-as-argument">Default value on generic predicate as argument</a>.</p>
  <p>But maybe there are new options now with c++11, c++14, or c++17?</p>
  <p>How can i make this work without overload?</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;numeric&gt;
  #include &lt;algorithm&gt;
  #include &lt;iterator&gt;
  #include &lt;iostream&gt;
  
  #if 0
  
  template &lt;typename CONTAINER, typename PRED&gt;
  void print(CONTAINER const &amp; cont, PRED pred = [] (typename CONTAINER::value_type) { return true;})
  {
      std::copy_if(cont.begin(), cont.end(), std::ostream_iterator&lt;typename CONTAINER::value_type&gt;(std::cout, &quot; &quot;), pred);
      std::cout &lt;&lt; std::endl;
  }
  
  #else
  
  template &lt;typename CONTAINER, typename PRED&gt;
  void print(CONTAINER const &amp; cont, PRED pred)
  {
      std::copy_if(cont.begin(), cont.end(), std::ostream_iterator&lt;typename CONTAINER::value_type&gt;(std::cout, &quot; &quot;), pred);
      std::cout &lt;&lt; std::endl;
  }
  
  template &lt;typename CONTAINER&gt;
  void print (CONTAINER const &amp; cont)
  {
      std::copy(cont.begin(), cont.end(), std::ostream_iterator&lt;typename CONTAINER::value_type&gt;(std::cout, &quot; &quot;));
      std::cout &lt;&lt; std::endl;
  }
  
  #endif
  
  bool
  even(
          const int&amp; i)
  {
      return not (i % 2);
  }
  
  int
  main(
          int argc,
          char **argv)
  {
      std::vector&lt;int&gt; myVec(20);
      std::iota(myVec.begin(), myVec.end(), 1);
  
      print(myVec);
  
      print(myVec, even);
  
      return 0;
  }
  </code></pre>
  <p>Enabling #if 0 section results in <BR>
  ../main.cpp:17:6: note:   template argument deduction/substitution failed:<BR>
  ../main.cpp:56:13: note:   couldn't deduce template parameter ‘PRED’<BR></p>