-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Remove assumptions that std::array::iterator is a raw pointer #74624
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,9 @@ | |
#include <__format/unicode.h> | ||
#include <__iterator/back_insert_iterator.h> | ||
#include <__iterator/concepts.h> | ||
#include <__iterator/iterator_traits.h> // iter_value_t | ||
#include <__iterator/iterator_traits.h> | ||
#include <__memory/addressof.h> | ||
#include <__memory/pointer_traits.h> | ||
#include <__utility/move.h> | ||
#include <__utility/unreachable.h> | ||
#include <cstddef> | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The goal here was to reduce the number of instantiations to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that, but the downside is that we'd have to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way we can do an OOB check ahead of time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that might be possible, but I would approach it from the top down. So I would write this code in a generic fashion, and then I would ensure that it ends up only being called with (optionally OOB-checked) raw pointers to reduce the number of instantiations. Also, at the end of the day, we're not instantiating this function with more unique types before/after this patch. We're just allowing the single type it's instantiated with to go from |
||
_Iterator __last, | ||
output_iterator<const _OutCharT&> auto __out_it, | ||
_UnaryOperation __operation) -> decltype(__out_it) { | ||
if constexpr (std::same_as<decltype(__out_it), std::back_insert_iterator<__format::__output_buffer<_OutCharT>>>) { | ||
|
@@ -260,8 +267,11 @@ __write(_Iterator __first, | |
return __formatter::__write(__first, __last, std::move(__out_it), __specs, __last - __first); | ||
} | ||
|
||
template <class _CharT, class _ParserCharT, class _UnaryOperation> | ||
_LIBCPP_HIDE_FROM_ABI auto __write_transformed(const _CharT* __first, const _CharT* __last, | ||
template <contiguous_iterator _Iterator, | ||
class _CharT = typename iterator_traits<_Iterator>::value_type, | ||
class _ParserCharT, | ||
class _UnaryOperation> | ||
_LIBCPP_HIDE_FROM_ABI auto __write_transformed(_Iterator __first, _Iterator __last, | ||
output_iterator<const _CharT&> auto __out_it, | ||
__format_spec::__parsed_specifications<_ParserCharT> __specs, | ||
_UnaryOperation __op) -> decltype(__out_it) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These iterators should be constrained to have a
char
value_type
the current constrains loosen these restrictions. (I'm fine with new conceptcontiguous_char_iterator
if you prefer that.)