brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 8c73df4 Raw
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_istringstream13 14// explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++2015// basic_istringstream() : basic_istringstream(ios_base::in) {}           // C++2016// explicit basic_istringstream(ios_base::openmode which);                // C++2017 18#include <sstream>19#include <cassert>20 21#include "test_macros.h"22#include "operator_hijacker.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::istringstream ss;37        assert(ss.rdbuf() != nullptr);38        assert(ss.good());39        assert(ss.str() == "");40    }41    {42      std::basic_istringstream<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::istringstream ss(std::ios_base::in);49        assert(ss.rdbuf() != nullptr);50        assert(ss.good());51        assert(ss.str() == "");52    }53    {54      std::basic_istringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::ios_base::in);55      assert(ss.rdbuf() != nullptr);56      assert(ss.good());57      assert(ss.str() == "");58    }59#ifndef TEST_HAS_NO_WIDE_CHARACTERS60    {61        std::wistringstream ss;62        assert(ss.rdbuf() != nullptr);63        assert(ss.good());64        assert(ss.str() == L"");65    }66    {67        std::wistringstream ss(std::ios_base::in);68        assert(ss.rdbuf() != nullptr);69        assert(ss.good());70        assert(ss.str() == L"");71    }72    {73      std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss;74      assert(ss.rdbuf() != nullptr);75      assert(ss.good());76      assert(ss.str() == L"");77    }78    {79      std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(80          std::ios_base::in);81      assert(ss.rdbuf() != nullptr);82      assert(ss.good());83      assert(ss.str() == L"");84    }85#endif86 87#if TEST_STD_VER >= 1188    test<std::istringstream>();89#  ifndef TEST_HAS_NO_WIDE_CHARACTERS90    test<std::wistringstream>();91#   endif92#endif93 94    return 0;95}96