std::error_code::operator=(3)

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

πŸ’– NAME πŸ’–

Bestie, welcome to the std::error_code::operator=(3) page from the C++ Standard Libary manual 😌✨. The NAME line is literally std::error_code::operator= - std::error_code::operator=, and honestly? Iconic repetitive queen behavior πŸ’….


✨ Synopsis ✨

template< class ErrorCodeEnum >                            (1) (since C++11)
error_code& operator=( ErrorCodeEnum e ) noexcept;

error_code& operator=( const error_code& other ) = default; (2) (since C++11)
                                                            (implicitly declared)

error_code& operator=( error_code&& other ) = default;      (3) (since C++11)
                                                            (implicitly declared)

Okay so here's the tea, overload by overload πŸ«–:

  1. This one replaces the error code and corresponding category with those representing error code enum e πŸ’–.

It's equivalent to *this = make_error_code(e), where make_error_code is only found by argument-dependent lookup β€” yes, ADL is the main character here πŸ‘‘.

Lowkey important: this overload participates in overload resolution only if std::is_error_code_enum<ErrorCodeEnum>::value is true 🚨.
  1. This is the implicitly defined copy-assignment operator, and it assigns the contents of other to *this πŸŽ€.
  2. This is the implicitly defined move-assignment operator, and it also assigns the contents of other to *this πŸ¦‹.

πŸŽ€ Parameters πŸŽ€

  • e β€” error code enum to construct 🌸
  • other β€” another error code to assign with πŸ’œ

πŸ’« Return value πŸ’«

*this β€” that's the return value, periodt πŸ’…βœ¨

🩹 Defect reports 🩹

The following behavior-changing defect reports were applied retroactively to previously published C++ standards πŸ“š:

  • LWG 3629, applied to C++11 β€” behavior as published: only std::make_error_code overloads were used. Correct behavior: ADL-found overloads are used πŸ”₯

πŸ‘€ See also πŸ‘€

  • assign β€” assigns another error code (public member function) πŸ’–

With love, zero cap, and full main-character energy: source/version http://cppreference.com, date 2024.06.10, page std::error_code::operator=(3) πŸŽ€πŸ’…πŸ«Ά

πŸ“¦ where this page comes from