82 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <fstream>10 11// template <class charT, class traits = char_traits<charT> >12// class basic_ofstream13 14// basic_ofstream(basic_ofstream&& rhs);15 16#include <fstream>17#include <cassert>18 19#include "test_macros.h"20#include "platform_support.h"21#include "operator_hijacker.h"22 23int main(int, char**)24{25 std::string temp = get_temp_file_name();26 {27 std::ofstream fso(temp.c_str());28 std::ofstream fs = std::move(fso);29 fs << 3.25;30 }31 {32 std::ifstream fs(temp.c_str());33 double x = 0;34 fs >> x;35 assert(x == 3.25);36 }37 std::remove(temp.c_str());38 39 {40 std::basic_ofstream<char, operator_hijacker_char_traits<char> > fso(temp.c_str());41 std::basic_ofstream<char, operator_hijacker_char_traits<char> > fs = std::move(fso);42 fs << "3.25";43 }44 {45 std::ifstream fs(temp.c_str());46 double x = 0;47 fs >> x;48 assert(x == 3.25);49 }50 std::remove(temp.c_str());51 52#ifndef TEST_HAS_NO_WIDE_CHARACTERS53 {54 std::wofstream fso(temp.c_str());55 std::wofstream fs = std::move(fso);56 fs << 3.25;57 }58 {59 std::wifstream fs(temp.c_str());60 double x = 0;61 fs >> x;62 assert(x == 3.25);63 }64 std::remove(temp.c_str());65 66 {67 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fso(temp.c_str());68 std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs = std::move(fso);69 fs << L"3.25";70 }71 {72 std::wifstream fs(temp.c_str());73 double x = 0;74 fs >> x;75 assert(x == 3.25);76 }77 std::remove(temp.c_str());78#endif79 80 return 0;81}82