<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2272: quoted should use char_traits::eq for character comparison</title>
<meta property="og:title" content="Issue 2272: quoted should use char_traits::eq for character comparison">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2272.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="2272"><a href="lwg-defects.html#2272">2272</a>. <code>quoted</code> should use <code>char_traits::eq</code> for character comparison</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> Marshall Clow <b>Opened:</b> 2013-07-12 <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#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>
In 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> p2 b2:
</p>
<blockquote>
<p>
&mdash; Each character in <code>s</code>. If the character to be output is equal to <code>escape</code> or <code>delim</code>, 
as determined by <code>operator==</code>, first output <code>escape</code>.
</p>
</blockquote>
<p>
In 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> p3 b1 sb1:
</p>
<blockquote>
<p>
&mdash; If the first character extracted is equal to <code>delim</code>, as determined by <code>operator==</code>, [&hellip;]
</p>
</blockquote>

<p>
these should both use <code>traits::eq</code>.
</p>

<p>
Also, I believe that 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> p3 implies that:
</p>
<blockquote>
<pre>
std::ostream _stream;
std::string _string;
_stream &lt;&lt; _string;
_stream &lt;&lt; quoted(_string);
</pre>
</blockquote>
<p>
should both compile, or both fail to compile, based on whether or not their <code>char_traits</code> match.
But I believe that the standard should say that explicitly.
</p>

<p><i>[
2013-09 Chicago
]</i></p>


<p>
Marshall Clow improved the wording with support from Stefanus.
</p>

<p><i>[
2013-09 Chicago (late night issues)
]</i></p>


<p>
Moved to Ready, after confirming wording correctly reflects discussion earlier in the day.
</p>



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

<p>This wording is relative to N3691.</p>

<ol>
<li><p>Change 31.7.9 <a href="https://wg21.link/quoted.manip">[quoted.manip]</a> p2+3 as indicated:</p>

<blockquote>
<pre>
template &lt;class charT&gt;
  <i>unspecified</i> quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\'));
template &lt;class charT, class traits, class Allocator&gt;
  <i>unspecified</i> 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> <ins>and with member type <code>traits_type</code>, which in the second form is 
the same as <code>traits</code></ins>, then the expression 
<code>out &lt;&lt; quoted(s, delim, escape)</code> behaves
as 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):
</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 <code>escape</code> or <code>delim</code>, 
as determined by <del><code>operator==</code></del><ins><code>traits_type::eq</code></ins>, first output <code>escape</code>.</p></li>
<li><p><code>delim</code></p></li>
</ul>
</blockquote>

<pre>
template &lt;class charT, class traits, class Allocator&gt;
  <i>unspecified</i> quoted(basic_string&lt;charT, traits, Allocator>&amp; s,
                     charT delim=charT('"'), charT escape=charT('\\'));
</pre>
<blockquote>
<p>
-3- <i>Returns:</i> An object of unspecified type such that:
</p>
<ul>
<li><p>If <code>in</code> is an instance of <code>basic_istream</code> with member type<ins>s</ins> <code>char_type</code>
<ins>and <code>traits_type</code></ins> the same as <code>charT</code> <ins>and <code>traits</code>, respectively</ins>, then the 
expression <code>in &gt;&gt; quoted(s, delim, escape)</code> behaves as if it extracts 
the following characters from in using <code>basic_istream::operator&gt;&gt;</code> (27.7.2.2.3) which may throw 
<code>ios_base::failure</code> (27.5.3.1.1):
</p>
<ul>
<li><p>If the first character extracted is equal to <code>delim</code>, as determined by 
<del><code>operator==</code></del><ins><code>traits_type::eq</code></ins>, then: [&hellip;]</p></li>
</ul>
</li>
<li><p>
If <code>out</code> is an instance of <code>basic_ostream</code> with member type<ins>s</ins> <code>char_type</code>
<ins>and <code>traits_type</code></ins> the same as <code>charT</code> <ins>and <code>traits</code>, respectively</ins>, 
then the expression <code>out &lt;&lt; quoted(s, delim, escape)</code> behaves as specified for the <code>const 
basic_string&lt;charT, traits, Allocator&gt;&amp;</code> overload of the quoted function.
</p></li>
</ul>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
