1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <ostream> 11 12 // template <class charT, class traits = char_traits<charT> > 13 // class basic_ostream; 14 15 // basic_ostream<charT,traits>& operator<<(basic_ios<charT,traits>& 16 // (*pf)(basic_ios<charT,traits>&)); 17 18 #include <ostream> 19 #include <cassert> 20 21 template <class CharT> 22 class testbuf 23 : public std::basic_streambuf<CharT> 24 { 25 typedef std::basic_streambuf<CharT> base; 26 std::basic_string<CharT> str_; 27 public: testbuf()28 testbuf() 29 { 30 } 31 str() const32 std::basic_string<CharT> str() const 33 {return std::basic_string<CharT>(base::pbase(), base::pptr());} 34 35 protected: 36 37 virtual typename base::int_type overflow(typename base::int_type __c=base::traits_type::eof ())38 overflow(typename base::int_type __c = base::traits_type::eof()) 39 { 40 if (__c != base::traits_type::eof()) 41 { 42 int n = str_.size(); 43 str_.push_back(__c); 44 str_.resize(str_.capacity()); 45 base::setp(const_cast<CharT*>(str_.data()), 46 const_cast<CharT*>(str_.data() + str_.size())); 47 base::pbump(n+1); 48 } 49 return __c; 50 } 51 }; 52 53 template <class CharT> 54 std::basic_ios<CharT>& f(std::basic_ios<CharT> & os)55f(std::basic_ios<CharT>& os) 56 { 57 std::uppercase(os); 58 return os; 59 } 60 main()61int main() 62 { 63 { 64 testbuf<char> sb; 65 std::ostream os(&sb); 66 assert(!(os.flags() & std::ios_base::uppercase)); 67 os << f; 68 assert( (os.flags() & std::ios_base::uppercase)); 69 } 70 } 71