blob: 37a7489458e7ddb3d24591eb9b800e6dde46e3bc [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
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 Hinnant256813f2010-08-22 00:26:48 +000012// template <class charT, class traits, class T>
13// basic_istream<charT, traits>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014// operator>>(basic_istream<charT, traits>&& is, T& x);
15
16#include <istream>
17#include <cassert>
18
Howard Hinnant73d21a42010-09-04 23:28:19 +000019#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020
21template <class CharT>
22struct testbuf
23 : public std::basic_streambuf<CharT>
24{
25 typedef std::basic_string<CharT> string_type;
26 typedef std::basic_streambuf<CharT> base;
27private:
28 string_type str_;
29public:
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 Hinnant73d21a42010-09-04 23:28:19 +000045#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000046
47int main()
48{
Howard Hinnant73d21a42010-09-04 23:28:19 +000049#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050 {
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 Hinnant73d21a42010-09-04 23:28:19 +000062#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063}