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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10
11 // <sstream>
12
13 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
14 // class basic_stringbuf
15
16 // explicit basic_stringbuf(basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::in | ios_base::out);
17
18 #include <sstream>
19 #include <cassert>
20
21 #include "make_string.h"
22 #include "test_allocator.h"
23 #include "test_macros.h"
24
25 #define STR(S) MAKE_STRING(CharT, S)
26 #define SV(S) MAKE_STRING_VIEW(CharT, S)
27
28 template <class CharT>
test()29 static void test() {
30 {
31 std::basic_string<CharT> s(STR("testing"));
32 const std::basic_stringbuf<CharT> buf(std::move(s));
33 assert(buf.view() == SV("testing"));
34 }
35 {
36 std::basic_string<CharT> s(STR("testing"));
37 const std::basic_stringbuf<CharT> buf(std::move(s), std::ios_base::out);
38 assert(buf.view() == SV("testing"));
39 }
40 {
41 std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"));
42 const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> buf(std::move(s));
43 assert(buf.view() == SV("testing"));
44 }
45 {
46 std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"));
47 const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> buf(
48 std::move(s), std::ios_base::in);
49 assert(buf.view() == SV("testing"));
50 }
51 }
52
main(int,char **)53 int main(int, char**) {
54 test<char>();
55 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
56 test<wchar_t>();
57 #endif
58 return 0;
59 }
60