title: How to create a lambda for ostream?
body: <p>I thought the call of the <code>operator&lt;&lt;</code> would generate a two-parameter function call. So, why does this not compile, then?</p>
  
  <pre><code>#include &lt;iostream&gt; // ostream
  #include &lt;iomanip&gt; // setw, setfill
  using std::ostream; using std::setw; using std::setfill;
  struct Clock {
      int h_, m_, s_;
      Clock(int hours, int minutes, int seconds)
      : h_{hours}, m_{minutes}, s_{seconds} {}
      void setClock(int hours, int minutes, int seconds) {
          h_ = hours; m_ = minutes; s_ = seconds;
      }
      friend ostream&amp; operator&lt;&lt;(ostream&amp;os, const Clock&amp; c) {
          auto w2 = [](ostream&amp;os, int f) -&gt; ostream&amp; {
              return os &lt;&lt; setw(2) &lt;&lt; setfill( '0' ) &lt;&lt; f; };
          return os &lt;&lt; w2(c.h_) &lt;&lt;':'&lt;&lt;w2(c.m_)&lt;&lt;':'&lt;&lt;w2(c.s_); // ERROR
      }
  };
  </code></pre>
  
  <p>The error is (gcc-6)</p>
  
  <pre><code>$ g++-6 -std=gnu++1y ...
  file.cpp: In function ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Clock&amp;)’:
  file.cpp:745:33: error: no match for call to ‘(operator&lt;&lt;(std::ostream&amp;, const Clock&amp;)::&lt;lambda(std::ostream&amp;, int)&gt;) (const int&amp;)’
           return os &lt;&lt; w2(c.h_) &lt;&lt;':'&lt;&lt;w2(c.m_)&lt;&lt;':'&lt;&lt;w2(c.s_);
                               ^
  </code></pre>
  
  <p>I also tried the call <code>os &lt;&lt; w2(os,c.h_)</code> but gcc and I agreed that was nonsense. Also I tried the lambda as auto as possible:</p>
  
  <pre><code>auto w2 = [](auto&amp;os, auto f) {
      return os &lt;&lt; setw(2) &lt;&lt; setfill( '0' ) &lt;&lt; f; };
  </code></pre>
  
  <p>also no luck.</p>
  
  <p>Any hints?</p>