brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 120a8ea 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_stringbuf15 16// explicit basic_stringbuf(basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::in | ios_base::out);17 18#include <sstream>19#include <cassert>20 21#include "make_string.h"22#include "test_allocator.h"23#include "test_macros.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_stringbuf<CharT> buf(std::move(s));33    assert(buf.view() == SV("testing"));34  }35  {36    std::basic_string<CharT> s(STR("testing"));37    const std::basic_stringbuf<CharT> buf(std::move(s), std::ios_base::out);38    assert(buf.view() == SV("testing"));39  }40  {41    std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"));42    const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> buf(std::move(s));43    assert(buf.view() == SV("testing"));44  }45  {46    std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"));47    const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> buf(48        std::move(s), std::ios_base::in);49    assert(buf.view() == 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