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