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

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