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