[libcxx-commits] [libcxx] [libc++] Add [[nodiscard]] to std::prev and std::next (PR #109550)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 25 13:51:50 PDT 2024


================
@@ -43,25 +43,26 @@ next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n =
 namespace ranges {
 struct __next {
   template <input_or_output_iterator _Ip>
-  _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
----------------
ldionne wrote:

We also want to add this to `std::next` above. But since that code must work before C++17, you can use `[[__nodiscard__]]` instead above, which is accepted as an extension before C++17.

The same comment applies to `std::prev`.

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


More information about the libcxx-commits mailing list