<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2758: std::string{}.assign("ABCDE", 0, 1) is ambiguous</title>
<meta property="og:title" content="Issue 2758: std::string{}.assign(&quot;ABCDE&quot;, 0, 1) is ambiguous">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2758.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++17">C++17</a> status.</em></p>
<h3 id="2758"><a href="lwg-defects.html#2758">2758</a>. <code>std::string{}.assign("ABCDE", 0, 1)</code> is ambiguous</h3>
<p><b>Section:</b> 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Marshall Clow <b>Opened:</b> 2016-07-30 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#string.assign">issues</a> in [string.assign].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Before C++17, we had the following signature to <code>std::basic_string</code>:
</p>
<blockquote><pre>
basic_string&amp;
  assign(const basic_string&amp; str, size_type pos, size_type n = npos);
</pre></blockquote>
<p>
Unlike most of the other member functions on <code>std::basic_string</code>, there were not corresponding
versions that take a <code>charT*</code> or <code>(charT *, size)</code>.
<p/>
In <a href="https://wg21.link/p0254r2">p0254r2</a>, we (I) added:
</p>
<blockquote><pre>
basic_string&amp;
  assign(basic_string_view&lt;charT, traits&gt; sv, size_type pos, size_type n = npos);
</pre></blockquote>
<p>
which made the code above ambiguous. There are two conversions from "<code>const charT*</code>", 
one to <code>basic_string</code>, and the other to <code>basic_string_view</code>, and they're both equally 
good (in the view of the compiler).
<p/>
This ambiguity also occurs with the calls
</p>
<blockquote><pre>
insert(size_type pos1, const basic_string&amp; str,             size_type pos2, size_type n = npos);
insert(size_type pos1, basic_string_view&lt;charT, traits&gt; sv, size_type pos2, size_type n = npos);
</pre></blockquote>
<p>
but I will file a separate issue (<a href="lwg-defects.html#2757" title="std::string{}.insert(3, &quot;ABCDE&quot;, 0, 1) is ambiguous (Status: Resolved)">2757</a><sup><a href="https://cplusplus.github.io/LWG/issue2757" title="Latest snapshot">(i)</a></sup>) for that.
<p/>
A solution is to add <em>even more</em> overloads to <code>assign</code>, to make it match all the other member
functions of <code>basic_string</code>, which come in fours (<code>string</code>, <code>pointer</code>, <code>pointer + size</code>, 
<code>string_view</code>).
</p>

<p><i>[2016-08-03, Chicago, Robert Douglas provides wording]</i></p>


<p><i>[2016-08-05, Tim Song comments]</i></p>

