<html><head>
<title>Literal suffixes for basic_string_view</title>
  <style type='text/css'>
  body {font-variant-ligatures: none;}
  p {text-align:justify}
  li {text-align:justify}
  blockquote.note, div.note
  {
          background-color:#E0E0E0;
          padding-left: 15px;
          padding-right: 15px;
          padding-top: 1px;
          padding-bottom: 1px;
  }
  p code {color:navy}
  blockquote code {color:inherit}
  ins {color:#00A000}
  del {color:#A00000}
  table#boilerplate { border:0 }
  table#boilerplate td { padding-left: 2em }
  table.bordered, table.bordered th, table.bordered td {
    border: 1px solid;
    text-align: center;
  }
  ins.block {color:#00A000; text-decoration: none}
  del.block {color:#A00000; text-decoration: none}
  </style>
</head><body>
<table id="boilerplate">
<tr><td>Document number</td><td>P0403R0</td></tr>
<tr><td>Date</td><td>2016-09-13</td></tr>
<tr><td>Project</td><td>Programming Language C++, Library Evolution Working Group</td></tr>
<tr><td>Reply-to</td><td>Marshall Clow &lt;mclow.lists&#x40;gmail.com&gt;</td></tr>
</table><hr>
<h1>Literal suffixes for basic_string_view</h1>
<h2>Introduction</h2>

<p>When we adopted <code>basic_string_view</code> into the standard library from the Library Fundamentals TS, we did not define any literal suffixes for the type.</p>

<p>We adopted the <code>""s</code> suffix for <code>basic_string</code> to make it easy to declare <code>string</code> variables. We should do the same for <code>basic_string_view</code>.  This would make declaring a <code>string_view</code> from a constant string simple:</p>

<pre><code>std::string_view sv = "ABCD"sv;
</code></pre>

<p>These operators should be constexpr, since the constructors for <code>string_view</code> are constexpr.</p>

<h2>Bikeshedding</h2>

<p>In this paper, I am assuming that we will use the literal suffix <code>""sv</code> for this feature. Of course, this is subject to bikeshedding.</p>

<h2>Wording</h2>

<p>This is relative to N4606:</p>

<p>Add to the end of section [string.view.synop] (after "hash support")</p>

<p><ins class="block">
    inline namespace literals {
    inline namespace string_literals {</p>

<pre><code>// 21.4.X, _suffix for basic\_string\_view literals:_

constexpr string_view    operator "" sv(const char* str, size_t len) noexcept;
constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept;
constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept;
constexpr wstring_view   operator "" sv(const wchar_t* str, size_t len) noexcept;
}}
</code></pre>

<p></ins></p>

<p>Add a new section after [string.view.hash]:</p>

<p><em>[ Note to the editor: The structure here is identical to [basic.string.literals] ]</em></p>

<p>21.4.X Suffix for basic_string_view literals     [basic.string_view.literals]</p>

<p><code>constexpr string_view operator "" sv(const char* str, size_t len) noexcept;</code></p>

<ol type="a">
<li>  <em>Returns:</em> <code>string_view{str, len}</code>.</li>
</ol>


<p><code>constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept;</code></p>

<ol type="a">
<li>  <em>Returns:</em> <code>u16string_view{str, len}</code>.</li>
</ol>


<p><code>constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept;</code></p>

<ol type="a">
<li>  <em>Returns:</em> <code>u32string_view{str, len}</code>.</li>
</ol>


<p><code>constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept;</code></p>

<ol type="a">
<li> <em>Returns:</em> <code>wstring_view{str, len}</code>.</li>
</ol>

</body></html>
