std::iostream_category(3)

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

✨ std::iostream_category(3) ✨

okay so this little page is from the C++ Standard Libary corner of cppreference, and we are about to make std::iostream_category make sense. it's giving β€œniche but iconic” energy, and honestly? obsessed. πŸŽ€


πŸ’– NAME πŸ’–

std::iostream_category - std::iostream_category

yes bestie, the name repeats, and we are simply going to let it have that main character moment. πŸ’…


πŸ¦‹ Synopsis πŸ¦‹

Defined in header <ios>:

const std::error_category& iostream_category() noexcept;  (since C++11)

So what does it do? It obtains a reference to the static error category object for iostream errors. That object is required to override the virtual function error_category::name() to return a pointer to the string "iostream". It is used to identify error codes provided in the exceptions of type std::ios_base::failure. no cap, that's the whole vibe check. ✨


🌸 Parameters 🌸

None. Nada. Zero. This one takes no arguments, bestie. 🫢


🧚 Return value 🧚

A reference to the static object of unspecified runtime type, derived from std::error_category. literally that's it, and it ate. πŸ’œ


πŸ”₯ Example πŸ”₯

#include <fstream>
#include <iostream>

int main()
{
    std::ifstream f("doesn't exist");
    try
    {
        f.exceptions(f.failbit);
    }
    catch (const std::ios_base::failure& e)
    {
        std::cout << "Caught an ios_base::failure.\n"
                  << "Error code: " << e.code().value()
                  << " (" << e.code().message() << ")\n"
                  << "Error category: " << e.code().category().name()
       << '\n';

    }
}

🌈 Possible output: 🌈

Caught an ios_base::failure.
Error code: 1 (unspecified iostream_category error)
Error category: iostream

πŸ’€ Defect reports πŸ’€

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

  • DR: LWG 2087 β€” Applied to: C++11
    • Behavior as published: iostream_category was not declared noexcept
    • Correct behavior: declared noexcept

periodt. the standards said β€œbestie, fix the noexcept,” and they did. 🫑


πŸ‘‘ See also πŸ‘‘

  • failure β€” stream exception (public member class of std::ios_base)
  • io_errc β€” the IO stream error codes (C++11) (enum)

🫢 that's the whole page, bestie! source/version/date vibes: http://cppreference.com, 2024.06.10, and the page tag std::iostream_category(3) β€” mwah πŸ’‹
πŸ“¦ where this page comes from