79143747

Date: 2024-10-31 07:13:17
Score: 1
Natty:
Report link

Here's a modern C++ solution based on the answer by john and comment by Sjoerd:

#include <ostream>
#include <streambuf>

// Adapted from https://stackoverflow.com/a/11826666
class oblivion_stream final : public std::ostream {
public:
    oblivion_stream() noexcept : std::ostream(&os_buffer_)
    {
    }

private:
    class oblivion_stream_buffer_ final : public std::streambuf {
    protected:
        [[nodiscard]] auto overflow(int_type ch) noexcept -> int_type override
        {
            return ch;
        }
    };

    oblivion_stream_buffer_ os_buffer_{};
};
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: user6134386