move.pass.cpp revision 73d21a4f0774d3fadab98e690619a359cfb160a3
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
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
12// template <class charT, class traits = char_traits<charT> >
13// class basic_istream;
14
15// basic_istream(basic_istream&& rhs);
16
17#include <istream>
18#include <cassert>
19
20#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21
22template <class CharT>
23struct testbuf
24    : public std::basic_streambuf<CharT>
25{
26    testbuf() {}
27};
28
29template <class CharT>
30struct test_istream
31    : public std::basic_istream<CharT>
32{
33    typedef std::basic_istream<CharT> base;
34    test_istream(testbuf<CharT>* sb) : base(sb) {}
35
36    test_istream(test_istream&& s)
37        : base(std::move(s)) {}
38};
39
40#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
41
42int main()
43{
44#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
45    {
46        testbuf<char> sb;
47        test_istream<char> is1(&sb);
48        test_istream<char> is(std::move(is1));
49        assert(is1.rdbuf() == &sb);
50        assert(is1.gcount() == 0);
51        assert(is.gcount() == 0);
52        assert(is.rdbuf() == 0);
53        assert(is.tie() == 0);
54        assert(is.fill() == ' ');
55        assert(is.rdstate() == is.goodbit);
56        assert(is.exceptions() == is.goodbit);
57        assert(is.flags() == (is.skipws | is.dec));
58        assert(is.precision() == 6);
59        assert(is.getloc().name() == "C");
60    }
61    {
62        testbuf<wchar_t> sb;
63        test_istream<wchar_t> is1(&sb);
64        test_istream<wchar_t> is(std::move(is1));
65        assert(is1.gcount() == 0);
66        assert(is.gcount() == 0);
67        assert(is1.rdbuf() == &sb);
68        assert(is.rdbuf() == 0);
69        assert(is.tie() == 0);
70        assert(is.fill() == L' ');
71        assert(is.rdstate() == is.goodbit);
72        assert(is.exceptions() == is.goodbit);
73        assert(is.flags() == (is.skipws | is.dec));
74        assert(is.precision() == 6);
75        assert(is.getloc().name() == "C");
76    }
77#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
78}
79