nonmember_swap.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 2// 3// ��������������������The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <fstream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_filebuf 14 15// template <class charT, class traits> 16// void 17// swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y); 18 19#include <fstream> 20#include <cassert> 21 22int main() 23{ 24 { 25 std::filebuf f; 26 assert(f.open("test.dat", std::ios_base::out | std::ios_base::in 27 | std::ios_base::trunc) != 0); 28 assert(f.is_open()); 29 assert(f.sputn("123", 3) == 3); 30 f.pubseekoff(1, std::ios_base::beg); 31 assert(f.sgetc() == '2'); 32 std::filebuf f2; 33 swap(f2, f); 34 assert(!f.is_open()); 35 assert(f2.is_open()); 36 assert(f2.sgetc() == '2'); 37 } 38 remove("test.dat"); 39 { 40 std::wfilebuf f; 41 assert(f.open("test.dat", std::ios_base::out | std::ios_base::in 42 | std::ios_base::trunc) != 0); 43 assert(f.is_open()); 44 assert(f.sputn(L"123", 3) == 3); 45 f.pubseekoff(1, std::ios_base::beg); 46 assert(f.sgetc() == L'2'); 47 std::wfilebuf f2; 48 swap(f2, f); 49 assert(!f.is_open()); 50 assert(f2.is_open()); 51 assert(f2.sgetc() == L'2'); 52 } 53 remove("test.dat"); 54} 55