60 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// FILE_DEPENDENCIES: test.dat10 11// <fstream>12 13// template <class charT, class traits = char_traits<charT> >14// class basic_ifstream15 16// basic_ifstream(basic_ifstream&& rhs);17 18#include <fstream>19#include <cassert>20#include <ios>21 22#include "test_macros.h"23#include "operator_hijacker.h"24 25int main(int, char**)26{27 {28 std::ifstream fso("test.dat");29 std::ifstream fs = std::move(fso);30 double x = 0;31 fs >> x;32 assert(x == 3.25);33 }34 {35 std::basic_ifstream<char, operator_hijacker_char_traits<char> > fso("test.dat");36 std::basic_ifstream<char, operator_hijacker_char_traits<char> > fs = std::move(fso);37 std::basic_string<char, operator_hijacker_char_traits<char> > x;38 fs >> x;39 assert(x == "3.25");40 }41#ifndef TEST_HAS_NO_WIDE_CHARACTERS42 {43 std::wifstream fso("test.dat");44 std::wifstream fs = std::move(fso);45 double x = 0;46 fs >> x;47 assert(x == 3.25);48 }49 {50 std::basic_ifstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fso("test.dat");51 std::basic_ifstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs = std::move(fso);52 std::basic_string<wchar_t, operator_hijacker_char_traits<wchar_t> > x;53 fs >> x;54 assert(x == L"3.25");55 }56#endif57 58 return 0;59}60