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_ofstream
14
15// template <class charT, class traits>
16//   void swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
17
18#include <fstream>
19#include <cassert>
20
21int main()
22{
23    {
24        std::ofstream fs1("test1.dat");
25        std::ofstream fs2("test2.dat");
26        fs1 << 3.25;
27        fs2 << 4.5;
28        swap(fs1, fs2);
29        fs1 << ' ' << 3.25;
30        fs2 << ' ' << 4.5;
31    }
32    {
33        std::ifstream fs("test1.dat");
34        double x = 0;
35        fs >> x;
36        assert(x == 3.25);
37        fs >> x;
38        assert(x == 4.5);
39    }
40    remove("test1.dat");
41    {
42        std::ifstream fs("test2.dat");
43        double x = 0;
44        fs >> x;
45        assert(x == 4.5);
46        fs >> x;
47        assert(x == 3.25);
48    }
49    remove("test2.dat");
50    {
51        std::wofstream fs1("test1.dat");
52        std::wofstream fs2("test2.dat");
53        fs1 << 3.25;
54        fs2 << 4.5;
55        swap(fs1, fs2);
56        fs1 << ' ' << 3.25;
57        fs2 << ' ' << 4.5;
58    }
59    {
60        std::wifstream fs("test1.dat");
61        double x = 0;
62        fs >> x;
63        assert(x == 3.25);
64        fs >> x;
65        assert(x == 4.5);
66    }
67    remove("test1.dat");
68    {
69        std::wifstream fs("test2.dat");
70        double x = 0;
71        fs >> x;
72        assert(x == 4.5);
73        fs >> x;
74        assert(x == 3.25);
75    }
76    remove("test2.dat");
77}
78