blob: 67f272e5a447159de3f303c9f1fcc6ddf379e81b [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// <ostream>
11
12// template <class charT, class traits = char_traits<charT> >
13// class basic_ostream;
14
15// basic_ostream& operator=(basic_ostream&& rhs);
16
17#include <ostream>
18#include <cassert>
19
Howard Hinnant73d21a42010-09-04 23:28:19 +000020#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22template <class CharT>
23struct testbuf
24 : public std::basic_streambuf<CharT>
25{
26 testbuf() {}
27};
28
29template <class CharT>
30struct test_ostream
31 : public std::basic_ostream<CharT>
32{
33 typedef std::basic_ostream<CharT> base;
34 test_ostream(testbuf<CharT>* sb) : base(sb) {}
35
36 test_ostream& operator=(test_ostream&& s)
37 {base::operator=(std::move(s)); return *this;}
38};
39
Howard Hinnant73d21a42010-09-04 23:28:19 +000040#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041
42int main()
43{
Howard Hinnant73d21a42010-09-04 23:28:19 +000044#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 {
46 testbuf<char> sb1;
47 testbuf<char> sb2;
48 test_ostream<char> os1(&sb1);
49 test_ostream<char> os2(&sb2);
50 os2 = (std::move(os1));
51 assert(os1.rdbuf() == &sb1);
52 assert(os1.tie() == 0);
53 assert(os1.fill() == ' ');
54 assert(os1.rdstate() == os1.goodbit);
55 assert(os1.exceptions() == os1.goodbit);
56 assert(os1.flags() == (os1.skipws | os1.dec));
57 assert(os1.precision() == 6);
58 assert(os1.getloc().name() == "C");
59 assert(os2.rdbuf() == &sb2);
60 assert(os2.tie() == 0);
61 assert(os2.fill() == ' ');
62 assert(os2.rdstate() == os2.goodbit);
63 assert(os2.exceptions() == os2.goodbit);
64 assert(os2.flags() == (os2.skipws | os2.dec));
65 assert(os2.precision() == 6);
66 assert(os2.getloc().name() == "C");
67 }
68 {
69 testbuf<wchar_t> sb1;
70 testbuf<wchar_t> sb2;
71 test_ostream<wchar_t> os1(&sb1);
72 test_ostream<wchar_t> os2(&sb2);
73 os2 = (std::move(os1));
74 assert(os1.rdbuf() == &sb1);
75 assert(os1.tie() == 0);
76 assert(os1.fill() == ' ');
77 assert(os1.rdstate() == os1.goodbit);
78 assert(os1.exceptions() == os1.goodbit);
79 assert(os1.flags() == (os1.skipws | os1.dec));
80 assert(os1.precision() == 6);
81 assert(os1.getloc().name() == "C");
82 assert(os2.rdbuf() == &sb2);
83 assert(os2.tie() == 0);
84 assert(os2.fill() == ' ');
85 assert(os2.rdstate() == os2.goodbit);
86 assert(os2.exceptions() == os2.goodbit);
87 assert(os2.flags() == (os2.skipws | os2.dec));
88 assert(os2.precision() == 6);
89 assert(os2.getloc().name() == "C");
90 }
Howard Hinnant73d21a42010-09-04 23:28:19 +000091#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092}