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>& seekp(off_type off, ios_base::seekdir dir); 16 17#include <ostream> 18#include <cassert> 19 20int seekoff_called = 0; 21 22template <class CharT> 23struct testbuf 24 : public std::basic_streambuf<CharT> 25{ 26 typedef std::basic_streambuf<CharT> base; 27 testbuf() {} 28 29protected: 30 31 typename base::pos_type 32 seekoff(typename base::off_type off, std::ios_base::seekdir way, 33 std::ios_base::openmode which) 34 { 35 ++seekoff_called; 36 assert(way == std::ios_base::beg); 37 assert(which == std::ios_base::out); 38 return off; 39 } 40}; 41 42int main() 43{ 44 { 45 std::ostream os((std::streambuf*)0); 46 assert(&os.seekp(5, std::ios_base::beg) == &os); 47 assert(seekoff_called == 0); 48 } 49 { 50 testbuf<char> sb; 51 std::ostream os(&sb); 52 assert(&os.seekp(10, std::ios_base::beg) == &os); 53 assert(seekoff_called == 1); 54 assert(os.good()); 55 assert(&os.seekp(-1, std::ios_base::beg) == &os); 56 assert(seekoff_called == 2); 57 assert(os.fail()); 58 } 59} 60