Skip input to next line, for reading serialized objects I was de-serializing objects that had an extra newline that needed to be removed before getting the next object.

#ifndef THORSANVIL_UTIL_H
#define THORSANVIL_UTIL_H

// Removed headers for   getDist() and getRandomContainerIterator()
// We already reviewed those two. 
#include &lt;iostream&gt;

namespace ThorsAnvil
{
    namespace Util
    {

// Removed getDist() and getRandomContainerIterator()
// We already reviewed those two.

class IgnoreUntilNewLine
{
    public:
        friend std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, IgnoreUntilNewLine&amp; /*data*/)
        {
            stream.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
            return stream;
        }
};

class SkipEmptyLineToEnd
{
    public:
        friend std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, SkipEmptyLineToEnd&amp; /*data*/)
        {
            std::string     emptyLine;
            std::getline(stream, emptyLine);
            if (!emptyLine.empty()) {
                stream.setstate(std::ios::badbit);
            }
            return stream;
        }
};

    }
}

#endif


Simplified Example for usage:

namespace TU = ThorsAnvil::Util;
struct Example1
{
     int    x;
     int    y;
     std::string  line; // Always one line with no "\n"
     void swap(Example1&amp; other) noexcept {/*Stuff*/}

     friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, Example1 const&amp; data)
     {
         // Note putting a new line here
         // to make the Serialized object more readable.
         // The actual object was a bit more complicated and
         // I really wanted to make it readable.
         return stream &lt;&lt; data.x &lt;&lt; " " &lt;&lt; data.y &lt;&lt; "\n"
                       &lt;&lt; data.line &lt;&lt; "\n";
     }
     friend std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, Example1&amp; data)
     {
         Example1  tmp;
         if (stream &gt;&gt; tmp.x &gt;&gt; tmp.y)
         {
             stream.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
             if (std::getline(stream, tmp.line)) {
                 data.swap(tmp);
             }
         }
         return stream;
     }
};


I thought the above read was a bit cumbersome and hard to read. Thus the two types above. This means I can re-write the read operation as:

     friend std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, Example1&amp; data)
     {
         TU::IgnoreUntilNewLine ignoreNewLine;
         Example1               tmp;

         if ((stream &gt;&gt; tmp.x &gt;&gt; tmp.y &gt;&gt; ignoreNewLine) &amp;&amp; std::getline(stream, tmp.line)) {
             data.swap(tmp);
         }
         return stream;
     }
IgnoreUntilNewLine is too long in my opinion.  I'd simplify it to ignore_line.

It probably makes sense to provide the manipulator object in the library instead of letting the user declare one:

struct ignore_line_t {
    constexpr explicit ignore_until_newline_t() = default;
    // ...
};
inline constexpr ignore_line_t ignore_line{};


so the user can use it directly in a &gt;&gt; chain:

stream &gt;&gt; tmp.x &gt;&gt; tmp.y &gt;&gt; TU::ignore_line


Incidentally, we can go further and provide a similar helper for getline to fit in the chain:

class getline {
    std::string&amp; dest;
public:
    explicit getline(std::string&amp; s)
        : dest{s}
    {
    }
    friend std::istream&amp; operator&gt;&gt;(std::istream&amp; is, getline man)
    {
        return std::getline(is, man.dest);
    }
};


so your example can be written simply as

stream &gt;&gt; tmp.x &gt;&gt; tmp.y &gt;&gt; TU::ignore_line &gt;&gt; TU::getline(tmp.line)