1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class Stream, class T>
12 // Stream&& operator>>(Stream&& is, T&& x);
18 #include "test_macros.h"
20 template <class CharT
>
22 : public std::basic_streambuf
<CharT
>
24 typedef std::basic_string
<CharT
> string_type
;
25 typedef std::basic_streambuf
<CharT
> base
;
31 testbuf(const string_type
& 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();}
46 template <class CharT
>
47 friend void operator>>(std::basic_istream
<CharT
>& is
, Int
& self
) {
54 void operator>>(std::istream
&, A
&&) { called
= true; }
59 testbuf
<char> sb(" 123");
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");
70 std::wistream
is(&sb
);
71 std::wistream
&& result
= (std::move(is
) >> i
);
72 assert(&result
== &is
);
73 assert(i
.value
== 123);
77 // test perfect forwarding
78 assert(called
== false);
79 std::istringstream ss
;
80 std::istringstream
&& result
= (std::move(ss
) >> A());
81 assert(&result
== &ss
);