brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 40528f1 Raw
60 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// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <sstream>12 13// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>14// class basic_stringstream15 16// explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, ios_base::openmode which = ios_base::out | ios_base::in);17 18#include <sstream>19#include <cassert>20 21#include "make_string.h"22#include "test_macros.h"23#include "operator_hijacker.h"24 25#define STR(S) MAKE_STRING(CharT, S)26#define SV(S) MAKE_STRING_VIEW(CharT, S)27 28template <class CharT>29static void test() {30  {31    std::basic_string<CharT> s(STR("testing"));32    const std::basic_stringstream<CharT> ss(std::move(s));33    assert(ss.str() == SV("testing"));34  }35  {36    std::basic_string<CharT, std::char_traits<CharT>, operator_hijacker_allocator<CharT>> s(STR("testing"));37    const std::basic_stringstream<CharT, std::char_traits<CharT>, operator_hijacker_allocator<CharT>> ss(std::move(s));38    assert(ss.str() == SV("testing"));39  }40  {41    std::basic_string<CharT> s(STR("testing"));42    const std::basic_stringstream<CharT> ss(std::move(s), std::ios_base::out);43    assert(ss.str() == SV("testing"));44  }45  {46    std::basic_string<CharT, std::char_traits<CharT>, operator_hijacker_allocator<CharT>> s(STR("testing"));47    const std::basic_stringstream<CharT, std::char_traits<CharT>, operator_hijacker_allocator<CharT>> ss(48        std::move(s), std::ios_base::out);49    assert(ss.str() == SV("testing"));50  }51}52 53int main(int, char**) {54  test<char>();55#ifndef TEST_HAS_NO_WIDE_CHARACTERS56  test<wchar_t>();57#endif58  return 0;59}60