[libcxx-commits] [libcxx] [libc++] Disallow std::prev(non_cpp17_bidi_iterator) (PR #112102)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 15 06:11:30 PDT 2024
================
@@ -35,6 +39,13 @@ prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n =
return __x;
}
+template <class _BidirectionalIterator,
+ __enable_if_t<__has_bidirectional_iterator_category<_BidirectionalIterator>::value, int> = 0>
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _BidirectionalIterator
+prev(_BidirectionalIterator __it) {
+ return std::prev(std::move(__it), 1);
+}
----------------
ldionne wrote:
Can you mention [LWG3197](https://cplusplus.github.io/LWG/issue3197) and explain that while it's not 100% clear yet what the Standard wants us to do, we take the stance that a non-bidi iterator is ill-formed because it's likely to lead to a bug.
https://github.com/llvm/llvm-project/pull/112102
More information about the libcxx-commits
mailing list