<p>
On the assumption that the <code>basic_string</code> version is untouchable, I like the updated P/R, with a couple comments:
</p>
<ol>
<li><p>If it's constraining on <code>is_convertible</code> to <code>basic_string_view</code>, then I think it should take 
by reference to avoid copying <code>T</code>, which can be arbitrarily expensive. Both <code>const T&amp;</code> and 
<code>T&amp;&amp;</code> should work; the question is whether to accommodate non-const <code>operator basic_string_view()</code>s 
(which arguably shouldn't exist).</p></li>
<li><p>Minor issue: <code>compare</code> tests <code>is_convertible</code> and then uses direct-initialization syntax 
(which is <code>is_constructible</code>). They should match, because it's possible to have <code>basic_string_view sv = t;</code> 
succeed yet <code>basic_string_view sv(t);</code> fail.</p></li>
</ol>

<p><i>[2016-08-05, Chicago LWG]</i></p>

<ol>
<li>breaking ABI was a non-starter</li>
<li>we want to convert <code>char const*</code> to <code>basic_string_view</code> if possible</li>
<li>we want to take the original type by reference, to avoid new user string types from being copied</li>
<li>it is unfortunate that each length of string literal will generate a new entry in the symbol table</li>
</ol>
<p>Given feedback from discussion, we wish to go with the <code>is_convertible_v</code> method, but change:</p>
<ol>
<li>the function parameter type to <code>T const&amp;</code> for each overload</li>
<li>the parameter type in <code>is_convertible_v</code> to <code>T const&amp;</code></li>
<li>the initialization of <code>sv(t)</code> to <code>sv = t</code></li>
</ol>

<p><i>[2016-08, Chicago]</i></p>

<p>Fri PM: Move to Tentatively Ready</p>

<p><i>[2016-08-16, Jonathan Wakely reopens]</i></p>

<p>
The P/R is not correct, the new overloads get chosen in preference to
the overloads taking <code>const char*</code> when passed a <code>char*</code>:
</p>
<blockquote><pre>
#include &lt;string&gt;

int main () {
  std::string str("a");
  char c = 'b';
  str.replace(0, 1, &amp;c, 1);
  if (str[0] != 'b')
    __builtin_abort();
}
</pre></blockquote>
<p>
With the resolution of 2758 this is now equivalent to:
</p>
<blockquote><pre>
str.replace(0, 1, string_view{&amp;c, 1}, 1);
</pre></blockquote>
<p>
which replaces the character with <code>string_view{"b", 1}.substr(1, npos)</code>
i.e. an empty string.
<p/>
The SFINAE constraints need to disable the new overloads for (at
least) the case of non-const <code>value_type*</code> arguments.
<p/>
I've implemented an alternative resolution, which would be specified as:
</p>
<blockquote><p>
<i>Remarks:</i> This function shall not participate in overload resolution
unless <code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is
<code>true</code> <ins>and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code></ins>.
</p></blockquote>
<p>
All the overloads have the same problem.
<p/>
This program prints no output in C++14, and we should make sure it prints no output in C++17 too:
</p>
<blockquote><pre>
#include &lt;string&gt;

int main()
{
  std::string str("a");
  char c[1] = { 'b' };
  str.append(c, 1);
  if (str != "ab")
    puts("bad append");
  str.assign(c, 1);
  if (str != "b")
    puts("bad assign");
  str.insert(0, c, 1);
  if (str != "bb")
    puts("bad insert");
  str.replace(0, 2, c, 1);
  if (str != "b")
    puts("bad replace");
  if (str.compare(0, 1, c, 1))
    puts("bad compare");
}
</pre></blockquote>
<p>
Ville and I considered "<code>is_same_v&lt;decay_t&lt;T&gt;, char*&gt;</code> is <code>false</code>" but
that would still select the wrong overload for an array of const <code>char</code>,
because the new function template would be preferred to doing an array-to-pointer conversion to 
call the old overload.
</p>

<p><i>[2016-09-09 Issues Resolution Telecon]</i></p>

<p>Ville to provide updated wording; Marshall to implement</p>
  
<p><i>[2016-10-05]</i></p>

<p>
Ville provides revised wording.
</p>

<p><i>[2016-10 Telecon]</i></p>

<p>Ville's wording has been implemented in libstdc++ and libc++. Move this to Tentatively Ready and <a href="lwg-defects.html#2757" title="std::string{}.insert(3, &quot;ABCDE&quot;, 0, 1) is ambiguous (Status: Resolved)">2757</a><sup><a href="https://cplusplus.github.io/LWG/issue2757" title="Latest snapshot">(i)</a></sup> to Tentatively Resolved</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to N4606.</p>

<ol>
<li><p>In 27.4.3 <a href="https://wg21.link/basic.string">[basic.string]</a> modify the synopsis for <code>basic_string</code> as follows:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class charT, class traits = char_traits&lt;charT&gt;,
    class Allocator = allocator&lt;charT&gt;&gt;
  class basic_string {
  public:
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; append(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; assign(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; insert(size_type pos1, <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos2, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; replace(size_type pos1, size_type n1,
                          <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                          size_type pos2, size_type n2 = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    int compare(size_type pos1, size_type n1,
                <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                size_type pos2, size_type n2 = npos) const;
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>In 27.4.3.7.2 <a href="https://wg21.link/string.append">[string.append]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; append(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos, size_type n = npos);
</pre>
<blockquote>
<p>
-7- <i>Throws:</i> <code>out_of_range</code> if <code>pos &gt; sv.size()</code>.
<p/>
-8- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length 
<code>rlen</code> of the string to append as the smaller of <code>n</code> and <code>sv.size() - pos</code> 
and calls <code>append(sv.data() + pos, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>.</ins>
<p/>
-9- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; assign(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos, size_type n = npos);
</pre>
<blockquote>
<p>
-9- <i>Throws:</i> <code>out_of_range</code> if <code>pos &gt; sv.size()</code>.
<p/>
-10- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length 
<code>rlen</code> of the string to assign as the smaller of <code>n</code> and <code>sv.size() - pos</code> 
and calls <code>assign(sv.data() + pos, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>.</ins>
<p/>
-11- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.4 <a href="https://wg21.link/string.insert">[string.insert]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; insert(size_type pos1, <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos2, size_type n = npos);
</pre>
<blockquote>
<p>
-6- <i>Throws:</i> <code>out_of_range</code> if <code>pos1 &gt; size()</code> or <code>pos2 &gt; sv.size()</code>.
<p/>
-7- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length <code>rlen</code> 
of the string to assign as the smaller of <code>n</code> and <code>sv.size() - pos2</code> and calls 
<code>insert(pos1, sv.data() + pos2, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>.</ins>
<p/>
-8- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.6 <a href="https://wg21.link/string.replace">[string.replace]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; replace(size_type pos1, size_type n1, 
                     <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos2, size_type n2 = npos);
</pre>
<blockquote>
<p>
-6- <i>Throws:</i> <code>out_of_range</code> if <code>pos1 &gt; size()</code> or <code>pos2 &gt; sv.size()</code>.
<p/>
-7- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length <code>rlen</code> 
of the string to be inserted as the smaller of <code>n2</code> and <code>sv.size() - pos2</code> and calls 
<code>replace(pos1, n1, sv.data() + pos2, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>.</ins>
<p/>
-8- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.8.4 <a href="https://wg21.link/string.compare">[string.compare]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
int compare(size_type pos1, size_type n1,
            <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
            size_type pos2, size_type n2 = npos) const;
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Equivalent to:
</p>
<blockquote><pre>
<ins>{</ins>
  <ins>basic_string_view&lt;charT, traits&gt; sv = t;</ins>
  return basic_string_view&lt;charT, traits&gt;(this.data(), pos1, n1).compare(sv, pos2, n2);
<ins>}</ins>
</pre></blockquote>
<p>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>


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

<ol>
<li><p>In 27.4.3 <a href="https://wg21.link/basic.string">[basic.string]</a> modify the synopsis for <code>basic_string</code> as follows:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class charT, class traits = char_traits&lt;charT&gt;,
    class Allocator = allocator&lt;charT&gt;&gt;
  class basic_string {
  public:
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; append(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; assign(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; insert(size_type pos1, <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                         size_type pos2, size_type n = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    basic_string&amp; replace(size_type pos1, size_type n1,
                          <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                          size_type pos2, size_type n2 = npos);
    [&hellip;]
    <ins>template&lt;class T&gt;</ins>
    int compare(size_type pos1, size_type n1,
                <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                size_type pos2, size_type n2 = npos) const;
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>In 27.4.3.7.2 <a href="https://wg21.link/string.append">[string.append]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; append(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos, size_type n = npos);
</pre>
<blockquote>
<p>
-7- <i>Throws:</i> <code>out_of_range</code> if <code>pos &gt; sv.size()</code>.
<p/>
-8- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length 
<code>rlen</code> of the string to append as the smaller of <code>n</code> and <code>sv.size() - pos</code> 
and calls <code>append(sv.data() + pos, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>
and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code>.</ins>
<p/>
-9- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; assign(<del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos, size_type n = npos);
</pre>
<blockquote>
<p>
-9- <i>Throws:</i> <code>out_of_range</code> if <code>pos &gt; sv.size()</code>.
<p/>
-10- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length 
<code>rlen</code> of the string to assign as the smaller of <code>n</code> and <code>sv.size() - pos</code> 
and calls <code>assign(sv.data() + pos, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>
and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code>.</ins>
<p/>
-11- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.4 <a href="https://wg21.link/string.insert">[string.insert]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; insert(size_type pos1, <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos2, size_type n = npos);
</pre>
<blockquote>
<p>
-6- <i>Throws:</i> <code>out_of_range</code> if <code>pos1 &gt; size()</code> or <code>pos2 &gt; sv.size()</code>.
<p/>
-7- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length <code>rlen</code> 
of the string to assign as the smaller of <code>n</code> and <code>sv.size() - pos2</code> and calls 
<code>insert(pos1, sv.data() + pos2, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>
and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code>.</ins>
<p/>
-8- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.6 <a href="https://wg21.link/string.replace">[string.replace]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
basic_string&amp; replace(size_type pos1, size_type n1, 
                     <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
                     size_type pos2, size_type n2 = npos);
</pre>
<blockquote>
<p>
-6- <i>Throws:</i> <code>out_of_range</code> if <code>pos1 &gt; size()</code> or <code>pos2 &gt; sv.size()</code>.
<p/>
-7- <i>Effects:</i> <ins>Creates a variable, <code>sv</code>, as if by 
<code>basic_string_view&lt;charT, traits&gt; sv = t</code>.</ins> Determines the effective length <code>rlen</code> 
of the string to be inserted as the smaller of <code>n2</code> and <code>sv.size() - pos2</code> and calls 
<code>replace(pos1, n1, sv.data() + pos2, rlen)</code>.
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>
and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code>.</ins>
<p/>
-8- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.8.4 <a href="https://wg21.link/string.compare">[string.compare]</a>, modify <code>basic_string_view</code> overload as follows:</p>

<blockquote class="note">
<p>
[<i>Drafting note</i>: The wording changes below are for the same part of the standard as <a href="lwg-defects.html#2771" title="Broken Effects of some basic_string::compare functions in terms of basic_string_view (Status: C++17)">2771</a><sup><a href="https://cplusplus.github.io/LWG/issue2771" title="Latest snapshot">(i)</a></sup>. 
However, they do not conflict. This one changes the definition of the routine, while the other changes the "Effects".
&mdash; <i>end drafting note</i>]
</p>
</blockquote>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
int compare(size_type pos1, size_type n1,
            <del>basic_string_view&lt;charT, traits&gt; sv</del><ins>const T&amp; t</ins>,
            size_type pos2, size_type n2 = npos) const;
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Equivalent to:
</p>
<blockquote><pre>
<ins>{</ins>
  <ins>basic_string_view&lt;charT, traits&gt; sv = t;</ins>
  return basic_string_view&lt;charT, traits&gt;(this.data(), pos1, n1).compare(sv, pos2, n2);
<ins>}</ins>
</pre></blockquote>
<p>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless
<code>is_convertible_v&lt;const T&amp;, basic_string_view&lt;charT, traits&gt;&gt;</code> is <code>true</code>
and <code>is_convertible_v&lt;const T&amp;, const charT*&gt;</code> is <code>false</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
