summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/string
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-05-26 18:52:49 +0000
committerdim <dim@FreeBSD.org>2016-05-26 18:52:49 +0000
commit6a450d405601a2fe1ac4163596a9f1f097938a67 (patch)
tree87163f0ca4abe85acc120b605dcfa6b9c46b29cd /contrib/libc++/include/string
parent934ebc933e3692b4690e2a19f92d402a4d7ac84a (diff)
parentfb2ca4532fddc71eec8c0229d53a0b1de52d5af8 (diff)
downloadFreeBSD-src-6a450d405601a2fe1ac4163596a9f1f097938a67.zip
FreeBSD-src-6a450d405601a2fe1ac4163596a9f1f097938a67.tar.gz
Update libc++ to 3.8.0. Excerpted list of fixes (with upstream revision
numbers): r242679 Implement the plugin-based version of std::search. There are no searchers yet; those are coming soon. r242682 Implement the default searcher for std::experimental::search. r243728 Add <experimental/any> v2. r245330 implement more of N4258 - Cleaning up noexcept in the standard library. Specifically add new noexcept stuff to vector and string's move-assignment operations r245334 Fix PR22606 - Leak pthread_key with static storage duration to ensure all of thread-local destructors are called. r245335 Fix PR23589: std::function doesn't recognize null pointer to varargs function. r247036 Implementation of Boyer-Moore and Boyer-Moore-Horspool searchers for the LFTS. r249325 Implement LWG#2063, and update the issues links to point to the github generated pages r249738 Split <ctype.h> out of <cctype>. r249739 Split <errno.h> out of <cerrno>. r249740 Split <float.h> out of <cfloat>. r249741 Split <inttypes.h> out of <cinttypes>. r249742 Split <math.h> out of <cmath>. r249743 Split <setjmp.h> out of <csetjmp>. r249761 Split <stddef.h> out of <cstddef>. r249798 Split <stdio.h> out of <cstdio>. r249800 Split <stdlib.h> out of <cstdlib>. r249889 Split <wchar.h> out of <cwchar>. r249890 Split <wctype.h> out of <cwctype>. r249929 Split <string.h> out of <cstring>. r250254 ABI versioning macros for libc++. r251246 Fix LWG#2244: basic_istream::seekg r251247 Fix LWG#2127: Move-construction with raw_storage_iterator. r251253 Fix LWG#2476: scoped_allocator_adaptor is not assignable r251257 Fix LWG#2489: mem_fn() should be noexcept r251618 Implement P0004R1 'Remove Deprecated iostreams aliases' r251766 Implement the first part of P0006R0: Adopt Type Traits Variable Templates for C++17. r252195 Implement P0092R1 for C++1z r252350 Allow deque to handle incomplete types. r252406 More of P0006R0: type traits variable aliases for C++17. r252407 Implement LWG#2353: std::next is over-constrained r252905 Implement P0074: Making owner_less more flexible r253215 Implement P0013R1: Logical Operator Type Traits. r253274 Implement P0007: Constant View: A proposal for a std::as_const helper function template. r254119 Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. r254283 Implement more of P0006; Type Traits Variable Templates. r255941 LWG2485: get() should be overloaded for const tuple&&. r256325 Fix LWG Issue #2367 - Fixing std::tuple and std::pair's default constructors. r256652 Fix for ALL undefined behavior in <list>. r256859 First half of LWG#2354: 'Unnecessary copying when inserting into maps with braced-init syntax' Exp-run: antoine Relnotes: yes
Diffstat (limited to 'contrib/libc++/include/string')
-rw-r--r--contrib/libc++/include/string213
1 files changed, 125 insertions, 88 deletions
diff --git a/contrib/libc++/include/string b/contrib/libc++/include/string
index 6e63ab1..9150244 100644
--- a/contrib/libc++/include/string
+++ b/contrib/libc++/include/string
@@ -115,8 +115,8 @@ public:
basic_string& operator=(const basic_string& str);
basic_string& operator=(basic_string&& str)
noexcept(
- allocator_type::propagate_on_container_move_assignment::value &&
- is_nothrow_move_assignable<allocator_type>::value);
+ allocator_type::propagate_on_container_move_assignment::value ||
+ allocator_type::is_always_equal::value ); // C++17
basic_string& operator=(const value_type* s);
basic_string& operator=(value_type c);
basic_string& operator=(initializer_list<value_type>);
@@ -517,10 +517,14 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits
{return __c1 < __c2;}
static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static size_t length(const char_type* __s);
+ _LIBCPP_INLINE_VISIBILITY
static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a);
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
@@ -550,7 +554,7 @@ char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_
}
template <class _CharT>
-inline _LIBCPP_INLINE_VISIBILITY
+inline
size_t
char_traits<_CharT>::length(const char_type* __s)
{
@@ -561,7 +565,7 @@ char_traits<_CharT>::length(const char_type* __s)
}
template <class _CharT>
-inline _LIBCPP_INLINE_VISIBILITY
+inline
const _CharT*
char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
{
@@ -595,7 +599,7 @@ char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
}
template <class _CharT>
-inline _LIBCPP_INLINE_VISIBILITY
+inline
_CharT*
char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -607,7 +611,7 @@ char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
}
template <class _CharT>
-inline _LIBCPP_INLINE_VISIBILITY
+inline
_CharT*
char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
{
@@ -726,11 +730,17 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
+ _LIBCPP_INLINE_VISIBILITY
static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static size_t length(const char_type* __s);
+ _LIBCPP_INLINE_VISIBILITY
static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a);
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
@@ -742,10 +752,10 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(0xDFFF);}
+ {return int_type(0xFFFF);}
};
-inline _LIBCPP_INLINE_VISIBILITY
+inline
int
char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -759,7 +769,7 @@ char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, siz
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
size_t
char_traits<char16_t>::length(const char_type* __s)
{
@@ -769,7 +779,7 @@ char_traits<char16_t>::length(const char_type* __s)
return __len;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
const char16_t*
char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
{
@@ -782,7 +792,7 @@ char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& _
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char16_t*
char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -802,7 +812,7 @@ char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
return __r;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char16_t*
char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -813,7 +823,7 @@ char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
return __r;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char16_t*
char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
{
@@ -839,11 +849,17 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
+ _LIBCPP_INLINE_VISIBILITY
static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static size_t length(const char_type* __s);
+ _LIBCPP_INLINE_VISIBILITY
static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
+ _LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a);
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
@@ -858,7 +874,7 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
{return int_type(0xFFFFFFFF);}
};
-inline _LIBCPP_INLINE_VISIBILITY
+inline
int
char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -872,7 +888,7 @@ char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, siz
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
size_t
char_traits<char32_t>::length(const char_type* __s)
{
@@ -882,7 +898,7 @@ char_traits<char32_t>::length(const char_type* __s)
return __len;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
const char32_t*
char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
{
@@ -895,7 +911,7 @@ char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& _
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char32_t*
char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -915,7 +931,7 @@ char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
return __r;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char32_t*
char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
{
@@ -926,7 +942,7 @@ char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
return __r;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline
char32_t*
char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
{
@@ -1185,7 +1201,31 @@ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
#pragma warning( pop )
#endif // _LIBCPP_MSVC
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_NO_EXCEPTIONS
+template <class _Iter>
+struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
+#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
+template <class _Iter>
+struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
+#else
+template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
+struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
+ noexcept(++(declval<_Iter&>())) &&
+ is_nothrow_assignable<_Iter&, _Iter>::value &&
+ noexcept(declval<_Iter>() == declval<_Iter>()) &&
+ noexcept(*declval<_Iter>())
+)) {};
+
+template <class _Iter>
+struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
+#endif
+
+
+template <class _Iter>
+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 <class _CharT, size_t = sizeof(_CharT)>
struct __padding
@@ -1198,7 +1238,7 @@ struct __padding<_CharT, 1>
{
};
-#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
template<class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TYPE_VIS_ONLY basic_string
@@ -1234,7 +1274,7 @@ public:
private:
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
struct __long
{
@@ -1294,7 +1334,7 @@ private:
value_type __data_[__min_cap];
};
-#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
union __ulx{__long __lx; __short __lxx;};
@@ -1377,8 +1417,7 @@ public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
basic_string& operator=(basic_string&& __str)
- _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
- is_nothrow_move_assignable<allocator_type>::value);
+ _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
#endif
_LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
basic_string& operator=(value_type __c);
@@ -1480,15 +1519,16 @@ public:
template<class _InputIterator>
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
append(_InputIterator __first, _InputIterator __last);
template<class _ForwardIterator>
typename enable_if
<
- __is_forward_iterator<_ForwardIterator>::value,
+ __is_forward_iterator<_ForwardIterator>::value
+ && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
basic_string&
>::type
append(_ForwardIterator __first, _ForwardIterator __last);
@@ -1510,6 +1550,7 @@ public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
basic_string& assign(basic_string&& str)
+ _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{*this = _VSTD::move(str); return *this;}
#endif
basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
@@ -1519,15 +1560,16 @@ public:
template<class _InputIterator>
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<class _ForwardIterator>
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);
@@ -1548,15 +1590,16 @@ public:
template<class _InputIterator>
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,
iterator
>::type
insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
template<class _ForwardIterator>
typename enable_if
<
- __is_forward_iterator<_ForwardIterator>::value,
+ __is_forward_iterator<_ForwardIterator>::value
+ && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
iterator
>::type
insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
@@ -1698,7 +1741,7 @@ private:
const allocator_type& __alloc() const _NOEXCEPT
{return __r_.second();}
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_short_size(size_type __s) _NOEXCEPT
@@ -1716,7 +1759,7 @@ private:
{return __r_.first().__s.__size_;}
# endif
-#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_short_size(size_type __s) _NOEXCEPT
@@ -1734,7 +1777,7 @@ private:
{return __r_.first().__s.__size_ >> 1;}
# endif
-#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_long_size(size_type __s) _NOEXCEPT
@@ -1801,8 +1844,7 @@ private:
template <class _InputIterator>
typename enable_if
<
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
+ __is_exactly_input_iterator<_InputIterator>::value,
void
>::type
__init(_InputIterator __first, _InputIterator __last);
@@ -1846,11 +1888,16 @@ private:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
- void __move_assign(basic_string& __str, false_type);
+ void __move_assign(basic_string& __str, false_type)
+ _NOEXCEPT_(__alloc_traits::is_always_equal::value);
_LIBCPP_INLINE_VISIBILITY
void __move_assign(basic_string& __str, true_type)
+#if _LIBCPP_STD_VER > 14
+ _NOEXCEPT;
+#else
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
#endif
+#endif
_LIBCPP_INLINE_VISIBILITY
void
@@ -2174,8 +2221,7 @@ template <class _CharT, class _Traits, class _Allocator>
template <class _InputIterator>
typename enable_if
<
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
+ __is_exactly_input_iterator<_InputIterator>::value,
void
>::type
basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
@@ -2431,6 +2477,7 @@ template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
+ _NOEXCEPT_(__alloc_traits::is_always_equal::value)
{
if (__alloc() != __str.__alloc())
assign(__str);
@@ -2442,7 +2489,11 @@ template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
+#if _LIBCPP_STD_VER > 14
+ _NOEXCEPT
+#else
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
+#endif
{
clear();
shrink_to_fit();
@@ -2455,8 +2506,7 @@ template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
- _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
- is_nothrow_move_assignable<allocator_type>::value)
+ _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{
__move_assign(__str, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());
@@ -2469,15 +2519,14 @@ template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
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);
+ basic_string __temp(__first, __last, __alloc());
+ assign(__temp.data(), __temp.size());
return *this;
}
@@ -2485,7 +2534,8 @@ template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
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)
@@ -2618,14 +2668,14 @@ template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
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>::append(_InputIterator __first, _InputIterator __last)
{
- for (; __first != __last; ++__first)
- push_back(*__first);
+ basic_string __temp (__first, __last, __alloc());
+ append(__temp.data(), __temp.size());
return *this;
}
@@ -2633,7 +2683,8 @@ template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
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>::append(_ForwardIterator __first, _ForwardIterator __last)
@@ -2749,9 +2800,9 @@ template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
typename enable_if
<
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
+ __is_exactly_input_iterator<_InputIterator>::value
+ || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+ typename basic_string<_CharT, _Traits, _Allocator>::iterator
>::type
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
{
@@ -2760,24 +2811,16 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIt
"string::insert(iterator, range) called with an iterator not"
" referring to this string");
#endif
- size_type __old_sz = size();
- difference_type __ip = __pos - begin();
- for (; __first != __last; ++__first)
- push_back(*__first);
- pointer __p = __get_pointer();
- _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
-#if _LIBCPP_DEBUG_LEVEL >= 2
- return iterator(this, __p + __ip);
-#else
- return iterator(__p + __ip);
-#endif
+ basic_string __temp(__first, __last, __alloc());
+ return insert(__pos, __temp.data(), __temp.data() + __temp.size());
}
template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
typename enable_if
<
- __is_forward_iterator<_ForwardIterator>::value,
+ __is_forward_iterator<_ForwardIterator>::value
+ && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
typename basic_string<_CharT, _Traits, _Allocator>::iterator
>::type
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
@@ -2980,22 +3023,8 @@ typename enable_if
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
_InputIterator __j1, _InputIterator __j2)
{
- for (; true; ++__i1, ++__j1)
- {
- if (__i1 == __i2)
- {
- if (__j1 != __j2)
- insert(__i1, __j1, __j2);
- break;
- }
- if (__j1 == __j2)
- {
- erase(__i1, __i2);
- break;
- }
- traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
- }
- return *this;
+ basic_string __temp(__j1, __j2, __alloc());
+ return this->replace(__i1, __i2, __temp);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -3788,7 +3817,11 @@ bool
operator==(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
- return __rhs.compare(__lhs) == 0;
+ typedef basic_string<_CharT, _Traits, _Allocator> _String;
+ _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
+ size_t __lhs_len = _Traits::length(__lhs);
+ if (__lhs_len != __rhs.size()) return false;
+ return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
}
template<class _CharT, class _Traits, class _Allocator>
@@ -3797,7 +3830,11 @@ bool
operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
- return __lhs.compare(__rhs) == 0;
+ typedef basic_string<_CharT, _Traits, _Allocator> _String;
+ _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
+ size_t __rhs_len = _Traits::length(__rhs);
+ if (__rhs_len != __lhs.size()) return false;
+ return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
}
// operator!=
OpenPOWER on IntegriCloud