From 68a51b68bd6c04b937bd1283279cd1203d0e4a16 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Thu, 11 Aug 2016 17:45:23 +0300 Subject: [PATCH] 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. From-SVN: r239370 --- libstdc++-v3/ChangeLog | 15 ++++++ libstdc++-v3/include/bits/basic_string.h | 30 ++++++++++-- .../21_strings/basic_string/lwg2758.cc | 46 +++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c676d03843c..def5c2960e5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2016-08-11 Ville Voutilainen + + 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 * doc/xml/manual/status_cxx2017.xml: Update status table. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 59f1c64ea35..89e210062f6 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -1227,9 +1227,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __n The number of characters to append from the string_view. * @return Reference to this string. */ - basic_string& append(__sv_type __sv, + template , + 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)); @@ -1392,10 +1396,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __n The number of characters to assign. * @return Reference to this string. */ + template , + 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)); @@ -1652,9 +1660,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __n The number of characters to insert. * @return Reference to this string. */ - basic_string& insert(size_type __pos1, __sv_type __sv, + template , + 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)); @@ -2071,10 +2083,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __n2 The number of characters to insert. * @return Reference to this string. */ + template , + 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)); @@ -2720,10 +2736,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __n2 The number of characters to compare. * @return Integer < 0, 0, or > 0. */ + template , + 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)); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc new file mode 100644 index 00000000000..1d292482014 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc @@ -0,0 +1,46 @@ +// { 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 +// . + +#include + +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); +} -- 2.30.2