Skip to content

Instantly share code, notes, and snippets.

@c0ffeeartc
Last active September 17, 2015 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0ffeeartc/39bcca436f23b29af035 to your computer and use it in GitHub Desktop.
Save c0ffeeartc/39bcca436f23b29af035 to your computer and use it in GitHub Desktop.
#include <iostream>
class ScopeSwapOStream
{
public:
ScopeSwapOStream(const ScopeSwapOStream&&) = delete;
ScopeSwapOStream(const ScopeSwapOStream&) = delete;
ScopeSwapOStream& operator=(const ScopeSwapOStream&&) = delete;
ScopeSwapOStream& operator=(const ScopeSwapOStream&) = delete;
ScopeSwapOStream
( std::ostream & original
, std::ostream & swap)
: _original(original)
, _originalBuf(_original.rdbuf(swap.rdbuf()))
{
}
~ScopeSwapOStream()
{
_original.rdbuf(_originalBuf);
}
private:
std::ostream & _original;
std::streambuf * _originalBuf;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment