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// <istream>
10
11// template <class charT, class traits = char_traits<charT> >
12// class basic_istream;
13
14// basic_istream& operator=(basic_istream&& rhs);
15
16#include <istream>
17#include <cassert>
18#include <streambuf>
19
20#include "test_macros.h"
21
22
23template <class CharT>
24struct testbuf
25 : public std::basic_streambuf<CharT>
26{
27 testbuf() {}
28};
29
30template <class CharT>
31struct test_istream
32 : public std::basic_istream<CharT>
33{
34 typedef std::basic_istream<CharT> base;
35 test_istream(testbuf<CharT>* sb) : base(sb) {}
36
37 test_istream& operator=(test_istream&& s)
38 {base::operator=(std::move(s)); return *this;}
39};
40
41
42int main(int, char**)
43{
44 {
45 testbuf<char> sb1;
46 testbuf<char> sb2;
47 test_istream<char> is1(&sb1);
48 test_istream<char> is2(&sb2);
49 is2 = (std::move(is1));
50 assert(is1.rdbuf() == &sb1);
51 assert(is1.tie() == 0);
52 assert(is1.fill() == ' ');
53 assert(is1.rdstate() == is1.goodbit);
54 assert(is1.exceptions() == is1.goodbit);
55 assert(is1.flags() == (is1.skipws | is1.dec));
56 assert(is1.precision() == 6);
57 assert(is1.getloc().name() == "C");
58 assert(is2.rdbuf() == &sb2);
59 assert(is2.tie() == 0);
60 assert(is2.fill() == ' ');
61 assert(is2.rdstate() == is2.goodbit);
62 assert(is2.exceptions() == is2.goodbit);
63 assert(is2.flags() == (is2.skipws | is2.dec));
64 assert(is2.precision() == 6);
65 assert(is2.getloc().name() == "C");
66 }
67#ifndef TEST_HAS_NO_WIDE_CHARACTERS
68 {
69 testbuf<wchar_t> sb1;
70 testbuf<wchar_t> sb2;
71 test_istream<wchar_t> is1(&sb1);
72 test_istream<wchar_t> is2(&sb2);
73 is2 = (std::move(is1));
74 assert(is1.rdbuf() == &sb1);
75 assert(is1.tie() == 0);
76 assert(is1.fill() == ' ');
77 assert(is1.rdstate() == is1.goodbit);
78 assert(is1.exceptions() == is1.goodbit);
79 assert(is1.flags() == (is1.skipws | is1.dec));
80 assert(is1.precision() == 6);
81 assert(is1.getloc().name() == "C");
82 assert(is2.rdbuf() == &sb2);
83 assert(is2.tie() == 0);
84 assert(is2.fill() == ' ');
85 assert(is2.rdstate() == is2.goodbit);
86 assert(is2.exceptions() == is2.goodbit);
87 assert(is2.flags() == (is2.skipws | is2.dec));
88 assert(is2.precision() == 6);
89 assert(is2.getloc().name() == "C");
90 }
91#endif
92
93 return 0;
94}
95

source code of libcxx/test/std/input.output/iostream.format/input.streams/istream/istream.assign/move_assign.pass.cpp