//===----------------------------------------------------------------------===// // // 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_stringbuf // template // basic_stringbuf(const T& t, 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 NStrBuf = std::basic_istringstream; 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 StrBuf = std::basic_stringbuf; // `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, const AllocT>); static_assert(test_convertible, const AllocT>()); // `std::basic_string` static_assert(std::constructible_from, const AllocT>); static_assert(test_convertible, const AllocT>()); // ConstConvertibleStringView static_assert(std::constructible_from, const AllocT>); static_assert(test_convertible, const AllocT>()); // NonConstConvertibleStringView static_assert(!std::constructible_from, const AllocT>); static_assert(!test_convertible, const AllocT>()); static_assert(!std::constructible_from, const AllocT>); static_assert(!test_convertible, const AllocT>()); // Non-`string-view-like` static_assert(!std::constructible_from); static_assert(!test_convertible()); // Non-allocator static_assert(!std::constructible_from, const NonAllocator>); static_assert(!test_convertible, const NonAllocator>()); } template , typename AllocT = std::allocator> void test() { using StrBuf = std::basic_stringbuf; const AllocT allocator; // const CharT* { StrBuf ss(CS("zmt"), allocator); assert(ss.str() == CS("zmt")); assert(ss.get_allocator() == allocator); } // std::basic_string_view { const std::basic_string_view csv = SV("zmt"); StrBuf ss(csv, allocator); assert(ss.str() == CS("zmt")); assert(ss.get_allocator() == allocator); } // std::basic_string { const std::basic_string cs = ST("zmt", allocator); StrBuf ss(cs, allocator); assert(ss.str() == CS("zmt")); assert(ss.get_allocator() == allocator); } // ConstConvertibleStringView { const ConstConvertibleStringView sv{CS("zmt")}; StrBuf ss(sv, allocator); assert(ss.str() == CS("zmt")); assert(ss.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; }