1/*
2Copyright 2019-2020 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7*/
8#ifndef BOOST_IO_DETAIL_OSTREAM_GUARD_HPP
9#define BOOST_IO_DETAIL_OSTREAM_GUARD_HPP
10
11#include <boost/config.hpp>
12#include <iosfwd>
13
14namespace boost {
15namespace io {
16namespace detail {
17
18template<class Char, class Traits>
19class ostream_guard {
20public:
21 explicit ostream_guard(std::basic_ostream<Char, Traits>& os) BOOST_NOEXCEPT
22 : os_(&os) { }
23
24 ~ostream_guard() BOOST_NOEXCEPT_IF(false) {
25 if (os_) {
26 os_->setstate(std::basic_ostream<Char, Traits>::badbit);
27 }
28 }
29
30 void release() BOOST_NOEXCEPT {
31 os_ = 0;
32 }
33
34private:
35 ostream_guard(const ostream_guard&);
36 ostream_guard& operator=(const ostream_guard&);
37
38 std::basic_ostream<Char, Traits>* os_;
39};
40
41} /* detail */
42} /* io */
43} /* boost */
44
45#endif
46

source code of boost/libs/io/include/boost/io/detail/ostream_guard.hpp