<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2226: wstring_convert methods do not take allocator instance</title>
<meta property="og:title" content="Issue 2226: wstring_convert methods do not take allocator instance">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2226.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#NAD">NAD</a> status.</em></p>
<h3 id="2226"><a href="lwg-closed.html#2226">2226</a>. <code>wstring_convert</code> methods do not take allocator instance</h3>
<p><b>Section:</b> 99 [depr.conversions.string] <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Glen Fernandes <b>Opened:</b> 2012-12-14 <b>Last modified:</b> 2019-02-26</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#depr.conversions.string">active issues</a> in [depr.conversions.string].</p>
<p><b>View all other</b> <a href="lwg-index.html#depr.conversions.string">issues</a> in [depr.conversions.string].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The <code>wstring_convert</code> class template, described in 99 [depr.conversions.string], does not 
support custom stateful allocators. It only supports custom stateless allocators.
<p/>
The <code>to_bytes</code> member function returns <code>basic_string&lt;char, char_traits&lt;char&gt;, Byte_alloc&gt;</code>  
but it does not take an instance of <code>Byte_alloc</code> to pass to the constructor of the <code>basic_string</code>.
<p/>
Similarly the <code>from_bytes</code> member function returns <code>basic_string&lt;Elem, char_traits&lt;Elem&gt;, Wide_alloc&gt;</code>  
but it does not take an instance of <code>Wide_alloc</code> to pass to the constructor of the <code>basic_string</code>.
<p/>
This makes these two member functions and the <code>wstring_convert</code> class template not usable when <code>Wide_alloc</code> 
or <code>Byte_alloc</code> are stateful allocators.
</p>

<p><i>[2013-01-22, Glen provides wording]</i></p>


<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to NAD Future.
</p>
<p>
This is clearly an extension that the LEWG may want to take a look at, once we have more experience
with appropriate use of allocators with the C++11 model.
</p>

<p><i>[LEWG Kona 2017]</i></p>

<p>Recommend NAD: Does this follow the pattern? Should be discussed as a group. Do we have the experience with 
the C++11 allocator model to know that this is the addition to make?</p>
<p>Should <code>to_string()</code> also take an allocator? <code>substr()</code>? Any function that returns a string?</p>
<p>This suggests a larger change.</p>

<p><i>[Kona 2019]</i></p>

<p>Jonathan points out: The wstring_convert type is deprecated now.</p>


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

<ol>
<li><p>In 99 [depr.conversions.string]/2 and /6 "Class template <code>wstring_convert</code> synopsis" change the overloads 
of the member function <code>from_bytes()</code> so that all four overloads take an additional parameter
which is an instance of <code>Wide_alloc</code>:</p>

<blockquote><pre>
wide_string from_bytes(char byte<ins>, const Wide_alloc&amp; alloc = Wide_alloc()</ins>);
wide_string from_bytes(const char *ptr<ins>, const Wide_alloc&amp; alloc = Wide_alloc()</ins>);
wide_string from_bytes(const byte_string&amp; str<ins>, const Wide_alloc&amp; alloc = Wide_alloc()</ins>);
wide_string from_bytes(const char *first, const char *last<ins>, const Wide_alloc&amp; alloc = Wide_alloc()</ins>);
</pre></blockquote>
</li>

<li><p>In 99 [depr.conversions.string] /8 specify that this <code>Wide_alloc</code> allocator parameter is used to
construct the <code>wide_string</code> object returned from the function:</p>

<p>
-7- <i>Effects</i>: The first member function shall convert the single-element sequence <code>byte</code> to a wide string.
The second member function shall convert the null-terminated sequence beginning at <code>ptr</code> to a wide
string. The third member function shall convert the sequence stored in <code>str</code> to a wide string. The fourth
member function shall convert the sequence defined by the range <code>[first, last)</code> to a wide string.
<p/>
-8- In all cases:
</p>
<ul>
<li><p>If the <code>cvtstate</code> object was not constructed with an explicit value, it shall be set to its default value
(the initial conversion state) before the conversion begins. Otherwise it shall be left unchanged.</p></li>

<li><p>The number of input elements successfully converted shall be stored in <code>cvtcount</code>.</p></li>

<li><p><ins>The <code>Wide_alloc</code> allocator parameter is used to construct the <code>wide_string</code> object returned 
from the function.</ins></p></li>
</ul>
</li>

<li><p>In 99 [depr.conversions.string]/2 and /12 "Class template <code>wstring_convert</code> synopsis" change the overloads 
of the member function <code>to_bytes()</code> so that all four overloads take an additional parameter
which is an instance of <code>Byte_alloc</code>:</p>

<blockquote><pre>
byte_string to_bytes(Elem wchar<ins>, const Byte_alloc&amp; alloc = Byte_alloc()</ins>);
byte_string to_bytes(const Elem *wptr<ins>, const Byte_alloc&amp; alloc = Byte_alloc()</ins>);
byte_string to_bytes(const wide_string&amp; wstr<ins>, const Byte_alloc&amp; alloc = Byte_alloc()</ins>);
byte_string to_bytes(const Elem *first, const Elem *last<ins>, const Byte_alloc&amp; alloc = Byte_alloc()</ins>);
</pre></blockquote>
</li>

<li><p>In 99 [depr.conversions.string] /13 specify that this <code>Byte_alloc</code> allocator parameter is used to
construct the <code>byte_string</code> object returned from the function:</p>

<p>
-12- <i>Effects</i>: The first member function shall convert the single-element sequence <code>wchar</code> to a byte string.
The second member function shall convert the null-terminated sequence beginning at <code>wptr</code> to a byte
string. The third member function shall convert the sequence stored in <code>wstr</code> to a byte string. The
fourth member function shall convert the sequence defined by the range <code>[first, last)</code> to a byte string.
<p/>
-13- In all cases:
</p>
<ul>
<li><p>If the <code>cvtstate</code> object was not constructed with an explicit value, it shall be set to its default value
(the initial conversion state) before the conversion begins. Otherwise it shall be left unchanged.</p></li>

<li><p>The number of input elements successfully converted shall be stored in <code>cvtcount</code>.</p></li>

<li><p><ins>The <code>Byte_alloc</code> allocator parameter is used to construct the <code>byte_string</code> object returned 
from the function.</ins></p></li>
</ul>
</li>

</ol>





</body>
</html>
