std::basic_...f::operator=(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

okay so this page is std::basic_...f::operator=(3), straight from the C++ Standard Libary manual, and it's all about std::basic_stringbuf::operator=. The name line is literally std::basic_stringbuf::operator= β€” std::basic_stringbuf::operator=. It's the assignment operator for std::basic_stringbuf, and it's giving β€œmove it, but don't copy it” energy πŸ’…βœ¨


✨ Synopsis ✨

two overloads, bestie. one is the move assignment (since C++11), and the other is deleted. here's the exact shape:

std::basic_stringbuf& operator=( std::basic_stringbuf&& rhs );
(1) (since C++11)
std::basic_stringbuf& operator=( const std::basic_stringbuf& rhs )
(2)
= delete;
  1. Move assignment operator: moves the contents of rhs into *this. After the move, *this has the associated string, the open mode, the locale, and all other state formerly held by rhs. The six pointers of std::basic_streambuf in *this are guaranteed to be different from the corresponding pointers in the moved-from rhs unless null. no cap, that's the whole guarantee 🫢
  2. The copy assignment operator is deleted; basic_stringbuf is not CopyAssignable. copying is not invited to the function, bestie πŸ’€

πŸŽ€ Parameters πŸŽ€

  • rhs β€” another basic_stringbuf that will be moved from. that's the whole param list, and yes it's doing exactly what it says on the tin πŸŽ€

πŸ’– Return value πŸ’–

*this. that's it. iconic behavior, honestly πŸ‘‘


🧚 Example 🧚

there's a little // Run this code vibe in the original, so here's the exact code:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::istringstream one("one");
    std::ostringstream two("two");

    std::cout << "Before move, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";

    *one.rdbuf() = std::move(*two.rdbuf());

    std::cout << "After move, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";
}

Output:

Before move, one = "one" two = "two"
After move, one = "two" two = ""

the way that move just ate and left two empty β€” we love to see it ✨


πŸ‘€ See also πŸ‘€

  • constructor β€” constructs a basic_stringbuf object (public member function). lowkey the prequel, and we're obsessed πŸ¦‹

πŸ’– source: http://cppreference.com Β· version/date: 2024.06.10 Β· page footer: std::basic_...f::operator=(3) β€” bye bestie, mwah! 🫢✨

πŸ“¦ where this page comes from