Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <ostream> |
| 11 | |
| 12 | // template <class charT, class traits = char_traits<charT> > |
| 13 | // class basic_ostream; |
| 14 | |
Howard Hinnant | 256813f | 2010-08-22 00:26:48 +0000 | [diff] [blame] | 15 | // template <class charT, class traits, class T> |
| 16 | // basic_ostream<charT, traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 17 | // operator<<(basic_ostream<charT, traits>&& os, const T& x); |
| 18 | |
| 19 | #include <ostream> |
| 20 | #include <cassert> |
| 21 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 22 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
| 24 | template <class CharT> |
| 25 | class testbuf |
| 26 | : public std::basic_streambuf<CharT> |
| 27 | { |
| 28 | typedef std::basic_streambuf<CharT> base; |
| 29 | std::basic_string<CharT> str_; |
| 30 | public: |
| 31 | testbuf() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | std::basic_string<CharT> str() const |
| 36 | {return std::basic_string<CharT>(base::pbase(), base::pptr());} |
| 37 | |
| 38 | protected: |
| 39 | |
| 40 | virtual typename base::int_type |
| 41 | overflow(typename base::int_type __c = base::traits_type::eof()) |
| 42 | { |
| 43 | if (__c != base::traits_type::eof()) |
| 44 | { |
| 45 | int n = str_.size(); |
| 46 | str_.push_back(__c); |
| 47 | str_.resize(str_.capacity()); |
| 48 | base::setp(const_cast<CharT*>(str_.data()), |
| 49 | const_cast<CharT*>(str_.data() + str_.size())); |
| 50 | base::pbump(n+1); |
| 51 | } |
| 52 | return __c; |
| 53 | } |
| 54 | }; |
| 55 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 56 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | |
| 58 | int main() |
| 59 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 60 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | { |
| 62 | testbuf<char> sb; |
| 63 | std::ostream(&sb) << "testing..."; |
| 64 | assert(sb.str() == "testing..."); |
| 65 | } |
| 66 | { |
| 67 | testbuf<wchar_t> sb; |
| 68 | std::wostream(&sb) << L"123"; |
| 69 | assert(sb.str() == L"123"); |
| 70 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 71 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | } |