std::basic_...f::operator=(3)
π
std::basic_...f::operator=(3) π
okay bestie, welcome to the C++ Standard Libary manual page for std::basic_filebuf::operator= β yes, that's the assignment operator for basic_filebuf, and it's kind of a two-overload situation. One is a move-assignment slay, one is deleted. Let's get into it.
β¨ NAME β¨
std::basic_filebuf::operator= - std::basic_filebuf::operator=
πΈ Synopsis πΈ
std::basic_filebuf& operator=( std::basic_filebuf&& rhs );
(1) (since C++11)
std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) =
(2)
delete;
okay so this operator assigns another basic_filebuf object. The two overloads are doing very different things:
- This is the move-assignment one,
(1) (since C++11). First it callsclose()to close the associated file, then it moves the contents ofrhsinto*this: the put and get buffers, the associated file, the locale, the openmode, theis_openflag, and any other state. After the move,rhsis not associated with a file andrhs.is_open() == false. - The copy assignment operator is deleted β literally
delete;in the synopsis β andbasic_filebufis notCopyAssignable.
no cap, the deleted copy one is a whole vibe: if you try to copy-assign a basic_filebuf, the compiler is gonna shut that down.
π Parameters π
rhsβ anotherbasic_filebufthat will be moved from.
π Return value π
*this β that's the return, bestie.
π¦ Example π¦
cppreference has the Run this code link, and the manpage literally shows // Run this code. Here's the example exactly as it appears:
#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::ofstream{"test.in"} << "test\n"; // writes via a temporary
object
std::ifstream fin("test.in"); // read-only stream
std::ofstream fout("test.out"); // write-only stream
std::string s;
std::getline(fin, s);
std::cout << "s = [" << s << "]\n"; // s contains "test"
assert(fout.is_open());
*fin.rdbuf() = std::move(*fout.rdbuf());
assert(!fout.is_open());
std::getline(fin, s);
std::cout << "s = [" << s << "]\n"; // s is empty input
}
yes, the object line is the original wrap β I left it exactly alone because details matter, bestie.
π Output π
s = [test]
s = []
π See also π
constructorβ constructs abasic_filebufobject (public member function).swapβ swaps twobasic_filebufobjects (C++11) (public member function).
okay that's the whole page, bestie π«Ά β source: http://cppreference.com, version/date: 2024.06.10. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms