llvm / llvm/llvm-project

[clang-tidy] Add `modernize-use-std-next` check

Open
#174,351 6 comments 0 reactions 0 assignees View on GitHub
check-request clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

It would be useful if `clang-tidy` can replace binary operator + (and optionally -) between an iterator and an integer with std::next (and std::prev).

Some examples:

```c++
// before
auto it = vec.begin();
auto next_it = it + 2;

// after
auto it = vec.begin();
auto next_it = std::next(it, 2);
```

```c++
// before
auto it = vec.begin() + 5;

// after
auto it = std::next(vec.begin(), 5);
```

```c++
// before
auto prev_it = it - 1;

// after
auto prev_it = std::prev(it);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.