brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 0702d9a Raw
87 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// <sstream>10 11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >12// class basic_stringstream13 14// basic_stringstream(basic_stringstream&& rhs);15 16#include <sstream>17#include <cassert>18 19#include "test_macros.h"20#include "operator_hijacker.h"21 22int main(int, char**)23{24    {25        std::stringstream ss0(" 123 456 ");26        std::stringstream ss(std::move(ss0));27        assert(ss.rdbuf() != nullptr);28        assert(ss.good());29        assert(ss.str() == " 123 456 ");30        int i = 0;31        ss >> i;32        assert(i == 123);33        ss >> i;34        assert(i == 456);35        ss << i << ' ' << 123;36        assert(ss.str() == "456 1236 ");37    }38    {39      std::basic_stringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss0(" 123 456 ");40      std::basic_stringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::move(ss0));41      assert(ss.rdbuf() != nullptr);42      assert(ss.good());43      assert(ss.str() == " 123 456 ");44      int i = 0;45      ss >> i;46      assert(i == 123);47      ss >> i;48      assert(i == 456);49      ss << i << ' ' << 123;50      assert(ss.str() == "456 1236 ");51    }52#ifndef TEST_HAS_NO_WIDE_CHARACTERS53    {54        std::wstringstream ss0(L" 123 456 ");55        std::wstringstream ss(std::move(ss0));56        assert(ss.rdbuf() != nullptr);57        assert(ss.good());58        assert(ss.str() == L" 123 456 ");59        int i = 0;60        ss >> i;61        assert(i == 123);62        ss >> i;63        assert(i == 456);64        ss << i << ' ' << 123;65        assert(ss.str() == L"456 1236 ");66    }67    {68      std::basic_stringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss0(69          L" 123 456 ");70      std::basic_stringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(71          std::move(ss0));72      assert(ss.rdbuf() != nullptr);73      assert(ss.good());74      assert(ss.str() == L" 123 456 ");75      int i = 0;76      ss >> i;77      assert(i == 123);78      ss >> i;79      assert(i == 456);80      ss << i << ' ' << 123;81      assert(ss.str() == L"456 1236 ");82    }83#endif84 85  return 0;86}87