@brief Exchanges the string contents witt the `other` string. */
| 2823 | |
| 2824 | /** @brief Exchanges the string contents witt the `other` string. */ |
| 2825 | void swap(basic_string &other) noexcept { |
| 2826 | // If at least one of the strings is on the stack, a basic `swap(string_, other.string_)` won't work, |
| 2827 | // as the pointer to the stack-allocated memory will be swapped, instead of the contents. |
| 2828 | sz_ptr_t first_start, second_start; |
| 2829 | sz_size_t first_length, second_length; |
| 2830 | sz_size_t first_space, second_space; |
| 2831 | sz_bool_t first_is_external, second_is_external; |
| 2832 | sz_string_unpack(&string_, &first_start, &first_length, &first_space, &first_is_external); |
| 2833 | sz_string_unpack(&other.string_, &second_start, &second_length, &second_space, &second_is_external); |
| 2834 | trivial_swap(string_, other.string_); |
| 2835 | if (!first_is_external) other.string_.internal.start = &other.string_.internal.chars[0]; |
| 2836 | if (!second_is_external) string_.internal.start = &string_.internal.chars[0]; |
| 2837 | } |
| 2838 | |
| 2839 | #if !SZ_AVOID_STL |
| 2840 |