Index: include/algorithm =================================================================== --- include/algorithm +++ include/algorithm @@ -1687,26 +1687,7 @@ } // copy - template -struct __libcpp_is_trivial_iterator -{ - static const bool value = is_pointer<_Iter>::value; -}; - -template -struct __libcpp_is_trivial_iterator > -{ - static const bool value = is_pointer<_Iter>::value; -}; - -template -struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > -{ - static const bool value = is_pointer<_Iter>::value; -}; - -template inline _LIBCPP_INLINE_VISIBILITY _Iter __unwrap_iter(_Iter __i) Index: include/iterator =================================================================== --- include/iterator +++ include/iterator @@ -437,6 +437,10 @@ template struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; +template +struct __is_exactly_input_iterator + : integral_constant::iterator_category, input_iterator_tag>::value> {}; + template struct _LIBCPP_TYPE_VIS_ONLY iterator @@ -1404,6 +1408,23 @@ return __x; } +template +struct __libcpp_is_trivial_iterator + : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; + +template +struct __libcpp_is_trivial_iterator > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + +template +struct __libcpp_is_trivial_iterator > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + +template +struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp* Index: include/string =================================================================== --- include/string +++ include/string @@ -1201,6 +1201,24 @@ #pragma warning( pop ) #endif // _LIBCPP_MSVC +#ifdef _LIBCPP_HAS_NO_NOEXCEPT +struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(false) {}; +#else +template +struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( + __is_forward_iterator<_Iter>::value && +// noexcept(declval<_Iter>().operator++()) && +// noexcept(++(declval<_Iter>())) && + noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(*declval<_Iter>()) +)) {}; +#endif + + +template +struct __libcpp_string_gets_noexcept_iterator + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {}; + #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template @@ -1535,15 +1553,16 @@ template typename enable_if < - __is_input_iterator <_InputIterator>::value && - !__is_forward_iterator<_InputIterator>::value, + __is_exactly_input_iterator<_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, basic_string& >::type assign(_InputIterator __first, _InputIterator __last); template typename enable_if < - __is_forward_iterator<_ForwardIterator>::value, + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string& >::type assign(_ForwardIterator __first, _ForwardIterator __last); @@ -2494,15 +2513,15 @@ template typename enable_if < - __is_input_iterator <_InputIterator>::value && - !__is_forward_iterator<_InputIterator>::value, + __is_exactly_input_iterator <_InputIterator>::value + || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { - clear(); - for (; __first != __last; ++__first) - push_back(*__first); + call_input(); + basic_string temp(__first, __last); + this->swap(temp); return *this; } @@ -2510,11 +2529,13 @@ template typename enable_if < - __is_forward_iterator<_ForwardIterator>::value, + __is_forward_iterator<_ForwardIterator>::value + && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) { + call_forward(); size_type __n = static_cast(_VSTD::distance(__first, __last)); size_type __cap = capacity(); if (__cap < __n)