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 //===----------------------------------------------------------------------===// 8 9 // <ostream> 10 11 // template <class charT, class traits = char_traits<charT> > 12 // class basic_ostream; 13 14 // basic_ostream& operator=(basic_ostream&& rhs); 15 16 #include <ostream> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 22 template <class CharT> 23 struct testbuf 24 : public std::basic_streambuf<CharT> 25 { 26 testbuf() {} 27 }; 28 29 template <class CharT> 30 struct 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 40 41 int main(int, char**) 42 { 43 { 44 testbuf<char> sb1; 45 testbuf<char> sb2; 46 test_ostream<char> os1(&sb1); 47 test_ostream<char> os2(&sb2); 48 os2 = (std::move(os1)); 49 assert(os1.rdbuf() == &sb1); 50 assert(os1.tie() == 0); 51 assert(os1.fill() == ' '); 52 assert(os1.rdstate() == os1.goodbit); 53 assert(os1.exceptions() == os1.goodbit); 54 assert(os1.flags() == (os1.skipws | os1.dec)); 55 assert(os1.precision() == 6); 56 assert(os1.getloc().name() == "C"); 57 assert(os2.rdbuf() == &sb2); 58 assert(os2.tie() == 0); 59 assert(os2.fill() == ' '); 60 assert(os2.rdstate() == os2.goodbit); 61 assert(os2.exceptions() == os2.goodbit); 62 assert(os2.flags() == (os2.skipws | os2.dec)); 63 assert(os2.precision() == 6); 64 assert(os2.getloc().name() == "C"); 65 } 66 { 67 testbuf<wchar_t> sb1; 68 testbuf<wchar_t> sb2; 69 test_ostream<wchar_t> os1(&sb1); 70 test_ostream<wchar_t> os2(&sb2); 71 os2 = (std::move(os1)); 72 assert(os1.rdbuf() == &sb1); 73 assert(os1.tie() == 0); 74 assert(os1.fill() == ' '); 75 assert(os1.rdstate() == os1.goodbit); 76 assert(os1.exceptions() == os1.goodbit); 77 assert(os1.flags() == (os1.skipws | os1.dec)); 78 assert(os1.precision() == 6); 79 assert(os1.getloc().name() == "C"); 80 assert(os2.rdbuf() == &sb2); 81 assert(os2.tie() == 0); 82 assert(os2.fill() == ' '); 83 assert(os2.rdstate() == os2.goodbit); 84 assert(os2.exceptions() == os2.goodbit); 85 assert(os2.flags() == (os2.skipws | os2.dec)); 86 assert(os2.precision() == 6); 87 assert(os2.getloc().name() == "C"); 88 } 89 90 return 0; 91 } 92