std::system...::operator=(3)
π NAME π
std::system_error::operator= β it's literally the assignment operator for std::system_error, bestie. Copy-paste energy but make it C++.
So this page is from the C++ Standard Library manual, section 3, and the page itself is std::system...::operator=(3). Yes the title is truncated with ... and that's just how cppreference rolls, no cap.
β¨ Synopsis β¨
system_error& operator=( const system_error& other ) noexcept;
<span style="color:cyan">(since C++11)</span> β so she's been iconic since C++11, we love a consistent queen π
What she does: assigns the contents of other into *this. Basically a hand-me-down but make it official.
And here's the β¨fancyβ¨ part: if both *this and other have dynamic type std::system_error, then after the assignment you get:
std::strcmp(what(), other.what()) == 0
Like, the what() strings match exactly. Vibe check passed β
π Parameters π
otherβ anothersystem_errorobject to assign with. That's it. That's the whole parameter. She's low maintenance π
πΈ Return value πΈ
*this β she returns herself, main character energy fr fr π
π¦ Example π¦
okay so run this code, it's giving demonstration:
// Run this code
#include <cassert>
#include <cstring>
#include <iostream>
#include <system_error>
void print(const std::system_error& e)
{
std::cout << "code: [" << e.code() << "]\n"
"message: [" << e.code().message() << "]\n"
"what: [" << e.what() << "]\n\n";
}
int main()
{
std::system_error e1(EDOM, std::generic_category(), "Error info #1");
print(e1);
std::system_error e2(EIO, std::system_category(), "Error info #2");
print(e2);
e1 = e2;
assert(std::strcmp(e1.what(), e2.what()) == 0);
print(e1);
}
Notice that assert? That's the receipts for the whole strcmp(what(), other.what()) == 0 thing. She said prove it, and then she proved it π
π Possible output π
code: [generic:33]
message: [Numerical argument out of domain]
what: [Error info #1: Numerical argument out of domain]
code: [system:5]
message: [Input/output error]
what: [Error info #2: Input/output error]
code: [system:5]
message: [Input/output error]
what: [Error info #2: Input/output error]
See how the third block is a total clone of the second? That's the assignment doing its thing β e1 fully absorbed e2's whole personality. Slay π
heads up bestie: the page says Possible output, so don't come for me if your terminal prints it slightly differently. It said possible, not guaranteed π
sign-off time π«Ά β this lil masterpiece lives over at http://cppreference.com, dated 2024.06.10, and it's page std::system...::operator=(3) from the C++ Standard Library manual. Bye bestie, go assign something πβ¨π
π¦ 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