title: Use << operator inside function arguments
body: <p>I want to create a function that allows me to use the <code>&lt;&lt;</code> operator in argument and inside it uses the corresponding stringstream.</p>
  
  <p>Something like:</p>
  
  <pre><code>/* This does not do what i want below */
  void printStream(std::stringstream&amp; ss) {
    std::cout &lt;&lt; ss.str();
  }
  
  /* Desired function usage */
  printStream("The number is: " &lt;&lt; 42 &lt;&lt; ".");
  </code></pre>
  
  <p>What should I use in function declaration?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Following Deduplicator suggestion, I'm trying to use variadic template. For my purposes, I've decided to create a template that takes a list of argument and returns the composed string.</p>
  
  <p>This is the code:</p>
  
  <pre><code>template &lt;typename First, typename... Rest&gt; void getStringInner(std::stringstream&amp; ss, const First&amp; first, const Rest&amp;... rest) {
    ss &lt;&lt; first;
    getStringInner(ss, rest...);
  }
  
  template &lt;typename First, typename... Rest&gt; std::string getString(const First&amp; first, const Rest&amp;... rest) {
    std::stringstream ss;
    getStringInner(ss, first, rest...);
    return ss.str();
  }
  </code></pre>
  
  <p>Unfortunately Visual Studio gives me an error:</p>
  
  <blockquote>
    <p>error C2678: binary '&lt;&lt;' : no operator found which takes a left-hand
    operand of type 'std::stringstream' (or there is no acceptable
    conversion)   main.cpp    42  Test</p>
  </blockquote>
  
  <p>The row with error is <code>ss &lt;&lt; first;</code> in <code>getStringInner</code>.</p>
  
  <p>What I'm doing wrong?</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I've found the error. This is the working code:</p>
  
  <pre><code>template &lt;typename First&gt; void getStringInner(std::stringstream&amp; ss) {}
  
  template &lt;typename First&gt; void getStringInner(std::stringstream&amp; ss, const First&amp; first) {
    ss &lt;&lt; first;
  }
  
  template &lt;typename First, typename... Rest&gt; void getStringInner(std::stringstream&amp; ss, const First&amp; first, const Rest&amp;... rest) {
    ss &lt;&lt; first;
    getStringInner(ss, rest...);
  }
  
  template &lt;typename First, typename... Rest&gt; std::string getString(const First&amp; first, const Rest&amp;... rest) {
    std::stringstream ss;
    getStringInner(ss, first, rest...);
    return ss.str();
  }
  </code></pre>