[libcxx-commits] [PATCH] D110495: [libc++][format][2/6] Adds a __output_iterator.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Sep 26 10:05:52 PDT 2021


Mordante marked 5 inline comments as done.
Mordante added inline comments.


================
Comment at: libcxx/include/__format/buffer.h:72-76
+/// Helper function call the buffer member function from @ref __output_iterator.
+template <class T, __formatter::__char_type _CharT>
+_LIBCPP_HIDE_FROM_ABI void __put(_CharT __c, void* __obj) {
+  static_cast<T*>(__obj)->put(__c);
+}
----------------
Quuxplusone wrote:
> The comment is ungrammatical and unhelpful, and `T` needs uglification; but why just not make this a private detail of `__output_iterator`? Instead of
> ```
>   _LIBCPP_HIDE_FROM_ABI explicit __output_iterator(_Fun __fun, void* __obj)
>       : __fun_(__fun), __obj_(__obj) {}
> ```
> do
> ```
>   _LIBCPP_HIDE_FROM_ABI explicit __output_iterator(_Tp *__t)
>       : __fun_([](_CharT __c, void *__o){ static_cast<_Tp*>(__o)->put(__c); }), __obj_(__t) {}
> ```
> and construct it on line 504 as
> ```
> _VSTD::__format::__output_iterator<_CharT>(_VSTD::addressof(__buffer))
> ```
> (notice `addressof`, not `operator&`, for ADL-proofing and hijacking-avoidance)
Your suggestion indeed looks better than the current code. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110495/new/

https://reviews.llvm.org/D110495



More information about the libcxx-commits mailing list