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 Stream, class T>
12 // Stream&& operator<<(Stream&& os, const T& x);
17 #include "test_macros.h"
20 template <class CharT
>
22 : public std::basic_streambuf
<CharT
>
24 typedef std::basic_streambuf
<CharT
> base
;
25 std::basic_string
<CharT
> str_
;
31 std::basic_string
<CharT
> str() const
32 {return std::basic_string
<CharT
>(base::pbase(), base::pptr());}
36 virtual typename
base::int_type
37 overflow(typename
base::int_type ch
= base::traits_type::eof())
39 if (ch
!= base::traits_type::eof())
41 int n
= static_cast<int>(str_
.size());
42 str_
.push_back(static_cast<CharT
>(ch
));
43 str_
.resize(str_
.capacity());
44 base::setp(const_cast<CharT
*>(str_
.data()),
45 const_cast<CharT
*>(str_
.data() + str_
.size()));
54 template <class CharT
>
55 friend void operator<<(std::basic_ostream
<CharT
>& os
, Int
const& self
) {
66 std::ostream
&& result
= (std::move(os
) << i
);
67 assert(&result
== &os
);
68 assert(sb
.str() == "123");
70 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
73 std::wostream
os(&sb
);
75 std::wostream
&& result
= (std::move(os
) << i
);
76 assert(&result
== &os
);
77 assert(sb
.str() == L
"123");