[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,92 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___OSTREAM_SYNCBUF_BASE_H
+#define _LIBCPP___OSTREAM_SYNCBUF_BASE_H
+
+#include <__config>
+#include <__ostream/basic_ostream.h>
+#include <streambuf>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
+
+template <class _CharT, class _Traits>
+class _LIBCPP_TEMPLATE_VIS __syncbuf_base : public basic_streambuf<_CharT, _Traits> {
+public:
+
+protected:
+  _LIBCPP_HIDE_FROM_ABI explicit __syncbuf_base(bool __b = false) : __emit_on_sync_(__b) {}
+
+private:
+  bool __emit_on_sync_{false};
+
+  virtual bool __emit() = 0;
+
+  template <class, class, class>
+  friend class basic_syncbuf;
+
+  friend struct __syncbuf_base_access;
+};
+
+struct __syncbuf_base_access {
----------------
ldionne wrote:

I think I would befriend the free functions that need to access private members instead. This is a nice pattern, but I am not certain it pulls its weight since there's only 3 functions that need to access private members, and they are all immediately below. Overall I think the code will be simpler to read with the 3 friend functions.

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


More information about the libcxx-commits mailing list