diff --git a/libcxx/include/__string b/libcxx/include/__string --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -106,7 +106,6 @@ _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \ _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \ _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \ - _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \ _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \ _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \ _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \ @@ -122,6 +121,12 @@ _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \ _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type)) +#define _LIBCPP_V1_STRING_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ + _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) + +#define _LIBCPP_V2_STRING_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ + _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__erase_external(size_type, size_type)) + // char_traits diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1574,6 +1574,8 @@ _LIBCPP_INLINE_VISIBILITY void __erase_to_end(size_type __pos); + basic_string& __erase_external(size_type __pos, size_type __n); + _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str) {__copy_assign_alloc(__str, integral_constant basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::__erase_external(size_type __pos, size_type __n) { - size_type __sz = size(); - if (__pos > __sz) - this->__throw_out_of_range(); if (__n) { + size_type __sz = size(); value_type* __p = _VSTD::__to_address(__get_pointer()); __n = _VSTD::min(__n, __sz - __pos); size_type __n_move = __sz - __pos - __n; @@ -3019,6 +3021,19 @@ return *this; } +// Inline-able portion of the erase() implementation (unstable) +template +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, + size_type __n) { + if (__pos > size()) this->__throw_out_of_range(); + if (__n == npos) { + __erase_to_end(__pos); + return *this; + } + return __erase_external(__pos, __n); +} + template inline typename basic_string<_CharT, _Traits, _Allocator>::iterator @@ -4341,6 +4356,14 @@ _LIBCPP_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) _LIBCPP_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) +#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2 +_LIBCPP_V2_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) +_LIBCPP_V2_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) +#else +_LIBCPP_V1_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) +_LIBCPP_V1_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) +#endif + #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals diff --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp --- a/libcxx/src/string.cpp +++ b/libcxx/src/string.cpp @@ -23,6 +23,12 @@ _LIBCPP_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) _LIBCPP_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t) +_LIBCPP_V1_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) +_LIBCPP_V1_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t) + +_LIBCPP_V2_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) +_LIBCPP_V2_STRING_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t) + template string operator+, allocator >(char const*, string const&);