1 /* 2 Copyright 2019-2020 Glen Joseph Fernandes 3 ([email protected]) 4 5 Distributed 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 14 namespace boost { 15 namespace io { 16 namespace detail { 17 18 template<class Char, class Traits> 19 class ostream_guard { 20 public: ostream_guard(std::basic_ostream<Char,Traits> & os)21 explicit ostream_guard(std::basic_ostream<Char, Traits>& os) BOOST_NOEXCEPT 22 : os_(&os) { } 23 BOOST_NOEXCEPT_IF(false)24 ~ostream_guard() BOOST_NOEXCEPT_IF(false) { 25 if (os_) { 26 os_->setstate(std::basic_ostream<Char, Traits>::badbit); 27 } 28 } 29 release()30 void release() BOOST_NOEXCEPT { 31 os_ = 0; 32 } 33 34 private: 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