std::basic_stringbuf<CharT,Traits,Allocator>::swap - cppreference.com (original) (raw)

| void swap( basic_stringbuf& rhs ); | | (since C++11) (until C++20) | | --------------------------------------------------------------- | | --------------------------- | | void swap( basic_stringbuf& rhs ) noexcept(/* see below */); | | (since C++20) |

Swaps the state and the contents of *this and rhs.

The behavior is undefined if Allocator does not propagate on swap and the allocators of *this and other are unequal. (since C++11)

[edit] Parameters

rhs - another basic_stringbuf

[edit] Return value

(none)

[edit] Exceptions

[edit] Notes

This function is called automatically when swapping std::stringstream objects. It is rarely necessary to call it directly.

[edit] Example

Output:

Before swap: one = "one", two = "two". After swap: one = "two", two = "one".

[edit] See also

| | constructs a basic_stringbuf object (public member function) [edit] | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | swaps two string streams (public member function of std::basic_stringstream<CharT,Traits,Allocator>) [edit] |