LWG 3075 basic_string needs deduction guides from basic_string_view
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Jun 2018 20:27:04 +0000 (21:27 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 14 Jun 2018 20:27:04 +0000 (21:27 +0100)
* testsuite/21_strings/basic_string/cons/char/deduction.cc: Test
deduction from string views.
* testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc:
Likewise.

From-SVN: r261612

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc
libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc

index 6db36225c1feae13253fcf63656238323d8b1015..e368044232f613de6ecf0d2200d38dba43d139e9 100644 (file)
@@ -1,5 +1,11 @@
 2018-06-14  Jonathan Wakely  <jwakely@redhat.com>
 
+       LWG 3075 basic_string needs deduction guides from basic_string_view
+       * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test
+       deduction from string views.
+       * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc:
+       Likewise.
+
        LWG 3074 make scalar types non-deduced in valarray non-member functions
        * include/bits/valarray_after.h (_DEFINE_EXPR_BINARY_FUNCTION): Change
        scalar parameters to be a non-deduced context.
index 5bffa1c72a12c6af9a34590cb48536ba2aa8779b..fbac38ae9736ae20ff704b9128fc73fbd683580c 100644 (file)
@@ -5873,6 +5873,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
           typename = _RequireAllocator<_Allocator>>
     basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
       -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
+
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3075. basic_string needs deduction guides from basic_string_view
+  template<typename _CharT, typename _Traits,
+          typename _Allocator = allocator<_CharT>,
+          typename = _RequireAllocator<_Allocator>>
+    basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
+      -> basic_string<_CharT, _Traits, _Allocator>;
+
+  template<typename _CharT, typename _Traits,
+          typename _Allocator = allocator<_CharT>,
+          typename = _RequireAllocator<_Allocator>>
+    basic_string(basic_string_view<_CharT, _Traits>,
+                typename basic_string<_CharT, _Traits, _Allocator>::size_type,
+                typename basic_string<_CharT, _Traits, _Allocator>::size_type,
+                const _Allocator& = _Allocator())
+      -> basic_string<_CharT, _Traits, _Allocator>;
 _GLIBCXX_END_NAMESPACE_CXX11
 #endif
 
index f7dee1e61417fc159af28548c719ff541668444a..cf6857c6678de27b1e23ab8ea60edf478f7ed802 100644 (file)
@@ -118,3 +118,23 @@ test04()
   std::basic_string s4((char32_t)1, U'a', std::allocator<char32_t>());
   check_type<std::u32string>(s4);
 }
+
+void
+test05()
+{
+  // LWG 3075 basic_string needs deduction guides from basic_string_view
+  std::string_view sv{"A View to a Kill"};
+  const std::allocator<char> a;
+
+  std::basic_string s1(sv);
+  check_type<std::string>(s1);
+
+  std::basic_string s2(sv, a);
+  check_type<std::string>(s2);
+
+  std::basic_string s3(sv, 2u, 6u);
+  check_type<std::string>(s3);
+
+  std::basic_string s4(sv, 2u, 6u, a);
+  check_type<std::string>(s4);
+}
index 7fe367b56dd54adc235e0a9107e8c3ea1e8e3d13..ea312ff653eb57b5501217e664197418a4b0974a 100644 (file)
@@ -77,3 +77,23 @@ test02()
   std::basic_string s4((wchar_t)1, L'a', std::allocator<wchar_t>());
   check_type<std::wstring>(s4);
 }
+
+void
+test05()
+{
+  // LWG 3075 basic_string needs deduction guides from basic_string_view
+  std::wstring_view sv{L"A View to a Kill"};
+  const std::allocator<wchar_t> a;
+
+  std::basic_string s1(sv);
+  check_type<std::wstring>(s1);
+
+  std::basic_string s2(sv, a);
+  check_type<std::wstring>(s2);
+
+  std::basic_string s3(sv, 2u, 6u);
+  check_type<std::wstring>(s3);
+
+  std::basic_string s4(sv, 2u, 6u, a);
+  check_type<std::wstring>(s4);
+}