| 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 |
// <ostream> |
| 10 |
|
| 11 |
// template <class charT, class traits = char_traits<charT> > |
| 12 |
// class basic_ostream; |
| 13 |
|
| 14 |
// basic_ostream<charT,traits>& operator<<(basic_ios<charT,traits>& |
| 15 |
// (*pf)(basic_ios<charT,traits>&)); |
| 16 |
|
| 17 |
#include <ostream> |
| 18 |
#include <cassert> |
| 19 |
|
| 20 |
#include "test_macros.h" |
| 21 |
|
| 22 |
template <class CharT> |
| 23 |
class testbuf |
| 24 |
: public std::basic_streambuf<CharT> |
| 25 |
{ |
| 26 |
typedef std::basic_streambuf<CharT> base; |
| 27 |
std::basic_string<CharT> str_; |
| 28 |
public: |
| 29 |
testbuf() |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
std::basic_string<CharT> str() const |
| 34 |
{return std::basic_string<CharT>(base::pbase(), base::pptr());} |
| 35 |
|
| 36 |
protected: |
| 37 |
|
| 38 |
virtual typename base::int_type |
| 39 |
overflow(typename base::int_type ch = base::traits_type::eof()) |
| 40 |
{ |
| 41 |
if (ch != base::traits_type::eof()) |
| 42 |
{ |
| 43 |
int n = static_cast<int>(str_.size()); |
| 44 |
str_.push_back(static_cast<CharT>(ch)); |
| 45 |
str_.resize(str_.capacity()); |
| 46 |
base::setp(const_cast<CharT*>(str_.data()), |
| 47 |
const_cast<CharT*>(str_.data() + str_.size())); |
| 48 |
base::pbump(n+1); |
| 49 |
} |
| 50 |
return ch; |
| 51 |
} |
| 52 |
}; |
| 53 |
|
| 54 |
template <class CharT> |
| 55 |
std::basic_ios<CharT>& |
| 56 |
f(std::basic_ios<CharT>& os) |
| 57 |
{ |
| 58 |
std::uppercase(os); |
| 59 |
return os; |
| 60 |
} |
| 61 |
|
| 62 |
int main(int, char**) |
| 63 |
{ |
| 64 |
{ |
| 65 |
testbuf<char> sb; |
| 66 |
std::ostream os(&sb); |
| 67 |
assert(!(os.flags() & std::ios_base::uppercase)); |
| 68 |
os << f; |
| 69 |
assert( (os.flags() & std::ios_base::uppercase)); |
| 70 |
} |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |