1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <istream>
11 
12 // template <class charT, class traits, class T>
13 //   basic_istream<charT, traits>&
14 //   operator>>(basic_istream<charT, traits>&& is, T& x);
15 
16 #include <istream>
17 #include <cassert>
18 
19 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 
testbuftestbuf31     testbuf() {}
testbuftestbuf32     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 
ebacktestbuf40     CharT* eback() const {return base::eback();}
gptrtestbuf41     CharT* gptr() const {return base::gptr();}
egptrtestbuf42     CharT* egptr() const {return base::egptr();}
43 };
44 
45 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
46 
main()47 int main()
48 {
49 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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     }
62 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
63 }
64