<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 562: stringbuf ctor inefficient</title>
<meta property="og:title" content="Issue 562: stringbuf ctor inefficient">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue562.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#CD1">CD1</a> status.</em></p>
<h3 id="562"><a href="lwg-defects.html#562">562</a>. stringbuf ctor inefficient</h3>
<p><b>Section:</b> 31.8 <a href="https://wg21.link/string.streams">[string.streams]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</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 other</b> <a href="lwg-index.html#string.streams">issues</a> in [string.streams].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
        <p>

For  better efficiency,  the requirement  on the  stringbuf  ctor that
takes  a  string  argument  should  be  loosened  up  to  let  it  set
<code>epptr()</code>  beyond  just   one  past  the  last  initialized
character  just like  <code>overflow()</code> has  been changed  to be
allowed  to  do   (see  issue  432).  That  way   the  first  call  to
<code>sputc()</code> on  an object won't  necessarily cause a  call to
<code>overflow</code>. The corresponding change  should be made to the
string overload of the <code>str()</code> member function.

        </p>


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

Change 27.7.1.1, p3 of the Working Draft, N1804, as follows:

        </p>

<blockquote><pre>
explicit basic_stringbuf(const basic_string&lt;charT,traits,Allocator&gt;&amp; <i>s<del>tr</del></i>,
               ios_base::openmode <i>which</i> = ios_base::in | ios_base::out);
</pre>

<p>
-3- <i>Effects:</i>  Constructs an object of class <code>basic_stringbuf</code>,
initializing the base class with <code>basic_streambuf()</code>
(27.5.2.1), and initializing <code><i>mode</i></code> with <code><i>which</i></code>.
Then <ins>calls <code>str(<i>s</i>)</code>.</ins> <del>copies the content of
<i>str</i> into the <code>basic_stringbuf</code> underlying character
sequence. If <code><i>which</i> &amp; ios_base::out</code> is true, initializes the
output sequence such that <code>pbase()</code> points to the first underlying
character, <code>epptr()</code> points one past the last underlying character, and
<code>pptr()</code> is equal to <code>epptr()</code> if <code><i>which</i> &amp; ios_base::ate</code>
is true, otherwise <code>pptr()</code> is equal to <code>pbase()</code>. If
<code>which &amp; ios_base::in</code> is true, initializes the input sequence such
that <code>eback()</code> and <code>gptr()</code> point to the first underlying 
character and <code>egptr()</code> points one past the last underlying character.</del>
</p>
</blockquote>

        <p>

Change the Effects clause of the <code>str()</code> in 27.7.1.2, p2 to
read:

        </p>
<blockquote>
<p>
-2- <i>Effects:</i> Copies the content<ins>s</ins> of <code><i>s</i></code> into the
<code>basic_stringbuf</code> underlying character sequence <ins>and
initializes the input and output sequences according to <code><i>mode</i></code></ins>.
<del>If
<code><i>mode</i> &amp; ios_base::out</code> is true, initializes the output
sequence such that <code>pbase()</code> points to the first underlying character, 
<code>epptr()</code> points one past the last underlying character, and <code>pptr()</code>
is equal to <code>epptr()</code> if <code><i>mode</i> &amp; ios_base::in</code>
is true, otherwise <code>pptr()</code> is equal to <code>pbase()</code>. If
<code>mode &amp; ios_base::in</code> is true, initializes the input sequence 
such that <code>eback()</code> and <code>gptr()</code> point to the first underlying
character and <code>egptr()</code> points one past the last underlying character.</del>
</p>

        <p>

<ins>-3- <i>Postconditions:</i>  If  <code>mode  &amp; ios_base::out</code>  is  true,
<code>pbase()</code>  points  to the  first  underlying character  and
<code>(epptr() &gt;= pbase() + s.size())</code> holds; in addition, if
<code>mode &amp; ios_base::in</code> is true, <code>(pptr() == pbase()
+ s.data())</code>  holds, otherwise <code>(pptr()  == pbase())</code>
is   true.    If  <code>mode   &amp;   ios_base::in</code>  is   true,
<code>eback()</code>  points to  the first  underlying  character, and
<code>(gptr()  ==  eback())</code>  and  <code>(egptr() ==  eback()  +
s.size())</code> hold.</ins>

        </p>
</blockquote>


<p><i>[
Kona (2007) Moved to Ready.
]</i></p>





</body>
</html>
