<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 565: xsputn inefficient</title>
<meta property="og:title" content="Issue 565: xsputn inefficient">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue565.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="565"><a href="lwg-defects.html#565">565</a>. <code>xsputn</code> inefficient</h3>
<p><b>Section:</b> 31.6.3.5.5 <a href="https://wg21.link/streambuf.virt.put">[streambuf.virt.put]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2006-02-23 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
        <p>

<code>streambuf::xsputn()</code>  is  specified  to  have  the  effect  of
"writing up to  <code>n</code> characters to the output  sequence as if by
repeated calls to <code>sputc(c)</code>."

        </p>
        <p>

Since  <code>sputc()</code> is required  to call  <code>overflow()</code> when
<code>(pptr()    ==   epptr())</code>    is   true,    strictly   speaking
<code>xsputn()</code>  should do  the same.   However, doing  so  would be
suboptimal in  some interesting cases,  such as in unbuffered  mode or
when the buffer is <code>basic_stringbuf</code>.

        </p>
        <p>

Assuming  calling <code>overflow()</code>  is  not really  intended to  be
required  and the  wording is  simply  meant to  describe the  general
effect of appending to the end  of the sequence it would be worthwhile
to  mention in  <code>xsputn()</code> that  the function  is  not actually
required to cause a call to <code>overflow()</code>.

        </p>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Move to Ready.
</p></blockquote>



<p id="res-565"><b>Proposed resolution:</b></p>
        <p>

Add the following sentence  to the <code>xsputn()</code> Effects clause in
27.5.2.4.5, p1 (N1804):

        </p>
        <blockquote>    
            <p>
-1- <i>Effects:</i> Writes up to <code><i>n</i></code> characters to the output
sequence as if by repeated calls to <code>sputc(<i>c</i>)</code>. The characters 
written are obtained from successive elements of the array whose first element
is designated by <code><i>s</i></code>. Writing stops when either <code><i>n</i></code>
characters have been written or a call to <code>sputc(<i>c</i>)</code> would return
<code>traits::eof()</code>. <ins>It is  uspecified whether the function  calls
<code>overflow()</code> when <code>(pptr() ==  epptr())</code> becomes true or whether
it achieves the same effects by other means.</ins>
            </p>
        </blockquote>    
        <p>

In addition,  I suggest to  add a footnote  to this function  with the
same text as Footnote 292 to  make it extra clear that derived classes
are permitted to override <code>xsputn()</code> for efficiency.

        </p>


<p><i>[
Kona (2007): We want to permit a <code>streambuf</code> that streams output directly
to a device without making calls to <code>sputc</code> or <code>overflow</code>. We believe that
has always been the intention of the committee. We believe that the
proposed wording doesn't accomplish that. Proposed Disposition: Open
]</i></p>





</body>
</html>
