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_fstream
13
14// basic_fstream(basic_fstream&& 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::fstream fso(temp, std::ios_base::in | std::ios_base::out
30 | std::ios_base::trunc);
31 std::fstream fs = std::move(fso);
32 double x = 0;
33 fs << 3.25;
34 fs.seekg(0);
35 fs >> x;
36 assert(x == 3.25);
37 }
38 std::remove(filename: temp.c_str());
39
40 {
41 std::basic_fstream<char, operator_hijacker_char_traits<char> > fso(
42 temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
43 std::basic_fstream<char, operator_hijacker_char_traits<char> > fs = std::move(fso);
44 std::basic_string<char, operator_hijacker_char_traits<char> > x;
45 fs << "3.25";
46 fs.seekg(0);
47 fs >> x;
48 assert(x == "3.25");
49 }
50 std::remove(filename: temp.c_str());
51
52#ifndef TEST_HAS_NO_WIDE_CHARACTERS
53 {
54 std::wfstream fso(temp, std::ios_base::in | std::ios_base::out
55 | std::ios_base::trunc);
56 std::wfstream fs = std::move(fso);
57 double x = 0;
58 fs << 3.25;
59 fs.seekg(0);
60 fs >> x;
61 assert(x == 3.25);
62 }
63 std::remove(filename: temp.c_str());
64
65 {
66 std::basic_fstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fso(
67 temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
68 std::basic_fstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs = std::move(fso);
69 std::basic_string<wchar_t, operator_hijacker_char_traits<wchar_t> > x;
70 fs << L"3.25";
71 fs.seekg(0);
72 fs >> x;
73 assert(x == L"3.25");
74 }
75 std::remove(filename: temp.c_str());
76#endif
77
78 return 0;
79}
80

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