1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <sstream>
11 
12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
13 // class basic_istringstream
14 
15 // template <class charT, class traits, class Allocator>
16 //   void
17 //   swap(basic_istringstream<charT, traits, Allocator>& x,
18 //        basic_istringstream<charT, traits, Allocator>& y);
19 
20 #include <sstream>
21 #include <cassert>
22 
main()23 int main()
24 {
25     {
26         std::istringstream ss0(" 123 456");
27         std::istringstream ss(" 789 321");
28         swap(ss, ss0);
29         assert(ss.rdbuf() != 0);
30         assert(ss.good());
31         assert(ss.str() == " 123 456");
32         int i = 0;
33         ss >> i;
34         assert(i == 123);
35         ss >> i;
36         assert(i == 456);
37         ss0 >> i;
38         assert(i == 789);
39         ss0 >> i;
40         assert(i == 321);
41     }
42     {
43         std::wistringstream ss0(L" 123 456");
44         std::wistringstream ss(L" 789 321");
45         swap(ss, ss0);
46         assert(ss.rdbuf() != 0);
47         assert(ss.good());
48         assert(ss.str() == L" 123 456");
49         int i = 0;
50         ss >> i;
51         assert(i == 123);
52         ss >> i;
53         assert(i == 456);
54         ss0 >> i;
55         assert(i == 789);
56         ss0 >> i;
57         assert(i == 321);
58     }
59 }
60