//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 // // template , class Allocator = allocator> // class basic_stringstream // template // basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); #include #include #include #include #include #include #include "constexpr_char_traits.h" #include "nasty_string.h" #include "test_allocator.h" #include "test_convertible.h" #include "test_macros.h" #include "../../helper_string_macros.h" #include "../../helper_types.h" template > void test_sfinae_with_nasty_char() { // nasty_char* using NStrStream = std::basic_stringstream>; static_assert(std::constructible_from>); static_assert(test_convertible>()); // const nasty_char* static_assert(std::constructible_from>); static_assert( test_convertible>()); } template , typename AllocT = std::allocator> void test_sfinae() { using StrStream = std::basic_stringstream; // `CharT*` static_assert(std::constructible_from); static_assert(test_convertible()); // `const CharT*` static_assert(std::constructible_from); static_assert(test_convertible()); // `std::basic_string_view` static_assert(std::constructible_from, std::ios_base::openmode, const AllocT>); static_assert(test_convertible, std::ios_base::openmode, const AllocT>()); // `std::basic_string` static_assert(std::constructible_from, std::ios_base::openmode, const AllocT>); static_assert( test_convertible, std::ios_base::openmode, const AllocT>()); // ConstConvertibleStringView static_assert(std::constructible_from, std::ios_base::openmode, const AllocT>); static_assert(test_convertible, std::ios_base::openmode, const AllocT>()); // NonConstConvertibleStringView static_assert(!std::constructible_from, std::ios_base::openmode, const AllocT>); static_assert(!test_convertible, std::ios_base::openmode, const AllocT>()); static_assert(!std::constructible_from, std::ios_base::openmode, const AllocT>); static_assert(!test_convertible, std::ios_base::openmode, const AllocT>()); // Non-`string-view-like` static_assert(!std::constructible_from); static_assert(!test_convertible()); static_assert(!std::constructible_from); static_assert(!test_convertible()); // Non-mode static_assert( !std::constructible_from, NonMode, const NonAllocator>); static_assert( !test_convertible, NonMode, const NonAllocator>()); // Non-allocator static_assert(!std::constructible_from, std::ios_base::openmode, const NonAllocator>); static_assert(!test_convertible, std::ios_base::openmode, const NonAllocator>()); } template , typename AllocT = std::allocator> void test() { using StrStream = std::basic_stringstream; const AllocT allocator; // const CharT* { StrStream ss(CS("zmt"), std::ios_base::out | std::ios_base::in, allocator); assert(ss.str() == CS("zmt")); assert(ss.rdbuf()->get_allocator() == allocator); } // std::basic_string_view { const std::basic_string_view csv = SV("zmt"); StrStream ss(csv, std::ios_base::out | std::ios_base::in, allocator); assert(ss.str() == CS("zmt")); assert(ss.rdbuf()->get_allocator() == allocator); } // std::basic_string { const std::basic_string cs = ST("zmt", allocator); StrStream ss(cs, std::ios_base::out | std::ios_base::in, allocator); assert(ss.str() == CS("zmt")); assert(ss.rdbuf()->get_allocator() == allocator); } // ConstConvertibleStringView { const ConstConvertibleStringView sv{CS("zmt")}; StrStream ss(sv, std::ios_base::out | std::ios_base::in, allocator); assert(ss.str() == CS("zmt")); assert(ss.rdbuf()->get_allocator() == allocator); } } int main(int, char**) { test_sfinae_with_nasty_char(); test_sfinae_with_nasty_char>(); test_sfinae(); test_sfinae, std::allocator>(); test_sfinae, test_allocator>(); test_sfinae, test_allocator>(); test(); test, std::allocator>(); test, test_allocator>(); test, test_allocator>(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS test_sfinae(); test_sfinae, std::allocator>(); test_sfinae, test_allocator>(); test_sfinae, test_allocator>(); test(); test, std::allocator>(); test, test_allocator>(); test, test_allocator>(); #endif return 0; }