1 //===----------------------------------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: libcpp-has-no-experimental-syncstream
15 // template <class charT, class traits, class Allocator>
16 // class basic_osyncstream;
18 // explicit basic_osyncstream(basic_ostream& os);
25 #include "test_macros.h"
26 #include "constexpr_char_traits.h"
27 #include "test_allocator.h"
29 template <class CharT
>
32 using OS
= std::basic_osyncstream
<CharT
>;
33 using W
= std::basic_ostringstream
<CharT
>;
35 static_assert(!std::convertible_to
<std::basic_ostream
<CharT
>&, OS
>);
36 static_assert(std::constructible_from
<OS
, std::basic_ostream
<CharT
>&>);
40 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
41 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
45 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
46 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 1);
48 assert(os
.get_wrapped() == w
.rdbuf());
49 assert(os
.rdbuf()->get_wrapped() == w
.rdbuf());
50 assert(os
.rdbuf()->get_allocator() == std::allocator
<CharT
>());
52 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
53 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
59 using OS
= std::basic_osyncstream
<CharT
, constexpr_char_traits
<CharT
>>;
60 using W
= std::basic_ostringstream
<CharT
, constexpr_char_traits
<CharT
>>;
62 static_assert(!std::convertible_to
<std::basic_ostream
<CharT
, constexpr_char_traits
<CharT
>>&, OS
>);
63 static_assert(std::constructible_from
<OS
, std::basic_ostream
<CharT
, constexpr_char_traits
<CharT
>>&>);
67 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
68 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
72 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
73 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 1);
75 assert(os
.get_wrapped() == w
.rdbuf());
76 assert(os
.rdbuf()->get_wrapped() == w
.rdbuf());
77 assert(os
.rdbuf()->get_allocator() == std::allocator
<CharT
>());
79 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
80 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
86 using OS
= std::basic_osyncstream
<CharT
, constexpr_char_traits
<CharT
>, test_allocator
<CharT
>>;
87 using W
= std::basic_ostringstream
<CharT
, constexpr_char_traits
<CharT
>, test_allocator
<CharT
>>;
89 static_assert(!std::convertible_to
<std::basic_ostream
<CharT
, constexpr_char_traits
<CharT
>>&, OS
>);
90 static_assert(std::constructible_from
<OS
, std::basic_ostream
<CharT
, constexpr_char_traits
<CharT
>>&>);
94 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
95 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
99 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
100 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 1);
102 assert(os
.get_wrapped() == w
.rdbuf());
103 assert(os
.rdbuf()->get_wrapped() == w
.rdbuf());
104 assert(os
.rdbuf()->get_allocator() == test_allocator
<CharT
>());
106 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
107 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w
.rdbuf()) == 0);
113 int main(int, char**) {
115 #ifndef TEST_HAS_NO_WIDE_CHARACTERS