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 // <iterator> 11 12 // class ostreambuf_iterator 13 14 // bool failed() const throw(); 15 16 #include <iterator> 17 #include <sstream> 18 #include <cassert> 19 20 template <typename Char, typename Traits = std::char_traits<Char> > 21 struct my_streambuf : public std::basic_streambuf<Char,Traits> { 22 typedef typename std::basic_streambuf<Char,Traits>::int_type int_type; 23 typedef typename std::basic_streambuf<Char,Traits>::char_type char_type; 24 25 my_streambuf() {} 26 int_type sputc(char_type) { return Traits::eof(); } 27 }; 28 29 int main() 30 { 31 { 32 my_streambuf<char> buf; 33 std::ostreambuf_iterator<char> i(&buf); 34 i = 'a'; 35 assert(i.failed()); 36 } 37 { 38 my_streambuf<wchar_t> buf; 39 std::ostreambuf_iterator<wchar_t> i(&buf); 40 i = L'a'; 41 assert(i.failed()); 42 } 43 } 44