1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <fstream>
10
11// template <class charT, class traits = char_traits<charT> >
12// class basic_ofstream
13
14// basic_ofstream(basic_ofstream&& rhs);
15
16// XFAIL: FROZEN-CXX03-HEADERS-FIXME
17
18#include <fstream>
19#include <cassert>
20
21#include "test_macros.h"
22#include "platform_support.h"
23#include "operator_hijacker.h"
24
25int main(int, char**)
26{
27 std::string temp = get_temp_file_name();
28 {
29 std::ofstream fso(temp.c_str());
30 std::ofstream fs = std::move(fso);
31 fs << 3.25;
32 }
33 {
34 std::ifstream fs(temp.c_str());
35 double x = 0;
36 fs >> x;
37 assert(x == 3.25);
38 }
39 std::remove(filename: temp.c_str());
40
41 {
42 std::basic_ofstream<char, operator_hijacker_char_traits<char> > fso(temp.c_str());
43 std::basic_ofstream<char, operator_hijacker_char_traits<char> > fs = std::move(fso);
44 fs << "3.25";
45 }
46 {
47 std::ifstream fs(temp.c_str());
48 double x = 0;
49 fs >> x;
50 assert(x == 3.25);
51 }
52 std::remove(filename: temp.c_str());
53
54#ifndef TEST_HAS_NO_WIDE_CHARACTERS
55 {
56 std::wofstream fso(temp.c_str());
57 std::wofstream fs = std::move(fso);
58 fs << 3.25;
59 }
60 {
61 std::wifstream fs(temp.c_str());
62 double x = 0;
63 fs >> x;
64 assert(x == 3.25);
65 }
66 std::remove(filename: temp.c_str());
67
68 {
69 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fso(temp.c_str());
70 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs = std::move(fso);
71 fs << L"3.25";
72 }
73 {
74 std::wifstream fs(temp.c_str());
75 double x = 0;
76 fs >> x;
77 assert(x == 3.25);
78 }
79 std::remove(filename: temp.c_str());
80#endif
81
82 return 0;
83}
84

source code of libcxx/test/std/input.output/file.streams/fstreams/ofstream.cons/move.pass.cpp