[libc++][doc] Updates format status.
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.rvalue / rvalue.pass.cpp
blob23ad80eddb8f82421c61520223bad1a871b42cd6
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 //===----------------------------------------------------------------------===//
9 // <istream>
11 // template <class Stream, class T>
12 // Stream&& operator>>(Stream&& is, T&& x);
14 #include <istream>
15 #include <sstream>
16 #include <cassert>
18 #include "test_macros.h"
20 template <class CharT>
21 struct testbuf
22 : public std::basic_streambuf<CharT>
24 typedef std::basic_string<CharT> string_type;
25 typedef std::basic_streambuf<CharT> base;
26 private:
27 string_type str_;
28 public:
30 testbuf() {}
31 testbuf(const string_type& str)
32 : str_(str)
34 base::setg(const_cast<CharT*>(str_.data()),
35 const_cast<CharT*>(str_.data()),
36 const_cast<CharT*>(str_.data()) + str_.size());
39 CharT* eback() const {return base::eback();}
40 CharT* gptr() const {return base::gptr();}
41 CharT* egptr() const {return base::egptr();}
44 struct Int {
45 int value;
46 template <class CharT>
47 friend void operator>>(std::basic_istream<CharT>& is, Int& self) {
48 is >> self.value;
52 struct A { };
53 bool called = false;
54 void operator>>(std::istream&, A&&) { called = true; }
56 int main(int, char**)
59 testbuf<char> sb(" 123");
60 Int i = {0};
61 std::istream is(&sb);
62 std::istream&& result = (std::move(is) >> i);
63 assert(&result == &is);
64 assert(i.value == 123);
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
68 testbuf<wchar_t> sb(L" 123");
69 Int i = {0};
70 std::wistream is(&sb);
71 std::wistream&& result = (std::move(is) >> i);
72 assert(&result == &is);
73 assert(i.value == 123);
75 #endif
77 // test perfect forwarding
78 assert(called == false);
79 std::istringstream ss;
80 std::istringstream&& result = (std::move(ss) >> A());
81 assert(&result == &ss);
82 assert(called);
85 return 0;