<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2344: quoted()'s interaction with padding is unclear</title>
<meta property="og:title" content="Issue 2344: quoted()'s interaction with padding is unclear">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2344.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++14">C++14</a> status.</em></p>
<h3 id="2344"><a href="lwg-defects.html#2344">2344</a>. <code>quoted()</code>'s interaction with padding is unclear</h3>
<p><b>Section:</b> 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Stephan T. Lavavej <b>Opened:</b> 2013-11-01 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#quoted.manip">issues</a> in [quoted.manip].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Given this code:
</p>
<blockquote><pre>
cout &lt;&lt; "[" &lt;&lt; left &lt;&lt; setfill('x') &lt;&lt; setw(20) &lt;&lt; R"("AB \"CD\" EF")" &lt;&lt; "]" &lt;&lt; endl;
cout &lt;&lt; "[" &lt;&lt; left &lt;&lt; setfill('y') &lt;&lt; setw(20) &lt;&lt; quoted(R"(GH "IJ" KL)") &lt;&lt; "]" &lt;&lt; endl;
</pre></blockquote>
<p>
The first line prints <code>["AB \"CD\" EF"xxxxxx]</code>. The second line should probably print <code>["GH \"IJ\" KL"yyyyyy]</code>, but 
31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a>/2 doesn't say whether or how <code>quoted()</code> should interact with padding. All it says is that 
</p>
<blockquote><p>
"<code>out &lt;&lt; quoted(s, delim, escape)</code> behaves as if it inserts the following characters into out using character 
inserter function templates (27.7.3.6.4)". 
</p></blockquote>
<p>
31.7.6.3.4 <a href="https://wg21.link/ostream.inserters.character">[ostream.inserters.character]</a> specifies both single-character and null-terminated inserters, both referring to 
31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>/3 for padding. Literally implementing <code>quoted()</code> with single-character inserters 
would result in padding being emitted after the first character, with undesirable effects for <code>ios_base::left</code>.
<p/>
It appears that 27.4.4.4 <a href="https://wg21.link/string.io">[string.io]</a>/5 has the appropriate incantations to follow here. It says that <code>os &lt;&lt; str</code> 
</p>
<blockquote><p>
"Behaves as a formatted output function (27.7.3.6.1) of <code>os</code>. Forms a character sequence <code>seq</code>, initially consisting of the 
elements defined by the range <code>[str.begin(), str.end())</code>. Determines padding for <code>seq</code> as described in 27.7.3.6.1. 
Then inserts <code>seq</code> as if by calling <code>os.rdbuf()-&gt;sputn(seq, n)</code>, where <code>n</code> is the larger of <code>os.width()</code> 
and <code>str.size();</code> then calls <code>os.width(0)</code>." 
</p></blockquote>
<p>
Additionally, saying that it's a "formatted output function" activates 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>/1's wording for 
sentry objects.
</p>

<p><i>[2014-02-14 Issaquah meeting: Move to Immediate]</i></p>




<p id="res-2344"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3797.</p>

<ol>
<li><p>Edit 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> as follows:</p>

<blockquote><pre>
template &lt;class charT&gt;
  unspecified quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\'));
template &lt;class charT, class traits, class Allocator&gt;
  unspecified quoted(const basic_string&lt;charT, traits, Allocator>&amp; s,
                     charT delim=charT('"'), charT escape=charT('\\'));
</pre><blockquote>
<p>
-2- <i>Returns:</i> An object of unspecified type such that if <code>out</code> is an instance of <code>basic_ostream</code> with member
type <code>char_type</code> the same as <code>charT</code>, then the expression <code>out &lt;&lt; quoted(s, delim, escape)</code> behaves
as <del>if it inserts the following characters into <code>out</code> using character inserter function templates (27.7.3.6.4),
which may throw <code>ios_base::failure</code> (27.5.3.1.1)</del><ins>a formatted output function (31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>) 
of <code>out</code>. This forms a character sequence <code>seq</code>, initially consisting of the following elements</ins>:
</p>
<ul>
<li><p>
<code>delim</code>.
</p></li>
<li><p>
Each character in <code>s</code>. If the character to be output is equal to escape or <code>delim</code>, as determined by
<code>operator==</code>, first output <code>escape</code>.
</p></li>
<li><p>
<code>delim</code>.
</p></li>
</ul>
<p>
<ins>Let <code>x</code> be the number of elements initially in <code>seq</code>. Then padding is determined for <code>seq</code> as described 
in 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>, <code>seq</code> is inserted as if by calling <code>out.rdbuf()-&gt;sputn(seq, n)</code>, where 
<code>n</code> is the larger of <code>out.width()</code> and <code>x</code>, and <code>out.width(0)</code> is called.</ins>
The expression <code>out &lt;&lt; quoted(s, delim, escape)</code> shall have type <code>basic_ostream&lt;charT, traits&gt;&amp;</code>
and value <code>out</code>.
</p>
</blockquote></blockquote>
</li>

</ol>






</body>
</html>
