+2016-08-11 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ Implement LWG 2758.
+ * include/bits/basic_string.h
+ (append(__sv_type, size_type, size_type)): Turn into a template,
+ change parameter type, constrain, add a conversion to __sv_type
+ from the dependent parameter type.
+ (assign(__sv_type, size_type, size_type)): Likewise.
+ (insert(size_type, __sv_type, size_type, size_type)): Likewise.
+ (replace(size_type, size_type, __sv_type, size_type, size_type)):
+ Likewise.
+ (compare(size_type, size_type,__sv_type, size_type, size_type)):
+ Likewise.
+ * testsuite/21_strings/basic_string/lwg2758.cc: New.
+
2016-08-06 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/manual/status_cxx2017.xml: Update status table.
* @param __n The number of characters to append from the string_view.
* @return Reference to this string.
*/
- basic_string& append(__sv_type __sv,
+ template <typename _Tp,
+ enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
+ bool> = true>
+ basic_string& append(const _Tp& __svt,
size_type __pos, size_type __n = npos)
{
+ __sv_type __sv = __svt;
return _M_append(__sv.data()
+ __sv._M_check(__pos, "basic_string::append"),
__sv._M_limit(__pos, __n));
* @param __n The number of characters to assign.
* @return Reference to this string.
*/
+ template <typename _Tp,
+ enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
+ bool> = true>
basic_string&
- assign(__sv_type __sv,
+ assign(const _Tp& __svt,
size_type __pos, size_type __n = npos)
{
+ __sv_type __sv = __svt;
return _M_replace(size_type(0), this->size(), __sv.data()
+ __sv._M_check(__pos, "basic_string::assign"),
__sv._M_limit(__pos, __n));
* @param __n The number of characters to insert.
* @return Reference to this string.
*/
- basic_string& insert(size_type __pos1, __sv_type __sv,
+ template <typename _Tp,
+ enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
+ bool> = true>
+ basic_string& insert(size_type __pos1, const _Tp& __svt,
size_type __pos2, size_type __n = npos)
{
+ __sv_type __sv = __svt;
return this->replace(__pos1, size_type(0), __sv.data()
+ __sv._M_check(__pos2, "basic_string::insert"),
__sv._M_limit(__pos2, __n));
* @param __n2 The number of characters to insert.
* @return Reference to this string.
*/
+ template <typename _Tp,
+ enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
+ bool> = true>
basic_string& replace(size_type __pos1, size_type __n1,
- __sv_type __sv,
+ const _Tp& __svt,
size_type __pos2, size_type __n2 = npos)
{
+ __sv_type __sv = __svt;
return this->replace(__pos1, __n1, __sv.data()
+ __sv._M_check(__pos2, "basic_string::replace"),
__sv._M_limit(__pos2, __n2));
* @param __n2 The number of characters to compare.
* @return Integer < 0, 0, or > 0.
*/
+ template <typename _Tp,
+ enable_if_t<is_convertible_v<const _Tp&, __sv_type>,
+ bool> = true>
int compare(size_type __pos1, size_type __n1,
- __sv_type __sv,
+ const _Tp& __svt,
size_type __pos2, size_type __n2 = npos) const
{
+ __sv_type __sv = __svt;
return __sv_type(*this)
.substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
}
--- /dev/null
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// 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/>.
+
+#include <string>
+
+struct CustomString
+{
+ std::string data = "foo";
+ std::string_view data_view = data;
+ operator std::string_view() const {return data_view;}
+};
+
+int main()
+{
+ std::string x;
+ CustomString cs;
+ x.append("foo", 0, 3);
+ x.append(cs, 0, 3);
+ x.assign("foo", 0, 3);
+ x.assign(cs, 0, 3);
+ x.insert(0, "foo", 0, 3);
+ x.insert(0, cs, 0, 3);
+ x = "bar";
+ x.replace(0, 3, "foo", 0, 3);
+ x.replace(0, 3, cs, 0, 3);
+ x = "bar";
+ x.compare(0, 3, "foo", 0, 3);
+ x.compare(0, 3, cs, 0, 3);
+}