[libcxx-commits] [libcxx] WIP [libc++][ranges] Applied [[nodiscard]] to adjacent_transform_view (PR #205900)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 25 12:53:01 PDT 2026
https://github.com/lknknm created https://github.com/llvm/llvm-project/pull/205900
[[nodiscard]] should be applied to functions where discarding the return value is most likely a correctness issue.
- https://libcxx.llvm.org/CodingGuidelines.html
- https://wg21.link/range.adjacent.transform
Towards https://github.com/llvm/llvm-project/issues/172124
>From 65046f1524740c0e4a7829b61cd6a7601c34cfa5 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 25 Jun 2026 21:47:55 +0200
Subject: [PATCH] initial: nodiscard adjacent_transform_view
---
.../include/__ranges/adjacent_transform_view.h | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/libcxx/include/__ranges/adjacent_transform_view.h b/libcxx/include/__ranges/adjacent_transform_view.h
index 4863d074482dc..bdae098623977 100644
--- a/libcxx/include/__ranges/adjacent_transform_view.h
+++ b/libcxx/include/__ranges/adjacent_transform_view.h
@@ -105,22 +105,23 @@ class adjacent_transform_view : public view_interface<adjacent_transform_view<_V
_LIBCPP_HIDE_FROM_ABI constexpr explicit adjacent_transform_view(_View __base, _Fn __fun)
: __inner_(std::move(__base)), __fun_(std::in_place, std::move(__fun)) {}
- _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
requires copy_constructible<_View>
{
return __inner_.base();
}
- _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__inner_).base(); }
- _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator<false>(*this, __inner_.begin()); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__inner_).base(); }
- _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator<false>(*this, __inner_.begin()); }
+
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
requires range<const _InnerView> && regular_invocable<__apply_n<const _Fn&, _Np>, range_reference_t<const _View>>
{
return __iterator<true>(*this, __inner_.begin());
}
- _LIBCPP_HIDE_FROM_ABI constexpr auto end() {
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() {
if constexpr (common_range<_InnerView>) {
return __iterator<false>(*this, __inner_.end());
} else {
@@ -128,7 +129,7 @@ class adjacent_transform_view : public view_interface<adjacent_transform_view<_V
}
}
- _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
requires range<const _InnerView> && regular_invocable<__apply_n<const _Fn&, _Np>, range_reference_t<const _View>>
{
if constexpr (common_range<const _InnerView>) {
@@ -138,13 +139,13 @@ class adjacent_transform_view : public view_interface<adjacent_transform_view<_V
}
}
- _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size()
requires sized_range<_InnerView>
{
return __inner_.size();
}
- _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
requires sized_range<const _InnerView>
{
return __inner_.size();
More information about the libcxx-commits
mailing list