aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Voutilainen <ville.voutilainen@gmail.com>2016-08-11 17:45:23 +0300
committerVille Voutilainen <ville@gcc.gnu.org>2016-08-11 17:45:23 +0300
commit68a51b68bd6c04b937bd1283279cd1203d0e4a16 (patch)
tree25fbfc32a1ac472c3780e5c66a6ef0e9c4ad66b7
parent3f1b33737d6392133cdc0f86100d1d0df977a984 (diff)
downloadgcc-68a51b68bd6c04b937bd1283279cd1203d0e4a16.zip
gcc-68a51b68bd6c04b937bd1283279cd1203d0e4a16.tar.gz
gcc-68a51b68bd6c04b937bd1283279cd1203d0e4a16.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog15
-rw-r--r--libstdc++-v3/include/bits/basic_string.h30
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc46
3 files changed, 86 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c676d03..def5c29 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,18 @@
+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.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 59f1c64..89e2100 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 <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));
@@ -1392,10 +1396,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* @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));
@@ -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 <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));
@@ -2071,10 +2083,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* @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));
@@ -2720,10 +2736,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* @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));
}
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 0000000..1d29248
--- /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
+// <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);
+}