96 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_ostringstream13 14// explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++2015// basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++2016// explicit basic_ostringstream(ios_base::openmode which); // C++2017 18#include <sstream>19#include <cassert>20 21#include "operator_hijacker.h"22#include "test_macros.h"23#if TEST_STD_VER >= 1124#include "test_convertible.h"25 26template <typename S>27void test() {28 static_assert(test_convertible<S>(), "");29 static_assert(!test_convertible<S, std::ios_base::openmode>(), "");30}31#endif32 33int main(int, char**)34{35 {36 std::ostringstream ss;37 assert(ss.rdbuf() != nullptr);38 assert(ss.good());39 assert(ss.str() == "");40 }41 {42 std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss;43 assert(ss.rdbuf() != nullptr);44 assert(ss.good());45 assert(ss.str() == "");46 }47 {48 std::ostringstream ss(std::ios_base::out);49 assert(ss.rdbuf() != nullptr);50 assert(ss.good());51 assert(ss.str() == "");52 }53 {54 std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::ios_base::out);55 assert(ss.rdbuf() != nullptr);56 assert(ss.good());57 assert(ss.str() == "");58 }59#ifndef TEST_HAS_NO_WIDE_CHARACTERS60 {61 std::wostringstream ss;62 assert(ss.rdbuf() != nullptr);63 assert(ss.good());64 assert(ss.str() == L"");65 }66 {67 std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss;68 assert(ss.rdbuf() != nullptr);69 assert(ss.good());70 assert(ss.str() == L"");71 }72 {73 std::wostringstream ss(std::ios_base::out);74 assert(ss.rdbuf() != nullptr);75 assert(ss.good());76 assert(ss.str() == L"");77 }78 {79 std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(80 std::ios_base::out);81 assert(ss.rdbuf() != nullptr);82 assert(ss.good());83 assert(ss.str() == L"");84 }85#endif // TEST_HAS_NO_WIDE_CHARACTERS86 87#if TEST_STD_VER >= 1188 test<std::ostringstream>();89# ifndef TEST_HAS_NO_WIDE_CHARACTERS90 test<std::wostringstream>();91# endif92#endif93 94 return 0;95}96