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_stringbuf 13 14 // void swap(basic_stringbuf& rhs); 15 16 #include <sstream> 17 #include <cassert> 18 19 int main(int, char**) 20 { 21 { 22 std::stringbuf buf1("testing"); 23 std::stringbuf buf; 24 buf.swap(buf1); 25 assert(buf.str() == "testing"); 26 assert(buf1.str() == ""); 27 } 28 { 29 std::stringbuf buf1("testing", std::ios_base::in); 30 std::stringbuf buf; 31 buf.swap(buf1); 32 assert(buf.str() == "testing"); 33 assert(buf1.str() == ""); 34 } 35 { 36 std::stringbuf buf1("testing", std::ios_base::out); 37 std::stringbuf buf; 38 buf.swap(buf1); 39 assert(buf.str() == "testing"); 40 assert(buf1.str() == ""); 41 } 42 { 43 std::wstringbuf buf1(L"testing"); 44 std::wstringbuf buf; 45 buf.swap(buf1); 46 assert(buf.str() == L"testing"); 47 assert(buf1.str() == L""); 48 } 49 { 50 std::wstringbuf buf1(L"testing", std::ios_base::in); 51 std::wstringbuf buf; 52 buf.swap(buf1); 53 assert(buf.str() == L"testing"); 54 assert(buf1.str() == L""); 55 } 56 { 57 std::wstringbuf buf1(L"testing", std::ios_base::out); 58 std::wstringbuf buf; 59 buf.swap(buf1); 60 assert(buf.str() == L"testing"); 61 assert(buf1.str() == L""); 62 } 63 64 return 0; 65 } 66