title: How can I obtain the length of a const stringstream's buffer without copying or seeking?
body: <p>I have a <code>const std::stringstream</code> and a desire to find out how many bytes there are in its underlying string buffer.</p>
  
  <ul>
  <li><p>I cannot <code>seekg</code> to the end, <code>tellg</code> then <code>seekg</code> to the start again, because none of these operations are available <code>const</code>ly.</p></li>
  <li><p>I do not want to get the <code>str().size()</code> because <code>str()</code> returns a copy and this may not be a trivial amount of data.</p></li>
  </ul>
  
  <p>Do I have any good options?</p>
  
  <hr>
  
  <p><em>(The stream itself is presented to me as <code>const</code>, only because it is a member of another type, and I receive a <code>const</code> reference to an object of that type. The stream represents the contents of a "document", its encapsulating object represents a CGI response and I am trying to generate an accurate <code>Content-Length</code> HTTP header line from within <code>operator&lt;&lt;(std::ostream&amp;, const cgi_response&amp;)</code>.)</em></p>