xref: /llvm-project/libcxx/test/std/input.output/syncstream/osyncstream/members/emit.pass.cpp (revision 7cc72a0a2ec22855572d96411febd4f2c4ac5a49)
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: libcpp-has-no-experimental-syncstream
12 
13 // <syncstream>
14 
15 // template <class charT, class traits, class Allocator>
16 // class basic_osyncstream;
17 
18 // void emit();
19 
20 #include <syncstream>
21 #include <sstream>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 template <class CharT>
test()27 void test() {
28   using OS = std::basic_osyncstream<CharT>;
29   using SS = std::basic_ostringstream<CharT>;
30   CharT c  = 'f';
31 
32   SS ss;
33   OS out(ss);
34   out << c;
35   assert(ss.str().empty());
36   out.emit();
37   assert(ss.str()[0] == c);
38 }
39 
main(int,char **)40 int main(int, char**) {
41   test<char>();
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
43   test<wchar_t>();
44 #endif
45 }
46