[libcxx-commits] [libcxx] [libc++] Remove assumptions that std::array::iterator is a raw pointer (PR #74624)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 6 08:51:33 PST 2023


================
@@ -110,26 +111,32 @@ _LIBCPP_HIDE_FROM_ABI auto __copy(basic_string_view<_CharT> __str, output_iterat
   }
 }
 
-template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT>
-_LIBCPP_HIDE_FROM_ABI auto
-__copy(const _CharT* __first, const _CharT* __last, output_iterator<const _OutCharT&> auto __out_it)
+template <contiguous_iterator _Iterator,
+          __fmt_char_type _CharT    = typename iterator_traits<_Iterator>::value_type,
+          __fmt_char_type _OutCharT = _CharT>
+_LIBCPP_HIDE_FROM_ABI auto __copy(_Iterator __first, _Iterator __last, output_iterator<const _OutCharT&> auto __out_it)
     -> decltype(__out_it) {
   return __formatter::__copy(basic_string_view{__first, __last}, std::move(__out_it));
 }
 
-template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT>
-_LIBCPP_HIDE_FROM_ABI auto __copy(const _CharT* __first, size_t __n, output_iterator<const _OutCharT&> auto __out_it)
+template <contiguous_iterator _Iterator,
+          __fmt_char_type _CharT    = typename iterator_traits<_Iterator>::value_type,
+          __fmt_char_type _OutCharT = _CharT>
+_LIBCPP_HIDE_FROM_ABI auto __copy(_Iterator __first, size_t __n, output_iterator<const _OutCharT&> auto __out_it)
     -> decltype(__out_it) {
-  return __formatter::__copy(basic_string_view{__first, __n}, std::move(__out_it));
+  return __formatter::__copy(basic_string_view{std::to_address(__first), __n}, std::move(__out_it));
 }
 
 /// Transform wrapper.
 ///
 /// This uses a "mass output function" of __format::__output_buffer when possible.
-template <__fmt_char_type _CharT, __fmt_char_type _OutCharT = _CharT, class _UnaryOperation>
+template <contiguous_iterator _Iterator,
+          __fmt_char_type _CharT    = typename iterator_traits<_Iterator>::value_type,
+          __fmt_char_type _OutCharT = _CharT,
+          class _UnaryOperation>
 _LIBCPP_HIDE_FROM_ABI auto
-__transform(const _CharT* __first,
-            const _CharT* __last,
+__transform(_Iterator __first,
----------------
mordante wrote:

The goal here was to reduce the number of instantiations to `_CharT == char` and `_CharT == wchar_t`. Would it be possible to adjust the caller to keep this code unchanged?

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


More information about the libcxx-commits mailing list