[libcxx-commits] [libcxx] [libc++][ranges] Applied [[nodiscard]] to `transform_view` (PR #203791)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 14 14:24:01 PDT 2026
https://github.com/lknknm updated https://github.com/llvm/llvm-project/pull/203791
>From 87ef47a2ba60da1854021c47c9aa27da5130b039 Mon Sep 17 00:00:00 2001
From: lknknm <sxswt at protonmail.com>
Date: Sun, 14 Jun 2026 22:38:25 +0200
Subject: [PATCH 1/2] add: nodiscard to transform_view<_View, _Fn>::__sentinel
---
libcxx/include/__ranges/transform_view.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index 98b38dd9b2aa1..01a5d18f7857d 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -213,7 +213,7 @@ class transform_view<_View, _Fn>::__iterator
_LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); }
- _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const
noexcept(noexcept(std::invoke(*__parent_->__func_, *__current_))) {
return std::invoke(*__parent_->__func_, *__current_);
}
@@ -361,26 +361,26 @@ class transform_view<_View, _Fn>::__sentinel {
requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
: __end_(std::move(__i.__end_)) {}
- _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; }
template <bool _OtherConst>
requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
- _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
return __x.__current_ == __y.__end_;
}
template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
- _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
return __x.__current_ - __y.__end_;
}
template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
- _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) {
- return __x.__end_ - __y.__current_;
+ return __x.__end_ - __y.__current_;
}
};
>From d08e3bd32ff8ea407e449a8c2fafd00b2174b0c0 Mon Sep 17 00:00:00 2001
From: lknknm <sxswt at protonmail.com>
Date: Sun, 14 Jun 2026 23:23:46 +0200
Subject: [PATCH 2/2] fix: clang-format
---
libcxx/include/__ranges/transform_view.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index 01a5d18f7857d..9f904dcd79342 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -365,7 +365,8 @@ class transform_view<_View, _Fn>::__sentinel {
template <bool _OtherConst>
requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool
+ operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
return __x.__current_ == __y.__end_;
}
@@ -380,7 +381,7 @@ class transform_view<_View, _Fn>::__sentinel {
requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) {
- return __x.__end_ - __y.__current_;
+ return __x.__end_ - __y.__current_;
}
};
More information about the libcxx-commits
mailing list