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

source code of libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/member_swap.pass.cpp