[libcxx-commits] [PATCH] D112017: [libcxx][format] Fix how we handle char traits in formatter<string> and formatter<string_view>

Victor Zverovich via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 18 17:09:54 PDT 2021


vitaut added inline comments.


================
Comment at: libcxx/include/__format/formatter.h:184-186
+template <class _CharT, class _Traits, class _Fill>
+_LIBCPP_HIDE_FROM_ABI auto __write_unicode(output_iterator<const _CharT&> auto __out_it,
+                                           basic_string_view<_CharT, _Traits> __str, ptrdiff_t __width,
----------------
DanielMcIntosh-IBM wrote:
> vitaut wrote:
> > I don't think traits are needed in this internal function. It might be better to convert `basic_string_view<_CharT, _Traits>` into `basic_string_view<_CharT>` when calling it and remove `_Traits` here to prevent template bloat.
> If my understanding of templates is correct, when `_Traits != char_traits<_CharT>`, then `basic_string_view<_CharT, _Traits>` is a totally different type from `basic_string_view<_CharT> == basic_string_view<_CharT, char_traits<_CharT>>`, and may not be convertible to `basic_string_view<_CharT>`.
Yes but string view is just a pointer and a size so you can do `basic_string_view<_CharT>(__str.data(), __str.size())` at the `__write_unicode` call site.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112017



More information about the libcxx-commits mailing list