libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

move_assign.pass.cpp (2699B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <istream>
     13 
     14 // template <class charT, class traits = char_traits<charT> >
     15 // class basic_iostream;
     16 
     17 // basic_iostream& operator=(basic_iostream&& rhs);
     18 
     19 #include <istream>
     20 #include <cassert>
     21 
     22 
     23 template <class CharT>
     24 struct testbuf
     25     : public std::basic_streambuf<CharT>
     26 {
     27     testbuf() {}
     28 };
     29 
     30 template <class CharT>
     31 struct test_iostream
     32     : public std::basic_iostream<CharT>
     33 {
     34     typedef std::basic_iostream<CharT> base;
     35     test_iostream(testbuf<CharT>* sb) : base(sb) {}
     36 
     37     test_iostream& operator=(test_iostream&& s)
     38         {base::operator=(std::move(s)); return *this;}
     39 };
     40 
     41 
     42 int main()
     43 {
     44     {
     45         testbuf<char> sb1;
     46         testbuf<char> sb2;
     47         test_iostream<char> is1(&sb1);
     48         test_iostream<char> is2(&sb2);
     49         is2 = (std::move(is1));
     50         assert(is1.rdbuf() == &sb1);
     51         assert(is1.tie() == 0);
     52         assert(is1.fill() == ' ');
     53         assert(is1.rdstate() == is1.goodbit);
     54         assert(is1.exceptions() == is1.goodbit);
     55         assert(is1.flags() == (is1.skipws | is1.dec));
     56         assert(is1.precision() == 6);
     57         assert(is1.getloc().name() == "C");
     58         assert(is2.rdbuf() == &sb2);
     59         assert(is2.tie() == 0);
     60         assert(is2.fill() == ' ');
     61         assert(is2.rdstate() == is2.goodbit);
     62         assert(is2.exceptions() == is2.goodbit);
     63         assert(is2.flags() == (is2.skipws | is2.dec));
     64         assert(is2.precision() == 6);
     65         assert(is2.getloc().name() == "C");
     66     }
     67     {
     68         testbuf<wchar_t> sb1;
     69         testbuf<wchar_t> sb2;
     70         test_iostream<wchar_t> is1(&sb1);
     71         test_iostream<wchar_t> is2(&sb2);
     72         is2 = (std::move(is1));
     73         assert(is1.rdbuf() == &sb1);
     74         assert(is1.tie() == 0);
     75         assert(is1.fill() == ' ');
     76         assert(is1.rdstate() == is1.goodbit);
     77         assert(is1.exceptions() == is1.goodbit);
     78         assert(is1.flags() == (is1.skipws | is1.dec));
     79         assert(is1.precision() == 6);
     80         assert(is1.getloc().name() == "C");
     81         assert(is2.rdbuf() == &sb2);
     82         assert(is2.tie() == 0);
     83         assert(is2.fill() == ' ');
     84         assert(is2.rdstate() == is2.goodbit);
     85         assert(is2.exceptions() == is2.goodbit);
     86         assert(is2.flags() == (is2.skipws | is2.dec));
     87         assert(is2.precision() == 6);
     88         assert(is2.getloc().name() == "C");
     89     }
     90 }