brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · d131f5c Raw
78 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_stringbuf13 14// explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++2015// basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {}               // C++2016// explicit basic_stringbuf(ios_base::openmode which);                                // C++2017 18#include <sstream>19#include <cassert>20 21#include "test_macros.h"22#if TEST_STD_VER >= 1123#include "test_convertible.h"24#endif25 26template<typename CharT>27struct testbuf28    : std::basic_stringbuf<CharT>29{30    void check()31    {32      // LWG299533      //   It is implementation-defined whether the sequence pointers (eback(),34      //   gptr(), egptr(), pbase(), pptr(), epptr()) are initialized to null35      //   pointers.36      // This tests the libc++ specific implementation.37      LIBCPP_ASSERT(this->eback() != nullptr);38      LIBCPP_ASSERT(this->gptr() != nullptr);39      LIBCPP_ASSERT(this->egptr() != nullptr);40      LIBCPP_ASSERT(this->pbase() != nullptr);41      LIBCPP_ASSERT(this->pptr() != nullptr);42      LIBCPP_ASSERT(this->epptr() != nullptr);43      assert(this->str().empty());44    }45};46 47int main(int, char**)48{49    {50        std::stringbuf buf;51        assert(buf.str() == "");52    }53    {54        testbuf<char> buf;55        buf.check();56    }57#ifndef TEST_HAS_NO_WIDE_CHARACTERS58    {59        std::wstringbuf buf;60        assert(buf.str() == L"");61    }62    {63        testbuf<wchar_t> buf;64        buf.check();65    }66#endif67 68#if TEST_STD_VER >= 1169    {70      typedef std::stringbuf B;71      static_assert(test_convertible<B>(), "");72      static_assert(!test_convertible<B, std::ios_base::openmode>(), "");73    }74#endif75 76    return 0;77}78