brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · dbac838 Raw
94 lines · cpp
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-exception6//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 22template <class CharT>23struct testbuf24    : public std::basic_streambuf<CharT>25{26    testbuf() {}27};28 29template <class CharT>30struct test_ostream31    : 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 41int 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#ifndef TEST_HAS_NO_WIDE_CHARACTERS67    {68        testbuf<wchar_t> sb1;69        testbuf<wchar_t> sb2;70        test_ostream<wchar_t> os1(&sb1);71        test_ostream<wchar_t> os2(&sb2);72        os2 = (std::move(os1));73        assert(os1.rdbuf() == &sb1);74        assert(os1.tie() == 0);75        assert(os1.fill() == ' ');76        assert(os1.rdstate() == os1.goodbit);77        assert(os1.exceptions() == os1.goodbit);78        assert(os1.flags() == (os1.skipws | os1.dec));79        assert(os1.precision() == 6);80        assert(os1.getloc().name() == "C");81        assert(os2.rdbuf() == &sb2);82        assert(os2.tie() == 0);83        assert(os2.fill() == ' ');84        assert(os2.rdstate() == os2.goodbit);85        assert(os2.exceptions() == os2.goodbit);86        assert(os2.flags() == (os2.skipws | os2.dec));87        assert(os2.precision() == 6);88        assert(os2.getloc().name() == "C");89    }90#endif91 92  return 0;93}94