brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 3fc0967 Raw
90 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_istringstream13 14// basic_istringstream& operator=(basic_istringstream&& rhs);15 16#include <sstream>17#include <cassert>18 19#include "test_macros.h"20 21int main(int, char**)22{23    {24        std::istringstream ss0(" 123 456");25        std::istringstream ss;26        ss = std::move(ss0);27        assert(ss.rdbuf() != 0);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    }36    {37        std::istringstream s1("Aaaaa Bbbbb Cccccccccc Dddddddddddddddddd");38        std::string s;39        s1 >> s;40 41        std::istringstream s2 = std::move(s1);42        s2 >> s;43        assert(s == "Bbbbb");44 45        std::istringstream s3;46        s3 = std::move(s2);47        s3 >> s;48        assert(s == "Cccccccccc");49 50        s1 = std::move(s3);51        s1 >> s;52        assert(s == "Dddddddddddddddddd");53    }54#ifndef TEST_HAS_NO_WIDE_CHARACTERS55    {56        std::wistringstream ss0(L" 123 456");57        std::wistringstream ss;58        ss = std::move(ss0);59        assert(ss.rdbuf() != 0);60        assert(ss.good());61        assert(ss.str() == L" 123 456");62        int i = 0;63        ss >> i;64        assert(i == 123);65        ss >> i;66        assert(i == 456);67    }68    {69        std::wistringstream s1(L"Aaaaa Bbbbb Cccccccccc Dddddddddddddddddd");70        std::wstring s;71        s1 >> s;72 73        std::wistringstream s2 = std::move(s1);74        s2 >> s;75        assert(s == L"Bbbbb");76 77        std::wistringstream s3;78        s3 = std::move(s2);79        s3 >> s;80        assert(s == L"Cccccccccc");81 82        s1 = std::move(s3);83        s1 >> s;84        assert(s == L"Dddddddddddddddddd");85    }86#endif // TEST_HAS_NO_WIDE_CHARACTERS87 88  return 0;89}90