Skip to content

[ADT] Mark reverse and concat as nodiscard #115611

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

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ static constexpr bool HasFreeFunctionRBegin =
} // namespace detail

// Returns an iterator_range over the given container which iterates in reverse.
template <typename ContainerTy> auto reverse(ContainerTy &&C) {
// Does not mutate the container.
template <typename ContainerTy> [[nodiscard]] auto reverse(ContainerTy &&C) {
if constexpr (detail::HasFreeFunctionRBegin<ContainerTy>)
return make_range(adl_rbegin(C), adl_rend(C));
else
Expand Down Expand Up @@ -1182,11 +1183,13 @@ template <typename ValueT, typename... RangeTs> class concat_range {

} // end namespace detail

/// Concatenated range across two or more ranges.
/// Returns a concatenated range across two or more ranges. Does not modify the
/// ranges.
///
/// The desired value type must be explicitly specified.
template <typename ValueT, typename... RangeTs>
detail::concat_range<ValueT, RangeTs...> concat(RangeTs &&... Ranges) {
[[nodiscard]] detail::concat_range<ValueT, RangeTs...>
concat(RangeTs &&...Ranges) {
static_assert(sizeof...(RangeTs) > 1,
"Need more than one range to concatenate!");
return detail::concat_range<ValueT, RangeTs...>(
Expand Down
Loading