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 | // <istream> |
| 11 | |
Howard Hinnant | 256813f | 2010-08-22 00:26:48 +0000 | [diff] [blame] | 12 | // template <class charT, class traits, class T> |
| 13 | // basic_istream<charT, traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | // operator>>(basic_istream<charT, traits>&& is, T& x); |
| 15 | |
| 16 | #include <istream> |
| 17 | #include <cassert> |
| 18 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 19 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | |
| 21 | template <class CharT> |
| 22 | struct testbuf |
| 23 | : public std::basic_streambuf<CharT> |
| 24 | { |
| 25 | typedef std::basic_string<CharT> string_type; |
| 26 | typedef std::basic_streambuf<CharT> base; |
| 27 | private: |
| 28 | string_type str_; |
| 29 | public: |
| 30 | |
| 31 | testbuf() {} |
| 32 | testbuf(const string_type& str) |
| 33 | : str_(str) |
| 34 | { |
| 35 | base::setg(const_cast<CharT*>(str_.data()), |
| 36 | const_cast<CharT*>(str_.data()), |
| 37 | const_cast<CharT*>(str_.data()) + str_.size()); |
| 38 | } |
| 39 | |
| 40 | CharT* eback() const {return base::eback();} |
| 41 | CharT* gptr() const {return base::gptr();} |
| 42 | CharT* egptr() const {return base::egptr();} |
| 43 | }; |
| 44 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 45 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | |
| 47 | int main() |
| 48 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 49 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 50 | { |
| 51 | testbuf<char> sb(" 123"); |
| 52 | int i = 0; |
| 53 | std::istream(&sb) >> i; |
| 54 | assert(i == 123); |
| 55 | } |
| 56 | { |
| 57 | testbuf<wchar_t> sb(L" 123"); |
| 58 | int i = 0; |
| 59 | std::wistream(&sb) >> i; |
| 60 | assert(i == 123); |
| 61 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 62 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | } |