@@ -109,6 +109,10 @@ public:
109
109
const allocator_type& a = allocator_type()); // constexpr since C++20
110
110
basic_string(const basic_string& str, size_type pos, size_type n,
111
111
const Allocator& a = Allocator()); // constexpr since C++20
112
+ constexpr basic_string(
113
+ basic_string&& str, size_type pos, const Allocator& a = Allocator()); // since C++23
114
+ constexpr basic_string(
115
+ basic_string&& str, size_type pos, size_type n, const Allocator& a = Allocator()); // since C++23
112
116
template<class T>
113
117
basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20
114
118
template <class T>
@@ -261,8 +265,9 @@ public:
261
265
basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20
262
266
263
267
size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20
264
- basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20
265
-
268
+ basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr in C++20, removed in C++23
269
+ basic_string substr(size_type pos = 0, size_type n = npos) const&; // since C++23
270
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; // since C++23
266
271
void swap(basic_string& str)
267
272
noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
268
273
allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20
@@ -897,6 +902,36 @@ public:
897
902
std::__debug_db_insert_c (this );
898
903
}
899
904
905
+ #if _LIBCPP_STD_VER > 20
906
+ _LIBCPP_HIDE_FROM_ABI constexpr
907
+ basic_string (basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator())
908
+ : basic_string(std::move(__str), __pos, npos, __alloc) {}
909
+
910
+ _LIBCPP_HIDE_FROM_ABI constexpr
911
+ basic_string (basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator())
912
+ : __r_(__default_init_tag(), __alloc) {
913
+ if (__pos > __str.size ())
914
+ __throw_out_of_range ();
915
+
916
+ auto __len = std::min<size_type>(__n, __str.size () - __pos);
917
+ if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc ()) {
918
+ __r_.first () = __str.__r_ .first ();
919
+ __str.__default_init ();
920
+
921
+ _Traits::move (data (), data () + __pos, __len);
922
+ __set_size (__len);
923
+ _Traits::assign (data ()[__len], value_type ());
924
+ } else {
925
+ // Perform a copy because the allocators are not compatible.
926
+ __init (__str.data () + __pos, __len);
927
+ }
928
+
929
+ std::__debug_db_insert_c (this );
930
+ if (__is_long ())
931
+ std::__debug_db_swap (this , &__str);
932
+ }
933
+ #endif
934
+
900
935
template <class = __enable_if_t <__is_allocator<_Allocator>::value, nullptr_t > >
901
936
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string (size_type __n, _CharT __c, const _Allocator& __a);
902
937
@@ -1324,8 +1359,24 @@ public:
1324
1359
#endif // _LIBCPP_CXX03_LANG
1325
1360
1326
1361
_LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy (value_type* __s, size_type __n, size_type __pos = 0 ) const ;
1362
+
1363
+ // TODO: Maybe don't pass in the allocator. See https://llvm.org/PR57190
1364
+ #if _LIBCPP_STD_VER <= 20
1327
1365
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1328
- basic_string substr (size_type __pos = 0 , size_type __n = npos) const ;
1366
+ basic_string substr (size_type __pos = 0 , size_type __n = npos) const {
1367
+ return basic_string (*this , __pos, __n, __alloc ());
1368
+ }
1369
+ #else
1370
+ _LIBCPP_HIDE_FROM_ABI constexpr
1371
+ basic_string substr (size_type __pos = 0 , size_type __n = npos) const & {
1372
+ return basic_string (*this , __pos, __n, __alloc ());
1373
+ }
1374
+
1375
+ _LIBCPP_HIDE_FROM_ABI constexpr
1376
+ basic_string substr (size_type __pos = 0 , size_type __n = npos) && {
1377
+ return basic_string (std::move (*this ), __pos, __n, __alloc ());
1378
+ }
1379
+ #endif
1329
1380
1330
1381
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1331
1382
void swap (basic_string& __str)
@@ -3472,14 +3523,6 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
3472
3523
return __rlen;
3473
3524
}
3474
3525
3475
- template <class _CharT , class _Traits , class _Allocator >
3476
- inline _LIBCPP_CONSTEXPR_SINCE_CXX20
3477
- basic_string<_CharT, _Traits, _Allocator>
3478
- basic_string<_CharT, _Traits, _Allocator>::substr (size_type __pos, size_type __n) const
3479
- {
3480
- return basic_string (*this , __pos, __n, __alloc ());
3481
- }
3482
-
3483
3526
template <class _CharT , class _Traits , class _Allocator >
3484
3527
inline _LIBCPP_CONSTEXPR_SINCE_CXX20
3485
3528
void
0 commit comments