diff mbox

Add std::string constructor for substring of string_view (LWG 2742)

Message ID 20161115193246.GM3145@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Nov. 15, 2016, 7:32 p.m. UTC
On 15/11/16 14:33 +0000, Jonathan Wakely wrote:
>This is another issue resolution for C++17 features that was approved

>at the recent meeting. I think this resolution is wrong too, but in

>this case the fix is obvious so I've gone ahead and done it.

>

>	* 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.

>

>Tested powerpc64le-linux, comitted to trunk.


I forgot I already added an convenience alias template for checking
the condition in this patch.

Tested powerpc64le-linux, comitted to trunk.
diff mbox

Patch

commit f7852de7c77f0d9cc8520d10549da0652e334dc7
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 15 18:55:35 2016 +0000

    Use existing helper for new std::string constructor
    
    	* include/bits/basic_string.h: Reuse _If_sv alias template for new
    	constructor.

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 943e88d..9af7bfb 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -585,6 +585,12 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	{ _M_construct(__beg, __end); }
 
 #if __cplusplus > 201402L
+      template<typename _Tp, typename _Res>
+	using _If_sv = enable_if_t<
+	  __and_<is_convertible<const _Tp&, __sv_type>,
+		 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
+	  _Res>;
+
       /**
        *  @brief  Construct string from a substring of a string_view.
        *  @param  __t   Source string view.
@@ -592,9 +598,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        *  @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*>>>>
+      template<typename _Tp, typename = _If_sv<_Tp, void>>
 	basic_string(const _Tp& __t, size_type __pos, size_type __n,
 		     const _Alloc& __a = _Alloc())
 	: basic_string(__sv_type(__t).substr(__pos, __n), __a) { }
@@ -1252,12 +1256,6 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       append(__sv_type __sv)
       { return this->append(__sv.data(), __sv.size()); }
 
-      template<typename _Tp, typename _Res>
-	using _If_sv = enable_if_t<
-	  __and_<is_convertible<const _Tp&, __sv_type>,
-		 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
-	  _Res>;
-
       /**
        *  @brief  Append a range of characters from a string_view.
        *  @param __sv  The string_view to be appended from.