1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_ostream;
14 // template <class charT, class traits>
15 // basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
20 #include "test_macros.h"
24 template <class CharT
>
26 : public std::basic_streambuf
<CharT
>
28 typedef std::basic_streambuf
<CharT
> base
;
29 std::basic_string
<CharT
> str_
;
35 std::basic_string
<CharT
> str() const
36 {return std::basic_string
<CharT
>(base::pbase(), base::pptr());}
40 virtual typename
base::int_type
41 overflow(typename
base::int_type ch
= base::traits_type::eof())
43 if (ch
!= base::traits_type::eof())
45 int n
= static_cast<int>(str_
.size());
46 str_
.push_back(static_cast<CharT
>(ch
));
47 str_
.resize(str_
.capacity());
48 base::setp(const_cast<CharT
*>(str_
.data()),
49 const_cast<CharT
*>(str_
.data() + str_
.size()));
69 assert(sb
.str() == "\n");
70 assert(sync_called
== 1);
73 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
76 std::wostream
os(&sb
);
78 assert(sb
.str() == L
"\n");
79 assert(sync_called
== 2);