nonmember_swap.pass.cpp revision 256813f4e7915d64776a4edd5f4765d893b9f062
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_fstream 14 15// template <class charT, class traits> 16// void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y); 17 18#include <fstream> 19#include <cassert> 20 21int main() 22{ 23 { 24 std::fstream fs1("test1.dat", std::ios_base::in | std::ios_base::out 25 | std::ios_base::trunc); 26 std::fstream fs2("test2.dat", std::ios_base::in | std::ios_base::out 27 | std::ios_base::trunc); 28 fs1 << 1 << ' ' << 2; 29 fs2 << 2 << ' ' << 1; 30 fs1.seekg(0); 31 swap(fs1, fs2); 32 fs1.seekg(0); 33 int i; 34 fs1 >> i; 35 assert(i == 2); 36 fs1 >> i; 37 assert(i == 1); 38 i = 0; 39 fs2 >> i; 40 assert(i == 1); 41 fs2 >> i; 42 assert(i == 2); 43 } 44 std::remove("test1.dat"); 45 std::remove("test2.dat"); 46 { 47 std::wfstream fs1("test1.dat", std::ios_base::in | std::ios_base::out 48 | std::ios_base::trunc); 49 std::wfstream fs2("test2.dat", std::ios_base::in | std::ios_base::out 50 | std::ios_base::trunc); 51 fs1 << 1 << ' ' << 2; 52 fs2 << 2 << ' ' << 1; 53 fs1.seekg(0); 54 swap(fs1, fs2); 55 fs1.seekg(0); 56 int i; 57 fs1 >> i; 58 assert(i == 2); 59 fs1 >> i; 60 assert(i == 1); 61 i = 0; 62 fs2 >> i; 63 assert(i == 1); 64 fs2 >> i; 65 assert(i == 2); 66 } 67 std::remove("test1.dat"); 68 std::remove("test2.dat"); 69} 70