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 // <sstream>
10
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_istringstream
13
14 // template <class charT, class traits, class Allocator>
15 // void
16 // swap(basic_istringstream<charT, traits, Allocator>& x,
17 // basic_istringstream<charT, traits, Allocator>& y);
18
19 #include <sstream>
20 #include <cassert>
21
22 #include "test_macros.h"
23
main(int,char **)24 int main(int, char**)
25 {
26 {
27 std::istringstream ss0(" 123 456");
28 std::istringstream ss(" 789 321");
29 swap(ss, ss0);
30 assert(ss.rdbuf() != 0);
31 assert(ss.good());
32 assert(ss.str() == " 123 456");
33 int i = 0;
34 ss >> i;
35 assert(i == 123);
36 ss >> i;
37 assert(i == 456);
38 ss0 >> i;
39 assert(i == 789);
40 ss0 >> i;
41 assert(i == 321);
42 }
43 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44 {
45 std::wistringstream ss0(L" 123 456");
46 std::wistringstream ss(L" 789 321");
47 swap(ss, ss0);
48 assert(ss.rdbuf() != 0);
49 assert(ss.good());
50 assert(ss.str() == L" 123 456");
51 int i = 0;
52 ss >> i;
53 assert(i == 123);
54 ss >> i;
55 assert(i == 456);
56 ss0 >> i;
57 assert(i == 789);
58 ss0 >> i;
59 assert(i == 321);
60 }
61 #endif
62
63 return 0;
64 }
65