diff --git a/stl/inc/bitset b/stl/inc/bitset index b91f8a6eb38..2c438e7dc21 100644 --- a/stl/inc/bitset +++ b/stl/inc/bitset @@ -347,13 +347,13 @@ public: _NODISCARD _CONSTEXPR23 basic_string<_Elem, _Tr, _Alloc> to_string( const _Elem _Elem0 = static_cast<_Elem>('0'), const _Elem _Elem1 = static_cast<_Elem>('1')) const { // convert bitset to string - basic_string<_Elem, _Tr, _Alloc> _Str(_Bits, _Elem0); - for (size_t _Pos = 0; _Pos < _Bits; ++_Pos) { - if (_Subscript(_Bits - 1 - _Pos)) { - _Str[_Pos] = _Elem1; + basic_string<_Elem, _Tr, _Alloc> _Str; + _Str._Resize_and_overwrite(_Bits, [this, _Elem0, _Elem1](_Elem* _Buf, size_t _Len) { + for (size_t _Pos = 0; _Pos < _Len; ++_Pos) { + _Buf[_Pos] = _Subscript(_Len - 1 - _Pos) ? _Elem1 : _Elem0; } - } - + return _Len; + }); return _Str; } diff --git a/stl/inc/xstring b/stl/inc/xstring index 455e6ae8f12..adb18c1f429 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4158,11 +4158,16 @@ public: } } -#if _HAS_CXX23 #pragma warning(push) #pragma warning(disable : 4018) // '<=': signed/unsigned mismatch (we compare to 0 before _New_size below, so it's safe) template - constexpr void resize_and_overwrite(_CRT_GUARDOVERFLOW const size_type _New_size, _Operation _Op) { + constexpr void +#if _HAS_CXX23 + resize_and_overwrite +#else // ^^^ _HAS_CXX23 / !_HAS_CXX23 vvv + _Resize_and_overwrite +#endif // ^^^ !_HAS_CXX23 ^^^ + (_CRT_GUARDOVERFLOW const size_type _New_size, _Operation _Op) { if (_Mypair._Myval2._Myres < _New_size) { _Reallocate_grow_by(_New_size - _Mypair._Myval2._Mysize, [](_Elem* const _New_ptr, const _Elem* const _Old_ptr, const size_type _Old_size) { @@ -4180,6 +4185,12 @@ public: _Eos(static_cast(_Result_size)); } #pragma warning(pop) + +#if _HAS_CXX23 + template + constexpr void _Resize_and_overwrite(_CRT_GUARDOVERFLOW const size_type _New_size, _Operation _Op) { + resize_and_overwrite(_New_size, _Op); + } #endif // _HAS_CXX23 _NODISCARD _CONSTEXPR20 size_type capacity() const noexcept {