Issue 156058
Summary [clang-tidy] Modernize function parameters using std::span<const T> where applicable
Labels clang-tidy, check-request
Assignees
Reporter SunBlack
    We often use `std::vector` instead of `std::array` in our code so that we don't have to template the methods.  With C++20 and `std::span`, there is an elegant alternative for this. Therefore, it would be useful to have a check that recognizes when the container itself is irrelevant and code can be written more generically. Here is a code example that shows how using `std::span` eliminates the need for the template:

```cpp
#include <iostream>
#include <span>
#include <vector>

int sum(const std::span<const int>& values)
{
    int sum = 0;
    for(auto value : values)
    {
        sum += value;
    }
    return sum;
}

int main()
{
    const auto values1 = std::to_array({0, 2, 1, 3});
    const std::vector<int> values2{4, 7, 8, 9};

    std::cout << sum(values1) << '\n';
    std::cout << sum(values2) << '\n';
    return 0;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to