[libcxx-commits] [libcxx] [libc++] Implement p0753r2 Manipulators for C++ Synchronized Buffered Ostream (PR #97955)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 12 09:05:12 PDT 2024


================
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: libcpp-has-no-experimental-syncstream
+
+// template<class charT, class traits>
+// basic_ostream<charT, traits>& noemit_on_flush(basic_ostream<charT, traits>& os);
+
+#include <cassert>
+#include <ostream>
+#include <sstream>
+#include <syncstream>
+
+template <class CharT>
+void test_noemit_on_flush() {
+  {
+    // non sync stream: nothing happens
+    std::basic_ostringstream<CharT> os;
+    std::noemit_on_flush(os);
+  }
+  {
+    std::basic_stringbuf<CharT> buf;
+    std::basic_osyncstream<CharT> ss(&buf);
+    std::noemit_on_flush(ss);
----------------
ldionne wrote:

For all of these manipulators, we should also have a test with the `<< manip` syntax, just to confirm that it works. For example if you define

```c++
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>& noemit_on_flush(basic_ostream<_CharT, _Traits>& __os, int __dummy = 0);
```

I think your current tests would all pass, but `stream << noemit_on_flush` would not compile.

https://github.com/llvm/llvm-project/pull/97955


More information about the libcxx-commits mailing list