Add std::string constructor for substring of string_view (LWG 2742)
* doc/xml/manual/intro.xml: Document LWG 2742 status. * doc/html/*: Regenerate. * include/bits/basic_string.h (basic_string(const T&, size_type, size_type, const Allocator&)): Add constructor for substring of basic_string_view, as per LWG 2742 but with additional constraint to fix ambiguity. * testsuite/21_strings/basic_string/cons/char/9.cc: New test. * testsuite/21_strings/basic_string/cons/wchar_t/9.cc: New test. From-SVN: r242416
This commit is contained in:
parent
8b99f005cb
commit
bf56b0b838
|
@ -1,5 +1,14 @@
|
|||
2016-11-15 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* doc/xml/manual/intro.xml: Document LWG 2742 status.
|
||||
* doc/html/*: Regenerate.
|
||||
* include/bits/basic_string.h
|
||||
(basic_string(const T&, size_type, size_type, const Allocator&)): Add
|
||||
constructor for substring of basic_string_view, as per LWG 2742 but
|
||||
with additional constraint to fix ambiguity.
|
||||
* testsuite/21_strings/basic_string/cons/char/9.cc: New test.
|
||||
* testsuite/21_strings/basic_string/cons/wchar_t/9.cc: New test.
|
||||
|
||||
* doc/xml/manual/intro.xml: Document LWG 2748 status.
|
||||
* include/std/optional (optional<T>::swap): Use is_nothrow_swappable_v
|
||||
for exception specification.
|
||||
|
|
|
@ -496,11 +496,21 @@
|
|||
</span></dt><dd><p>Avoid using <code class="code">dynamic_cast</code> when it would be
|
||||
ill-formed.
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2583" target="_top">2583</a>:
|
||||
<span class="emphasis"><em>There is no way to supply an allocator for <code class="code"> basic_string(str, pos)</code>
|
||||
<span class="emphasis"><em>There is no way to supply an allocator for <code class="code">basic_string(str, pos)</code>
|
||||
</em></span>
|
||||
</span></dt><dd><p>Add new constructor
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2684" target="_top">2684</a>:
|
||||
<span class="emphasis"><em><code class="code">priority_queue</code> lacking comparator typedef
|
||||
</em></span>
|
||||
</span></dt><dd><p>Define the <code class="code">value_compare</code> typedef.
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2742" target="_top">2742</a>:
|
||||
<span class="emphasis"><em>Inconsistent <code class="code">string</code> interface taking <code class="code">string_view</code>
|
||||
</em></span>
|
||||
</span></dt><dd><p>Add the new constructor and additionally constrain it
|
||||
to avoid ambiguities with non-const <code class="code">charT*</code>.
|
||||
</p></dd><dt><span class="term"><a class="link" href="../ext/lwg-defects.html#2748" target="_top">2748</a>:
|
||||
<span class="emphasis"><em>swappable traits for optionals
|
||||
</em></span>
|
||||
</span></dt><dd><p>Disable the non-member <code class="code">swap</code> overload when
|
||||
the contained object is not swappable.
|
||||
</p></dd></dl></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="license.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="status.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="setup.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">License </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. Setup</td></tr></table></div></body></html>
|
|
@ -1107,6 +1107,14 @@ requirements of the license of GCC.
|
|||
<listitem><para>Define the <code>value_compare</code> typedef.
|
||||
</para></listitem></varlistentry>
|
||||
|
||||
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2742">2742</link>:
|
||||
<emphasis>Inconsistent <code>string</code> interface taking <code>string_view</code>
|
||||
</emphasis>
|
||||
</term>
|
||||
<listitem><para>Add the new constructor and additionally constrain it
|
||||
to avoid ambiguities with non-const <code>charT*</code>.
|
||||
</para></listitem></varlistentry>
|
||||
|
||||
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2748">2748</link>:
|
||||
<emphasis>swappable traits for optionals
|
||||
</emphasis>
|
||||
|
|
|
@ -585,13 +585,28 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
|||
{ _M_construct(__beg, __end); }
|
||||
|
||||
#if __cplusplus > 201402L
|
||||
/**
|
||||
* @brief Construct string from a substring of a string_view.
|
||||
* @param __t Source string view.
|
||||
* @param __pos The index of the first character to copy from __t.
|
||||
* @param __n The number of characters to copy from __t.
|
||||
* @param __a Allocator to use.
|
||||
*/
|
||||
template<typename _Tp, typename =
|
||||
_Require<is_convertible<_Tp, __sv_type>,
|
||||
__not_<is_convertible<const _Tp&, const _CharT*>>>>
|
||||
basic_string(const _Tp& __t, size_type __pos, size_type __n,
|
||||
const _Alloc& __a = _Alloc())
|
||||
: basic_string(__sv_type(__t).substr(__pos, __n), __a) { }
|
||||
|
||||
/**
|
||||
* @brief Construct string from a string_view.
|
||||
* @param __sv Source string view.
|
||||
* @param __a Allocator to use (default is default allocator).
|
||||
*/
|
||||
explicit basic_string(__sv_type __sv, const _Alloc& __a = _Alloc())
|
||||
: basic_string(__sv.data(), __sv.size(), __a) {}
|
||||
explicit
|
||||
basic_string(__sv_type __sv, const _Alloc& __a = _Alloc())
|
||||
: basic_string(__sv.data(), __sv.size(), __a) { }
|
||||
#endif // C++17
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do run { target c++1z } }
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
using C = char;
|
||||
using string_type = std::basic_string<C>;
|
||||
using view_type = std::basic_string_view<C>;
|
||||
|
||||
std::allocator<C> alloc;
|
||||
VERIFY( string_type(view_type("string")) == "string" );
|
||||
VERIFY( string_type(view_type("string"), alloc) == "string" );
|
||||
|
||||
// LWG 2742
|
||||
VERIFY( string_type("substring", 3, 6) == "string" );
|
||||
VERIFY( string_type("substring", 3, 6, alloc) == "string" );
|
||||
VERIFY( string_type(view_type("substring"), 3, 6) == "string" );
|
||||
VERIFY( string_type(view_type("substring"), 3, 6, alloc) == "string" );
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
// { dg-do run { target c++1z } }
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
using C = wchar_t;
|
||||
using string_type = std::basic_string<C>;
|
||||
using view_type = std::basic_string_view<C>;
|
||||
|
||||
std::allocator<C> alloc;
|
||||
VERIFY( string_type(view_type(L"string")) == L"string" );
|
||||
VERIFY( string_type(view_type(L"string"), alloc) == L"string" );
|
||||
|
||||
// LWG 2742
|
||||
VERIFY( string_type(L"substring", 3, 6) == L"string" );
|
||||
VERIFY( string_type(L"substring", 3, 6, alloc) == L"string" );
|
||||
VERIFY( string_type(view_type(L"substring"), 3, 6) == L"string" );
|
||||
VERIFY( string_type(view_type(L"substring"), 3, 6, alloc) == L"string" );
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
Loading…
Reference in New Issue