Optimize filesystem::path by providing weaker exception guarantees.

path uses string::append to construct, append, and concatenate paths. Unfortunatly
string::append has a strong exception safety guaranteed and if it can't prove
that the iterator operations don't throw then it will allocate a temporary
string copy to append to. However this extra allocation and copy is very
undesirable for path which doesn't have the same exception guarantees.

To work around this this patch adds string::__append_forward_unsafe which exposes
the std::string::append interface for forward iterators without enforcing
that the iterator is noexcept.



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285532 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/string b/include/string
index b56ab38..95fbce0 100644
--- a/include/string
+++ b/include/string
@@ -926,6 +926,8 @@
     basic_string& append(const value_type* __s, size_type __n);
     basic_string& append(const value_type* __s);
     basic_string& append(size_type __n, value_type __c);
+    template <class _ForwardIterator>
+    basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
     template<class _InputIterator>
         typename enable_if
         <
@@ -933,7 +935,12 @@
                 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
             basic_string&
         >::type
-        append(_InputIterator __first, _InputIterator __last);
+    _LIBCPP_INLINE_VISIBILITY
+    append(_InputIterator __first, _InputIterator __last) {
+      const basic_string __temp (__first, __last, __alloc());
+      append(__temp.data(), __temp.size());
+      return *this;
+    }
     template<class _ForwardIterator>
         typename enable_if
         <
@@ -941,7 +948,11 @@
                 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
             basic_string&
         >::type
-        append(_ForwardIterator __first, _ForwardIterator __last);
+    _LIBCPP_INLINE_VISIBILITY
+    append(_ForwardIterator __first, _ForwardIterator __last) {
+      return __append_forward_unsafe(__first, __last);
+    }
+
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
     basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
@@ -2182,21 +2193,6 @@
     traits_type::assign(*++__p, value_type());
 }
 
-template <class _CharT, class _Traits, class _Allocator>
-template<class _InputIterator>
-typename enable_if
-<
-    __is_exactly_input_iterator<_InputIterator>::value
-             || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
-    basic_string<_CharT, _Traits, _Allocator>&
->::type
-basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
-{
-    const basic_string __temp (__first, __last, __alloc());
-    append(__temp.data(), __temp.size());
-    return *this;
-}
-
 template <class _Tp>
 bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
 {
@@ -2211,14 +2207,12 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _ForwardIterator>
-typename enable_if
-<
-    __is_forward_iterator<_ForwardIterator>::value
-          && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
-    basic_string<_CharT, _Traits, _Allocator>&
->::type
-basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
+    _ForwardIterator __first, _ForwardIterator __last)
 {
+    static_assert(__is_forward_iterator<_ForwardIterator>::value,
+                  "function requires a ForwardIterator");
     size_type __sz = size();
     size_type __cap = capacity();
     size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));